Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.josescalia.tumblr.form; import com.josescalia.tumblr.app.BaseForm; import com.josescalia.tumblr.app.Bootstrap; import com.josescalia.tumblr.app.MainFrame; import com.josescalia.tumblr.form.dialog.TumblrFavLinkListDialog; import com.josescalia.tumblr.model.DownloadableImage; import com.josescalia.tumblr.model.Rss; import com.josescalia.tumblr.model.RssHeader; import com.josescalia.tumblr.model.RssItem; import com.josescalia.tumblr.service.RssService; import com.josescalia.tumblr.service.TumblrRssReaderService; import com.josescalia.tumblr.source.RssModel; import com.josescalia.tumblr.util.ApplicationConstants; import com.josescalia.tumblr.util.FileUtility; import com.josescalia.tumblr.util.RssReaderCore; import com.josescalia.tumblr.util.net.BinaryCacheUtil; import com.josescalia.tumblr.util.net.ReadWritePropertyFile; import com.josescalia.tumblr.util.swing.UIAlert; import com.josescalia.tumblr.util.swing.UIMessageConstants; import org.apache.log4j.Logger; import org.jdesktop.observablecollections.ObservableCollections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.util.FileSystemUtils; import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; /** * * @author josescalia */ @Component @Scope("prototype") public class TumblrImageViewer extends BaseForm { private static final long serialVersionUID = 6983826155334541112L; static Logger logger = Logger.getLogger(TumblrImageViewer.class.getName()); @Autowired private RssService rssService; @Autowired private TumblrRssReaderService service; private java.util.List<RssModel> rssList = new ArrayList<RssModel>(); private java.util.List<DownloadableImage> imgList = new ArrayList<DownloadableImage>(); private RssHeader rssHeader; private RssItem selectedItem; private String url; private String downloadPath = ""; private RssReaderCore core; private String imageDisplay; //parent Form private MainFrame frame; private TumblrImageViewer form; public void showForm() { setDownloadPath(ReadWritePropertyFile.readAppProperty(ApplicationConstants.APP_PROPERTY_FILE, "default.download.dir")); initComponents(); } private void initRightClickOnTable() { } /** * Creates new form TumblrImageViewer */ public TumblrImageViewer() { //initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); folderChooser = new javax.swing.JFileChooser(); mainPanel = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jPanel5 = new javax.swing.JPanel(); jScrollPane5 = new javax.swing.JScrollPane(); txtRssItemDescription1 = new javax.swing.JTextArea(); btnLast = new javax.swing.JButton(); btnNext = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); btnPrev = new javax.swing.JButton(); btnFirst = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); btnDownload = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); btnAddToCollection = new javax.swing.JButton(); btnLoad = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); txtUrlDesc = new javax.swing.JTextField(); jScrollPane3 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jLabel3 = new javax.swing.JLabel(); txtRssLink = new javax.swing.JTextField(); btnFetch = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); txtDownloadPath = new javax.swing.JTextField(); btnChangeFolder = new javax.swing.JButton(); btnOpenFolder = new javax.swing.JButton(); mainPanel.setBackground(java.awt.Color.white); mainPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); mainPanel.setPreferredSize(new java.awt.Dimension(1210, 730)); mainPanel.setRequestFocusEnabled(false); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel1.setPreferredSize(new java.awt.Dimension(1178, 435)); jEditorPane1.setContentType("text/html"); // NOI18N org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${imageDisplay}"), jEditorPane1, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jScrollPane2.setViewportView(jEditorPane1); org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty .create("${rssHeader.itemList}"); org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings .createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jTable1); org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${title}")); columnBinding.setColumnName("Title"); columnBinding.setColumnClass(String.class); bindingGroup.addBinding(jTableBinding); jTableBinding.bind(); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedItem}"), jTable1, org.jdesktop.beansbinding.BeanProperty.create("selectedElement")); bindingGroup.addBinding(binding); jScrollPane1.setViewportView(jTable1); jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder()); txtRssItemDescription1.setColumns(20); txtRssItemDescription1.setLineWrap(true); txtRssItemDescription1.setRows(5); txtRssItemDescription1.setWrapStyleWord(true); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedItem.description}"), txtRssItemDescription1, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jScrollPane5.setViewportView(txtRssItemDescription1); btnLast.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/forward.png"))); // NOI18N btnLast.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLastActionPerformed(evt); } }); btnNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arrow-right.png"))); // NOI18N btnNext.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNextActionPerformed(evt); } }); jLabel1.setText("Image Description :"); btnPrev.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arrow-left.png"))); // NOI18N btnPrev.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPrevActionPerformed(evt); } }); btnFirst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/backward.png"))); // NOI18N btnFirst.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFirstActionPerformed(evt); } }); jLabel6.setText("Image Link :"); eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedItem.imageList}"); jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jTable2); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${url}")); columnBinding.setColumnName("Url"); columnBinding.setColumnClass(String.class); bindingGroup.addBinding(jTableBinding); jTableBinding.bind(); jScrollPane4.setViewportView(jTable2); btnDownload.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/download.png"))); // NOI18N btnDownload.setText("Download"); btnDownload.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDownloadActionPerformed(evt); } }); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel6) .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE) .addGroup(jPanel5Layout.createSequentialGroup() .addComponent(btnFirst, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnPrev, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnLast, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(btnDownload, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnDownload).addGap(18, 18, 18) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnLast).addComponent(btnFirst).addComponent(btnPrev) .addComponent(btnNext)) .addContainerGap())); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1).addComponent(jScrollPane2)) .addContainerGap())); jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel2.setPreferredSize(new java.awt.Dimension(1190, 140)); btnAddToCollection.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/save.png"))); // NOI18N btnAddToCollection.setText("Save"); btnAddToCollection.setToolTipText("Save to Collection"); btnAddToCollection.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddToCollectionActionPerformed(evt); } }); btnLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/magnifier.png"))); // NOI18N btnLoad.setText("Load"); btnLoad.setToolTipText("Load from Collection"); btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoadActionPerformed(evt); } }); jLabel2.setText("Tumblr URL "); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${rssHeader.headerTitle}"), txtUrlDesc, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jTextArea1.setColumns(20); jTextArea1.setLineWrap(true); jTextArea1.setRows(5); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${rssHeader.headerDesc}"), jTextArea1, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jScrollPane3.setViewportView(jTextArea1); jLabel3.setText("URL Title "); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${url}"), txtRssLink, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); btnFetch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh.png"))); // NOI18N btnFetch.setText("Fetch"); btnFetch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFetchActionPerformed(evt); } }); jLabel4.setText("URL Description"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout .createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(txtRssLink) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnFetch, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnAddToCollection, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(txtUrlDesc)) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(7, 7, 7).addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtRssLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2).addComponent(btnFetch).addComponent(btnLoad) .addComponent(btnAddToCollection)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtUrlDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(14, Short.MAX_VALUE))); jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel3.setPreferredSize(new java.awt.Dimension(1178, 89)); jLabel7.setText("Download Path"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${downloadPath}"), txtDownloadPath, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); btnChangeFolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/change-folder.png"))); // NOI18N btnChangeFolder.setText("Change Folder"); btnChangeFolder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnChangeFolderActionPerformed(evt); } }); btnOpenFolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/open-folder.png"))); // NOI18N btnOpenFolder.setText("Open Folder"); btnOpenFolder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnOpenFolderActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtDownloadPath, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnChangeFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnOpenFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel7) .addComponent(txtDownloadPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnChangeFolder).addComponent(btnOpenFolder)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup(mainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1198, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1198, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 1198, Short.MAX_VALUE)) .addContainerGap())); mainPanelLayout.setVerticalGroup(mainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup().addGap(9, 9, 9) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(6, 6, 6))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 1250, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createSequentialGroup().addContainerGap().addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1226, Short.MAX_VALUE) .addContainerGap()))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 709, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE) .addContainerGap()))); bindingGroup.bind(); }// </editor-fold>//GEN-END:initComponents private void btnLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLastActionPerformed int rowLength = jTable1.getRowCount(); int selectedRow = jTable1.getSelectedRow(); jTable1.removeRowSelectionInterval(selectedRow, selectedRow); System.out.println("rowLength " + rowLength); jTable1.addRowSelectionInterval(rowLength - 1, rowLength - 1); }//GEN-LAST:event_btnLastActionPerformed private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed int selectedRow = jTable1.getSelectedRow(); jTable1.removeRowSelectionInterval(selectedRow, selectedRow); jTable1.addRowSelectionInterval(selectedRow + 1, selectedRow + 1); }//GEN-LAST:event_btnNextActionPerformed private void btnPrevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrevActionPerformed int selectedRow = jTable1.getSelectedRow(); jTable1.removeRowSelectionInterval(selectedRow, selectedRow); jTable1.addRowSelectionInterval(selectedRow - 1, selectedRow - 1); }//GEN-LAST:event_btnPrevActionPerformed private void btnFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFirstActionPerformed int selectedRow = jTable1.getSelectedRow(); jTable1.removeRowSelectionInterval(selectedRow, selectedRow); jTable1.addRowSelectionInterval(0, 0); }//GEN-LAST:event_btnFirstActionPerformed private void btnDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadActionPerformed frame = (MainFrame) this.getTopLevelAncestor(); form = this; /*since the application using cache, all we need is only copying target file to destination folder*/ //busy cursor and progress bar panel and frame form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.startProgressBar("Downloading"); new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { int successCount = 0; int failedCount = 0; for (DownloadableImage image : imgList) { String fileName = image.getUrl().substring(image.getUrl().lastIndexOf("/") + 1); String downloadUrl = image.getUrl(); File targetFile = new File(BinaryCacheUtil.getBinaryImagePath(".cache", fileName, downloadUrl)); try { FileSystemUtils.copyRecursively(targetFile, new File(downloadPath + "//" + fileName)); successCount++; } catch (IOException e) { logger.error("Copy Failed Exception : " + e.getMessage()); failedCount++; } } return "Download file finished : \n" + successCount + " file(s) downloaded successfully \n" + failedCount + "failed to download"; } @Override protected void done() { try { UIAlert.showInformation(null, get()); } catch (InterruptedException e) { logger.error(e); } catch (ExecutionException e) { logger.error(e); } form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.stopProgressBar(""); } }.execute(); }//GEN-LAST:event_btnDownloadActionPerformed private Rss constructNewObject() { logger.info("Url to save : " + url); Rss rss = new Rss(); rss.setLink(url); rss.setTitle(url.split("\\.")[0].replaceAll("http://", "")); return rss; } private void btnAddToCollectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddToCollectionActionPerformed frame = (MainFrame) this.getTopLevelAncestor(); form = this; if (validateUrl()) { final Rss rss = constructNewObject(); if (rss != null) { //set Progressbar and cursor form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.startProgressBar("Saving"); new SwingWorker<Boolean, Boolean>() { @Override protected Boolean doInBackground() throws Exception { try { rssService.save(rss); return Boolean.TRUE; } catch (Exception e) { UIAlert.showError(null, UIMessageConstants.saveFailedMsg + "\n" + e.getMessage()); } return Boolean.FALSE; } protected void done() { try { if (get()) { UIAlert.showInformation(null, UIMessageConstants.saveSucceedMsg); } else { UIAlert.showInformation(null, UIMessageConstants.saveFailedMsg); } } catch (InterruptedException e) { logger.error(e); } catch (ExecutionException e) { logger.error(e); } form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.stopProgressBar(""); } }.execute(); } } }//GEN-LAST:event_btnAddToCollectionActionPerformed private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed frame = (MainFrame) this.getTopLevelAncestor(); form = this; //busy cursor and progress bar in frame and panel form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.startProgressBar("Processing"); new SwingWorker<JDialog, JDialog>() { @Override protected JDialog doInBackground() throws Exception { return new TumblrFavLinkListDialog(null, true); } @Override protected void done() { TumblrFavLinkListDialog dlg = null; String urlToFetch = ""; try { dlg = (TumblrFavLinkListDialog) get(); dlg.showDialog(); } catch (InterruptedException e) { logger.error(e); } catch (ExecutionException e) { logger.error(e); } if (dlg != null) { form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.stopProgressBar(""); urlToFetch = dlg.getFieldText(); } if (!urlToFetch.equals("")) { setUrl(urlToFetch); } } }.execute(); }//GEN-LAST:event_btnLoadActionPerformed private void btnFetchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFetchActionPerformed frame = (MainFrame) this.getTopLevelAncestor(); form = this; validateUrl(); //busy cursor and progress bar form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.startProgressBar("Fetching"); new SwingWorker<RssHeader, RssHeader>() { @Override protected RssHeader doInBackground() throws Exception { return service.getRssHeader(url + "/rss"); } protected void done() { try { setRssHeader(get()); } catch (InterruptedException e) { logger.error(e); } catch (ExecutionException e) { logger.error(e); } form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.stopProgressBar(""); } }.execute(); }//GEN-LAST:event_btnFetchActionPerformed private void btnChangeFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeFolderActionPerformed folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnValue = folderChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { setDownloadPath(folderChooser.getSelectedFile().getPath()); } }//GEN-LAST:event_btnChangeFolderActionPerformed private void btnOpenFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFolderActionPerformed FileUtility.openFolder(new File(downloadPath)); }//GEN-LAST:event_btnOpenFolderActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAddToCollection; private javax.swing.JButton btnChangeFolder; private javax.swing.JButton btnDownload; private javax.swing.JButton btnFetch; private javax.swing.JButton btnFirst; private javax.swing.JButton btnLast; private javax.swing.JButton btnLoad; private javax.swing.JButton btnNext; private javax.swing.JButton btnOpenFolder; private javax.swing.JButton btnPrev; private javax.swing.JFileChooser folderChooser; private javax.swing.JEditorPane jEditorPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JScrollPane jScrollPane5; private javax.swing.JTable jTable1; private javax.swing.JTable jTable2; private javax.swing.JTextArea jTextArea1; private javax.swing.JPanel mainPanel; private javax.swing.JTextField txtDownloadPath; private javax.swing.JTextArea txtRssItemDescription1; private javax.swing.JTextField txtRssLink; private javax.swing.JTextField txtUrlDesc; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables private void setDisplay(List<DownloadableImage> downloadableImageList) { frame = (MainFrame) this.getTopLevelAncestor(); form = this; final List<DownloadableImage> downloadableImages = downloadableImageList; form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); frame.startProgressBar("Viewing"); if (downloadableImages != null && downloadableImages.size() > 0) { new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { String sReturn = ""; for (DownloadableImage image : downloadableImages) { String fileName = image.getUrl().substring(image.getUrl().lastIndexOf("/") + 1); String downloadUrl = image.getUrl(); if (sReturn.length() > 0) { sReturn += "<br>"; } sReturn += "<img src='file:///" + BinaryCacheUtil.getBinaryImagePath(".cache", fileName, downloadUrl) + "'>"; } return sReturn; } @Override protected void done() { try { setImageDisplay(get()); } catch (InterruptedException e) { logger.error(e); } catch (ExecutionException e) { logger.error(e); } form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); frame.stopProgressBar(""); } }.execute(); } } private Boolean validateUrl() { if (url == null) { JOptionPane.showMessageDialog(this, "Url is empty", "Error", JOptionPane.ERROR_MESSAGE); return false; } else { return true; } } public RssHeader getRssHeader() { return rssHeader; } public void setRssHeader(RssHeader rssHeader) { RssHeader old = this.rssHeader; this.rssHeader = rssHeader; firePropertyChange("rssHeader", old, rssHeader); } public String getUrl() { return url; } public void setUrl(String url) { String old = this.url; this.url = url; firePropertyChange("url", old, url); } public RssItem getSelectedItem() { return selectedItem; } public void setSelectedItem(RssItem selectedItem) { RssItem old = this.selectedItem; this.selectedItem = selectedItem; firePropertyChange("selectedItem", old, selectedItem); if (selectedItem != null) { jEditorPane1 .setText("<p style='text-align:center'><strong>Loading Image<br></strong>Please Wait...</p> "); //clear editor pane setDisplay(selectedItem.getImageList()); logger.info(selectedItem.getImageList()); setImgList(ObservableCollections.observableList(selectedItem.getImageList())); } } public List<DownloadableImage> getImgList() { return imgList; } public void setImgList(List<DownloadableImage> imgList) { List<DownloadableImage> old = this.imgList; this.imgList = imgList; firePropertyChange("imgList", old, imgList); } public String getDownloadPath() { return downloadPath; } public void setDownloadPath(String downloadPath) { String old = this.downloadPath; this.downloadPath = downloadPath; firePropertyChange("downloadPath", old, downloadPath); } public RssReaderCore getCore() { return core; } public void setCore(RssReaderCore core) { this.core = core; } public String getImageDisplay() { return imageDisplay; } public void setImageDisplay(String imageDisplay) { String old = this.imageDisplay; this.imageDisplay = imageDisplay; firePropertyChange("imageDisplay", old, imageDisplay); } }