KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > wizard > ProgressFrame


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.dbschema.jdbcimpl.wizard;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28 import org.netbeans.api.progress.ProgressHandle;
29 import org.netbeans.api.progress.ProgressHandleFactory;
30
31 import org.openide.util.NbBundle;
32
33 public class ProgressFrame extends javax.swing.JFrame JavaDoc {
34
35     ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
36
public PropertyChangeSupport JavaDoc propertySupport;
37     private ProgressHandle progressHandle;
38     private JComponent JavaDoc progressComponent;
39     private int workunits;
40     private boolean finished = false;
41     
42     /** Creates new form ProgressFrame */
43     public ProgressFrame() {
44         propertySupport = new PropertyChangeSupport JavaDoc(this);
45         
46         initComponents ();
47         this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ProgressFrameTabA11yDesc")); // NOI18N
48
okButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CancelButtonA11yDesc")); // NOI18N
49

50         progressHandle = ProgressHandleFactory.createHandle(null);
51         progressComponent = ProgressHandleFactory.createProgressComponent(progressHandle);
52         progressPanel.add(progressComponent);
53         progressHandle.start();
54
55         javax.swing.ImageIcon JavaDoc ideIcon = new javax.swing.ImageIcon JavaDoc("/org/netbeans/core/resources/frames/ide.gif"); //NOI18N
56
setIconImage(ideIcon.getImage());
57
58         java.awt.Dimension JavaDoc dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
59         setSize(380, 150);
60         setLocation(dim.width/2 - 190, dim.height/2 - 80);
61     }
62     
63     public void dispose() {
64         if (!finished) {
65             progressHandle.finish();
66             finished = true;
67         }
68         super.dispose();
69     }
70
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the FormEditor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         progressPanel = new javax.swing.JPanel JavaDoc();
81         msgLabel = new javax.swing.JLabel JavaDoc();
82         okButton = new javax.swing.JButton JavaDoc();
83
84         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
85
86         setTitle(bundle.getString("Title"));
87         setResizable(false);
88         progressPanel.setLayout(new java.awt.BorderLayout JavaDoc());
89
90         progressPanel.setMinimumSize(new java.awt.Dimension JavaDoc(20, 20));
91         progressPanel.setPreferredSize(new java.awt.Dimension JavaDoc(20, 20));
92         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
93         gridBagConstraints.gridx = 0;
94         gridBagConstraints.gridy = 1;
95         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
96         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 11, 11);
97         getContentPane().add(progressPanel, gridBagConstraints);
98
99         msgLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
100         msgLabel.setText(bundle.getString("PreparingToCapture"));
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 0;
103         gridBagConstraints.gridy = 0;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 11, 6, 11);
106         getContentPane().add(msgLabel, gridBagConstraints);
107
108         okButton.setText(bundle.getString("Close"));
109         okButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
110         okButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
111             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
112                 okButtonActionPerformed(evt);
113             }
114         });
115
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 2;
119         gridBagConstraints.weightx = 0.3;
120         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 11, 11);
121         getContentPane().add(okButton, gridBagConstraints);
122
123     }
124     // </editor-fold>//GEN-END:initComponents
125

126   private void okButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_okButtonActionPerformed
127
setVisible(false);
128     propertySupport.firePropertyChange("cancel", null, Boolean.TRUE); //NOI18N
129

130     dispose();
131   }//GEN-LAST:event_okButtonActionPerformed
132

133     // Variables declaration - do not modify//GEN-BEGIN:variables
134
private javax.swing.JLabel JavaDoc msgLabel;
135     private javax.swing.JButton JavaDoc okButton;
136     private javax.swing.JPanel JavaDoc progressPanel;
137     // End of variables declaration//GEN-END:variables
138

139     public void setMaximum(final int max) {
140         progressHandle.switchToDeterminate(max);
141         workunits = max;
142     }
143     
144     public void setValue(final int value) {
145         String JavaDoc message;
146         
147         progressHandle.progress(value);
148         
149         if (value >= workunits) {
150             SwingUtilities.invokeLater(new Runnable JavaDoc() {
151                 public void run() {
152                     String JavaDoc message = MessageFormat.format(bundle.getString("Complete"), new String JavaDoc[] {Integer.toString(value)}); //NOI18N
153
msgLabel.setText(message);
154                 }
155             });
156         }
157     }
158     
159     public void setMessage(String JavaDoc msg) {
160         msgLabel.setText(msg);
161     }
162     
163     public void finishProgress() {
164         // running in the event thread ensures synchronized access to the finished field
165
SwingUtilities.invokeLater(new Runnable JavaDoc() {
166             public void run() {
167                 progressHandle.finish();
168                 finished = true;
169             }
170         });
171     }
172     
173     //========== property change support needed for progressbar ==========
174
public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
175         propertySupport.addPropertyChangeListener (l);
176     }
177     
178     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
179         propertySupport.removePropertyChangeListener (l);
180     }
181 }
182
Popular Tags