1 19 20 package org.netbeans.modules.projectimport.j2seimport.ui; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.JDialog ; 26 import javax.swing.Timer ; 27 import javax.swing.WindowConstants ; 28 import org.netbeans.api.progress.ProgressHandle; 29 import org.netbeans.api.progress.ProgressHandleFactory; 30 import org.netbeans.modules.projectimport.j2seimport.ImportProcess; 31 import org.openide.DialogDescriptor; 32 import org.openide.DialogDisplayer; 33 import org.openide.util.NbBundle; 34 35 40 public class ProgressPanel extends javax.swing.JPanel { 41 public static void showProgress(final ImportProcess iProcess) { 42 final ProgressHandle ph = iProcess.getProgressHandle(); 43 final ProgressPanel progressPanel = new ProgressPanel(ph); 44 String title = NbBundle.getMessage(ProgressPanel.class, "CTL_ProgressDialogTitle"); 46 DialogDescriptor desc = new DialogDescriptor(progressPanel,title,true, new Object []{}, null, 0, null, null); 47 desc.setClosingOptions(new Object []{}); 48 49 final Dialog progressDialog = DialogDisplayer.getDefault().createDialog(desc); 50 ((JDialog ) progressDialog).setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 51 52 final Timer progressTimer = new Timer (50, null); 54 progressTimer.addActionListener(new ActionListener () { 55 public void actionPerformed(ActionEvent e) { 56 if (iProcess.isFinished()) { 57 progressTimer.stop(); 58 progressDialog.setVisible(false); 59 progressDialog.dispose(); 60 } 61 } 62 }); 63 iProcess.startImport(true); progressTimer.start(); 65 progressDialog.setVisible(true); 66 } 67 68 69 70 private ProgressPanel(final ProgressHandle progressHandle) { 71 initComponents(progressHandle); 72 } 73 74 75 private void initComponents(final ProgressHandle progressHandle) { 76 java.awt.GridBagConstraints gridBagConstraints; 77 78 setLayout(new java.awt.GridBagLayout ()); 79 80 setPreferredSize(new java.awt.Dimension (450, 80)); 81 gridBagConstraints = new java.awt.GridBagConstraints (); 82 gridBagConstraints.gridx = 0; 83 gridBagConstraints.gridy = 0; 84 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 85 gridBagConstraints.weightx = 1.0; 86 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 5); 87 add(ProgressHandleFactory.createProgressComponent(progressHandle), gridBagConstraints); 88 } 89 } 90 | Popular Tags |