KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > j2seimport > ui > ProgressPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.j2seimport.ui;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JDialog JavaDoc;
26 import javax.swing.Timer JavaDoc;
27 import javax.swing.WindowConstants JavaDoc;
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 /**
36  * Shows status(progress) of importing.
37  *
38  * @author Radek Matous
39  */

40 public class ProgressPanel extends javax.swing.JPanel JavaDoc {
41     public static void showProgress(final ImportProcess iProcess) {
42         final ProgressHandle ph = iProcess.getProgressHandle();
43         final ProgressPanel progressPanel = new ProgressPanel(ph);
44         String JavaDoc title = NbBundle.getMessage(ProgressPanel.class, "CTL_ProgressDialogTitle");//NOI18N
45

46         DialogDescriptor desc = new DialogDescriptor(progressPanel,title,true, new Object JavaDoc[]{}, null, 0, null, null);
47         desc.setClosingOptions(new Object JavaDoc[]{});
48         
49         final Dialog JavaDoc progressDialog = DialogDisplayer.getDefault().createDialog(desc);
50         ((JDialog JavaDoc) progressDialog).setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
51         
52         // progress timer for periodically update progress
53
final Timer JavaDoc progressTimer = new Timer JavaDoc(50, null);
54         progressTimer.addActionListener(new ActionListener JavaDoc() {
55             public void actionPerformed(ActionEvent JavaDoc e) {
56                 if (iProcess.isFinished()) {
57                     progressTimer.stop();
58                     progressDialog.setVisible(false);
59                     progressDialog.dispose();
60                 }
61             }
62         });
63         iProcess.startImport(true); // runs importing in separate thread
64
progressTimer.start();
65         progressDialog.setVisible(true);
66     }
67     
68     
69     /** Creates new form ProgressPanel */
70     private ProgressPanel(final ProgressHandle progressHandle) {
71         initComponents(progressHandle);
72     }
73     
74     
75     private void initComponents(final ProgressHandle progressHandle) {
76         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
77         
78         setLayout(new java.awt.GridBagLayout JavaDoc());
79         
80         setPreferredSize(new java.awt.Dimension JavaDoc(450, 80));
81         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 5, 0, 5);
87         add(ProgressHandleFactory.createProgressComponent(progressHandle), gridBagConstraints);
88     }
89 }
90
Popular Tags