KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > DownloadProgressPanel


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.autoupdate;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dialog JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import javax.swing.SwingUtilities JavaDoc;
29 import org.netbeans.api.progress.ProgressHandle;
30 import org.netbeans.api.progress.ProgressHandleFactory;
31
32 import org.openide.util.NbBundle;
33
34 class DownloadProgressPanel extends javax.swing.JPanel JavaDoc {
35
36     private static final String JavaDoc EMPTY_STRING = ""; // NOI18N
37

38     /** The dialog */
39     private Dialog JavaDoc dialog;
40     /** Title of the dialog */
41     private String JavaDoc title;
42     
43     static final long serialVersionUID =1986287669107010921L;
44     
45     private Wizard.WizardPanel wizardPanel;
46     
47     /** Creates new form DownloadProgressPanel */
48     public DownloadProgressPanel(Wizard.WizardPanel wizardPanel) {
49         this.wizardPanel = wizardPanel;
50         putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(2)); // NOI18N
51
setName(getBundle("LBL_Download"));
52         initComponents();
53         
54         partialLabel.setText (EMPTY_STRING);
55         overallLabel.setText (EMPTY_STRING);
56         extraLabel.setText (EMPTY_STRING);
57
58         getAccessibleContext().setAccessibleName(getBundle("LBL_Download"));
59         getAccessibleContext().setAccessibleDescription(getBundle("LBL_31"));
60         jTextArea1.getAccessibleContext().setAccessibleName(getBundle("ACS_31"));
61         jTextArea1.getAccessibleContext().setAccessibleDescription(getBundle("ACSD_31"));
62     }
63     
64     /** Overload getPreffered size to get a bit bigger dialog */
65     public java.awt.Dimension JavaDoc getPreferredSize() {
66         return new java.awt.Dimension JavaDoc( 350, super.getPreferredSize().height );
67     }
68     
69     /** This method is called from within the constructor to
70      * initialize the form.
71      * WARNING: Do NOT modify this code. The content of this method is
72      * always regenerated by the Form Editor.
73      */

74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
77
78         jTextArea1 = new javax.swing.JTextArea JavaDoc();
79         partialLabel = new javax.swing.JLabel JavaDoc();
80         jPanel1 = new javax.swing.JPanel JavaDoc();
81         jProgressBar1 = new javax.swing.JProgressBar JavaDoc();
82         overallLabel = new javax.swing.JLabel JavaDoc();
83         jPanel2 = new javax.swing.JPanel JavaDoc();
84         jProgressBar2 = new javax.swing.JProgressBar JavaDoc();
85         extraLabel = new javax.swing.JLabel JavaDoc();
86         jButton1 = new javax.swing.JButton JavaDoc();
87
88         setLayout(new java.awt.GridBagLayout JavaDoc());
89
90         jTextArea1.setBackground(partialLabel.getBackground());
91         jTextArea1.setEditable(false);
92         jTextArea1.setFont(new Font JavaDoc("Dialog", Font.PLAIN, jTextArea1.getFont().getSize()));
93         jTextArea1.setLineWrap(true);
94         jTextArea1.setText(getBundle("LBL_31"));
95         jTextArea1.setWrapStyleWord(true);
96         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
97         gridBagConstraints.gridx = 0;
98         gridBagConstraints.gridy = 0;
99         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
100         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
101         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
102         gridBagConstraints.weightx = 1.0;
103         add(jTextArea1, gridBagConstraints);
104
105         partialLabel.setLabelFor(jPanel1);
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 1;
109         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
112         add(partialLabel, gridBagConstraints);
113
114         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
115
116         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(0, 20));
117         jPanel1.add(jProgressBar1, java.awt.BorderLayout.CENTER);
118
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 0;
121         gridBagConstraints.gridy = 2;
122         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 0);
125         add(jPanel1, gridBagConstraints);
126
127         overallLabel.setLabelFor(jPanel2);
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 3;
131         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
134         add(overallLabel, gridBagConstraints);
135
136         jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
137
138         jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(0, 20));
139         jPanel2.add(jProgressBar2, java.awt.BorderLayout.CENTER);
140
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 0;
143         gridBagConstraints.gridy = 4;
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 0);
147         add(jPanel2, gridBagConstraints);
148
149         extraLabel.setLabelFor(this);
150         org.openide.awt.Mnemonics.setLocalizedText(extraLabel, getBundle("LBL_32"));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 5;
154         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
156         gridBagConstraints.weighty = 1.0;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
158         add(extraLabel, gridBagConstraints);
159
160         org.openide.awt.Mnemonics.setLocalizedText(jButton1, getBundle("BTN_Stop"));
161         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
162             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
163                 jButton1ActionPerformed(evt);
164             }
165         });
166
167         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
168         gridBagConstraints.gridx = 1;
169         gridBagConstraints.gridy = 5;
170         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
171         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
172         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
174         add(jButton1, gridBagConstraints);
175
176     }// </editor-fold>//GEN-END:initComponents
177

178     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
179
if (IncompleteDialog.showDialog() == IncompleteDialog.STOP) {
180             setExtraLabel (getBundle ("DownloadProgressPanel.jLabel1.Stop")); // NOI18N
181
wizardPanel.end(false);
182             jButton1.setEnabled (false);
183         }
184     }//GEN-LAST:event_jButton1ActionPerformed
185

186     
187     // Variables declaration - do not modify//GEN-BEGIN:variables
188
private javax.swing.JLabel JavaDoc extraLabel;
189     private javax.swing.JButton JavaDoc jButton1;
190     private javax.swing.JPanel JavaDoc jPanel1;
191     private javax.swing.JPanel JavaDoc jPanel2;
192     private javax.swing.JProgressBar JavaDoc jProgressBar1;
193     private javax.swing.JProgressBar JavaDoc jProgressBar2;
194     private javax.swing.JTextArea JavaDoc jTextArea1;
195     private javax.swing.JLabel JavaDoc overallLabel;
196     private javax.swing.JLabel JavaDoc partialLabel;
197     // End of variables declaration//GEN-END:variables
198

199     void setEnableStop(boolean enable) {
200         jButton1.setEnabled(enable);
201     }
202     
203     // progress components
204

205     void setPartialProgressComponent (ProgressHandle partial) {
206         final Component JavaDoc c = ProgressHandleFactory.createProgressComponent (partial);
207         SwingUtilities.invokeLater (new Runnable JavaDoc () {
208             public void run () {
209                 plugProgressComponent (c, jPanel1);
210             }
211         });
212     }
213     
214     void setOverallProgressComponent (ProgressHandle overall) {
215         final Component JavaDoc c = ProgressHandleFactory.createProgressComponent (overall);
216         SwingUtilities.invokeLater (new Runnable JavaDoc () {
217             public void run () {
218                 plugProgressComponent (c, jPanel2);
219             }
220         });
221     }
222     
223     private void plugProgressComponent (Component JavaDoc c, JPanel JavaDoc p) {
224         p.removeAll ();
225         p.add (c, BorderLayout.CENTER);
226         revalidate ();
227     }
228     
229     /** Closes the dialog */
230     public void close() {
231         dialog.setVisible( false );
232         dialog.dispose();
233         dialog = null;
234     }
235
236     // setting labels
237
public void setPartialLabel (String JavaDoc msg) {
238         partialLabel.setText (msg);
239     }
240
241     public void setOverallLabel (String JavaDoc msg) {
242         overallLabel.setText (msg);
243     }
244
245     public void setExtraLabel (String JavaDoc msg) {
246         extraLabel.setText (msg);
247     }
248     
249     // helpers
250

251     private static String JavaDoc getBundle( String JavaDoc key ) {
252         return NbBundle.getMessage( DownloadProgressPanel.class, key );
253     }
254 }
255
Popular Tags