Commits

Anonymous committed c510557

Commit content:
1. Normal realization of Channels
2. Fixed problems with interface

Comments (0)

Files changed (2)

src/org/narsereg/nbnetcatupdater/NBUpdaterDownloadFile.java

     private File downloadedFile = null;
     private URL fileLink;
     FileOutputStream fos = null;
+    boolean wasCancelled = false;
     
     
     @Override
                 }
         } finally {
             try {
+                publish(fileSize);
+                if(isCancelled()){
+                    downloadedFile.delete();
+                    publish(0);
+                }
                 pt.isDownloaded = true;
                 fos.flush();
                 fos.close();
-                publish(fileSize);
             } catch (IOException ex) {
                 Logger.getLogger(NBUpdaterDownloadFile.class.getName()).log(Level.SEVERE, null, ex);
             }
     }
     
     protected void closeConnection() throws InterruptedException{
-//        throw new ThreadDeath();
-//        try {
-//            fos.close();
-//        } catch (IOException ex) {
-//            Logger.getLogger(NBUpdaterDownloadFile.class.getName()).log(Level.SEVERE, null, ex);
-//        }
-//        try {
-//            fos.getChannel().close();
-//            fos.getChannel().force(true);
-//        } catch (IOException ex) {
-//            Logger.getLogger(NBUpdaterDownloadFile.class.getName()).log(Level.SEVERE, null, ex);
-//        }
-//        try {
-//            rbc.close();
-//        } catch (IOException ex) {
-//            Logger.getLogger(NBUpdaterDownloadFile.class.getName()).log(Level.SEVERE, null, ex);
-//        }
         Thread.currentThread().interrupt();
     }
     

src/org/narsereg/nbnetcatupdater/NBUpdaterForm.java

     String[] options = { "javase", "javaee", "cpp", "php", "all" };
     String[] platforms = { "windows", "linux", "solaris-x86", "solaris-sparc", "macosx", "zip" };
     String pathToDownloadedFile;
+    NBUpdaterDownloadFile df = null;
 
     /**
      * Creates new form NewJFrame
     }//GEN-LAST:event_chooseDownloadDirButtonActionPerformed
 
     private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed
-        //downloadButton.setEnabled(false);
-        NBUpdaterUtils nbUtils = new NBUpdaterUtils();
-        nbUtils.setOption(options[bundleComboBox.getSelectedIndex()]);
-        nbUtils.setPlatform(platforms[platformComboBox.getSelectedIndex()]);
-        NBUpdaterDownloadFile df = new NBUpdaterDownloadFile(nbUtils.getDownloadFileURL(), this);
         if (downloadButton.getText().equals("Download")) {
+            NBUpdaterUtils nbUtils = new NBUpdaterUtils();
+            nbUtils.setOption(options[bundleComboBox.getSelectedIndex()]);
+            nbUtils.setPlatform(platforms[platformComboBox.getSelectedIndex()]);
+            df = new NBUpdaterDownloadFile(nbUtils.getDownloadFileURL(), this);
+            
             this.setComponentsEnabled(false);
             
             downloadProgressBar.setMinimum(0);
             downloadButton.setText("Cancel");
         } else {
             this.setComponentsEnabled(true);
-//            try {
-//                //df.
-//                df.cancel(true);
-//            } catch (java.lang.NullPointerException ex) {
-//                
-//            }
-//            df = null;
-            //df.cancel(true);
             df.cancel(true);
-//            try {
-//                df.closeConnection();
-//            } catch (InterruptedException ex) {
-//                Logger.getLogger(NBUpdaterForm.class.getName()).log(Level.SEVERE, null, ex);
-//            }
-            
-            //df.cancel(true);
             downloadButton.setText("Download");
-        }
-//            downloadProgressBar.setMinimum(0);
-//            downloadProgressBar.setMaximum(df.fileSize);
-//            downloadProgressBar.setStringPainted(true);
-//            df.execute();
-            
-            
+        }  
     }//GEN-LAST:event_downloadButtonActionPerformed
 
     private void setComponentsEnabled(boolean enabled){
 
     protected void updateDownloadProgressbar(int bytes){
         downloadProgressBar.setValue(bytes);
+        if (downloadProgressBar.getValue() >= downloadProgressBar.getMaximum()){
+            this.setComponentsEnabled(true);
+            downloadButton.setText("Download");
+        }
     }
     
     protected void unzipDownloadedFile (String pathToFileToUnzip){
 
                 new File(newPath).mkdir();
                 Enumeration zipFileEntries = zip.entries();
-
+                
                 while (zipFileEntries.hasMoreElements())
                 {
                     ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();