KickJava   Java API By Example, From Geeks To Geeks.

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


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.Dialog JavaDoc;
23 import javax.swing.JPanel JavaDoc;
24 import org.netbeans.api.options.OptionsDisplayer;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.util.NbBundle;
28
29 /** Used to let user now the web will be checked for new updates. And
30  * optionally config the process
31  * @author Petr Hrebejk
32  */

33 class AutoCheckInfo extends javax.swing.JPanel JavaDoc {
34
35     private Settings settings;
36
37     /** prefferd width of dialog */
38     private int prefX = 0;
39
40     private java.awt.Dimension JavaDoc prefSize = null;
41
42     /** Creates new form LicencePanel */
43     public AutoCheckInfo( String JavaDoc message, int messageType ) {
44
45         settings = Settings.getShared();
46         int period = settings.getPeriod();
47
48         initComponents ();
49
50         Settings.PeriodPropertyEditor ppe = new Settings.PeriodPropertyEditor();
51
52         String JavaDoc[] tags = ppe.getTags();
53
54         for ( int i = 0; i < tags.length; i++ )
55             periodComboBox.addItem( tags[i] );
56
57         messageText.setText( message );
58         iconLabel.setIcon( getIconForType( messageType ) );
59
60         beforeCheckBox.setSelected( settings.isAskBefore() );
61         negativCheckBox.setSelected( settings.isNegativeResults() );
62
63         periodComboBox.setSelectedIndex( period );
64
65         prefX = getPreferredSize().width;
66
67         JPanel JavaDoc lPanel = new ServerPanel();
68         java.awt.GridBagConstraints JavaDoc gridBagConstraints4 = new java.awt.GridBagConstraints JavaDoc();
69         gridBagConstraints4.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
70         gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
71         gridBagConstraints4.gridy = 0;
72         gridBagConstraints4.weightx = 1.0;
73         gridBagConstraints4.weighty = 1.0;
74         gridBagConstraints4.fill = java.awt.GridBagConstraints.BOTH;
75         
76         extSettingsPanel.add(lPanel, gridBagConstraints4);
77
78         configPanel.setBorder (new javax.swing.border.TitledBorder JavaDoc(NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.configBorder")));
79         extSettingsPanel.setBorder (new javax.swing.border.TitledBorder JavaDoc(NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.additionalBorder")));
80
81         configPanel.setVisible( false );
82         extSettingsPanel.setVisible( false );
83
84         getAccessibleContext().setAccessibleName(NbBundle.getBundle(AutoCheckInfo.class).getString("CTL_AutoCheck_Title"));
85         getAccessibleContext().setAccessibleDescription(message);
86         configCheckBox.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AutoCheckInfo.class).getString("ACS_AutoCheckInfo.configCheckBox.text"));
87         periodComboBox.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AutoCheckInfo.class).getString("ACS_AutoCheckInfo.jLabel2.text"));
88         beforeCheckBox.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AutoCheckInfo.class).getString("ACS_AutoCheckInfo.jCheckBox1.text"));
89         negativCheckBox.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AutoCheckInfo.class).getString("ACS_AutoCheckInfo.jCheckBox2.text"));
90         proxyButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AutoCheckInfo.class).getString("ACS_AutoCheckInfo.proxyButton.text"));
91         messageText.getAccessibleContext().setAccessibleName(message);
92         messageText.getAccessibleContext().setAccessibleDescription(message);
93     }
94
95     /** Overload getPreffered size to get a bit bigger dialog */
96
97     public java.awt.Dimension JavaDoc getPreferredSize() {
98         if ( prefX == 0 ) {
99             return super.getPreferredSize();
100         }
101
102         //if ( prefSize == null )
103
prefSize = super.getPreferredSize();
104         prefSize.width = java.lang.Math.max( prefSize.width, prefX );
105
106         return prefSize;
107     }
108
109
110     /** This method is called from within the constructor to
111      * initialize the form.
112      * WARNING: Do NOT modify this code. The content of this method is
113      * always regenerated by the FormEditor.
114      */

115     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
116
private void initComponents() {
117         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
118
119         messagePanel = new javax.swing.JPanel JavaDoc();
120         iconLabel = new javax.swing.JLabel JavaDoc();
121         messageText = new javax.swing.JTextArea JavaDoc();
122         configCheckBox = new javax.swing.JCheckBox JavaDoc();
123         configPanel = new javax.swing.JPanel JavaDoc();
124         jLabel2 = new javax.swing.JLabel JavaDoc();
125         periodComboBox = new javax.swing.JComboBox JavaDoc();
126         beforeCheckBox = new javax.swing.JCheckBox JavaDoc();
127         negativCheckBox = new javax.swing.JCheckBox JavaDoc();
128         extSettingsPanel = new javax.swing.JPanel JavaDoc();
129         proxyButton = new javax.swing.JButton JavaDoc();
130
131         FormListener formListener = new FormListener();
132
133         setLayout(new java.awt.GridBagLayout JavaDoc());
134
135         setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
136         messagePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
137
138         iconLabel.setLabelFor(configCheckBox);
139         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
140         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
141         gridBagConstraints.weighty = 1.0;
142         messagePanel.add(iconLabel, gridBagConstraints);
143
144         messageText.setEditable(false);
145         messageText.setOpaque(false);
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
148         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
150         gridBagConstraints.weightx = 1.0;
151         gridBagConstraints.weighty = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 18, 0, 0);
153         messagePanel.add(messageText, gridBagConstraints);
154
155         org.openide.awt.Mnemonics.setLocalizedText(configCheckBox, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.configCheckBox.text"));
156         configCheckBox.addActionListener(formListener);
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 1;
160         gridBagConstraints.gridy = 1;
161         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 18, 0, 0);
164         messagePanel.add(configCheckBox, gridBagConstraints);
165
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.weightx = 1.0;
170         gridBagConstraints.weighty = 1.0;
171         add(messagePanel, gridBagConstraints);
172
173         configPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
174
175         jLabel2.setLabelFor(periodComboBox);
176         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jLabel2.text"));
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 8, 0, 5);
181         configPanel.add(jLabel2, gridBagConstraints);
182
183         periodComboBox.addActionListener(formListener);
184
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
187         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
188         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 0);
189         configPanel.add(periodComboBox, gridBagConstraints);
190
191         org.openide.awt.Mnemonics.setLocalizedText(beforeCheckBox, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jCheckBox1.text"));
192         beforeCheckBox.addActionListener(formListener);
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
196         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
197         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 0, 0);
198         configPanel.add(beforeCheckBox, gridBagConstraints);
199
200         org.openide.awt.Mnemonics.setLocalizedText(negativCheckBox, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jCheckBox2.text"));
201         negativCheckBox.addActionListener(formListener);
202
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 0;
205         gridBagConstraints.gridy = 2;
206         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
208         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 8, 0);
209         configPanel.add(negativCheckBox, gridBagConstraints);
210
211         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
212         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
213         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
215         gridBagConstraints.weightx = 1.0;
216         gridBagConstraints.weighty = 1.0;
217         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
218         add(configPanel, gridBagConstraints);
219
220         extSettingsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
221
222         extSettingsPanel.setPreferredSize(new java.awt.Dimension JavaDoc(350, 200));
223         org.openide.awt.Mnemonics.setLocalizedText(proxyButton, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.proxyButton.text"));
224         proxyButton.setPreferredSize(new java.awt.Dimension JavaDoc(139, 27));
225         proxyButton.addActionListener(formListener);
226
227         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints.gridx = 0;
229         gridBagConstraints.gridy = 2;
230         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
231         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
232         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
233         extSettingsPanel.add(proxyButton, gridBagConstraints);
234
235         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
237         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
238         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
239         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
240         gridBagConstraints.weightx = 1.0;
241         gridBagConstraints.weighty = 1.0;
242         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
243         add(extSettingsPanel, gridBagConstraints);
244
245     }
246
247     // Code for dispatching events from components to event handlers.
248

249     private class FormListener implements java.awt.event.ActionListener JavaDoc {
250         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
251             if (evt.getSource() == configCheckBox) {
252                 AutoCheckInfo.this.configButtonActionPerformed(evt);
253             }
254             else if (evt.getSource() == periodComboBox) {
255                 AutoCheckInfo.this.periodComboBoxActionPerformed(evt);
256             }
257             else if (evt.getSource() == beforeCheckBox) {
258                 AutoCheckInfo.this.beforeCheckBoxActionPerformed(evt);
259             }
260             else if (evt.getSource() == negativCheckBox) {
261                 AutoCheckInfo.this.negativCheckBoxActionPerformed(evt);
262             }
263             else if (evt.getSource() == proxyButton) {
264                 AutoCheckInfo.this.proxyButtonActionPerformed(evt);
265             }
266         }
267     }// </editor-fold>//GEN-END:initComponents
268

269     private void proxyButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_proxyButtonActionPerformed
270
OptionsDisplayer.getDefault ().open ("General");
271     }//GEN-LAST:event_proxyButtonActionPerformed
272

273     private void periodComboBoxActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_periodComboBoxActionPerformed
274
settings.setPeriod( periodComboBox.getSelectedIndex() );
275     }//GEN-LAST:event_periodComboBoxActionPerformed
276

277     private void negativCheckBoxActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_negativCheckBoxActionPerformed
278
settings.setNegativeResults( negativCheckBox.isSelected() );
279     }//GEN-LAST:event_negativCheckBoxActionPerformed
280

281     private void beforeCheckBoxActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_beforeCheckBoxActionPerformed
282
settings.setAskBefore( beforeCheckBox.isSelected() );
283     }//GEN-LAST:event_beforeCheckBoxActionPerformed
284

285     private void configButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configButtonActionPerformed
286
configPanel.setVisible( configCheckBox.isSelected() );
287         extSettingsPanel.setVisible( configCheckBox.isSelected() );
288
289         if ( getTopLevelAncestor() instanceof java.awt.Window JavaDoc ) {
290             ((java.awt.Window JavaDoc)getTopLevelAncestor()).pack();
291         }
292
293     }//GEN-LAST:event_configButtonActionPerformed
294

295
296     // Variables declaration - do not modify//GEN-BEGIN:variables
297
private javax.swing.JCheckBox JavaDoc beforeCheckBox;
298     private javax.swing.JCheckBox JavaDoc configCheckBox;
299     private javax.swing.JPanel JavaDoc configPanel;
300     private javax.swing.JPanel JavaDoc extSettingsPanel;
301     private javax.swing.JLabel JavaDoc iconLabel;
302     private javax.swing.JLabel JavaDoc jLabel2;
303     private javax.swing.JPanel JavaDoc messagePanel;
304     private javax.swing.JTextArea JavaDoc messageText;
305     private javax.swing.JCheckBox JavaDoc negativCheckBox;
306     private javax.swing.JComboBox JavaDoc periodComboBox;
307     private javax.swing.JButton JavaDoc proxyButton;
308     // End of variables declaration//GEN-END:variables
309

310     boolean showDialog(boolean yesNo) {
311         //if ( dialog == null ) {
312
DialogDescriptor dd = createDialog(yesNo);
313         //}
314

315         //dialog.invalidate();
316
//dialog.pack();
317

318         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
319         dialog.setVisible(true); // will block
320
dialog.setVisible(false);
321         dialog.dispose();
322         return yesNo ? dd.getValue() == DialogDescriptor.YES_OPTION : true ;
323     }
324
325     private DialogDescriptor createDialog(boolean yesNo) {
326
327         DialogDescriptor dd;
328
329         if ( yesNo ) {
330             dd = new DialogDescriptor(
331                      this,
332                      NbBundle.getBundle(AutoCheckInfo.class).getString( "CTL_AutoCheck_Title" ),
333                      true, // Modal
334
DialogDescriptor.YES_NO_OPTION, // Option list
335
DialogDescriptor.YES_OPTION, // Default
336
DialogDescriptor.BOTTOM_ALIGN, // Align
337
null, //new HelpCtx ( AutoCheckInfo.class ), // Help
338
null );
339         }
340         else {
341             dd = new DialogDescriptor(
342                      this,
343                      NbBundle.getBundle(AutoCheckInfo.class).getString( "CTL_AutoCheck_Title" ),
344                      true, // Modal
345
new Object JavaDoc [] { DialogDescriptor.OK_OPTION }, // Option list
346
DialogDescriptor.OK_OPTION, // Default
347
DialogDescriptor.BOTTOM_ALIGN, // Align
348
null, //new HelpCtx ( AutoCheckInfo.class ), // Help
349
null );
350             dd.setClosingOptions( null );
351         }
352         return dd;
353     }
354
355
356     /** Gets the right icon */
357
358     private static javax.swing.Icon JavaDoc getIconForType(int messageType) {
359         if(messageType < 0 || messageType > 3)
360             return null;
361         switch(messageType) {
362         case 0:
363             return javax.swing.UIManager.getIcon("OptionPane.errorIcon"); // NOI18N
364
case 1:
365             return javax.swing.UIManager.getIcon("OptionPane.informationIcon"); // NOI18N
366
case 2:
367             return javax.swing.UIManager.getIcon("OptionPane.warningIcon"); // NOI18N
368
case 3:
369             return javax.swing.UIManager.getIcon("OptionPane.questionIcon"); // NOI18N
370
}
371         return null;
372     }
373 }
374
Popular Tags