KickJava   Java API By Example, From Geeks To Geeks.

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


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.Font JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JButton JavaDoc;
26 import org.netbeans.api.options.OptionsDisplayer;
27 import org.openide.DialogDescriptor;
28 import org.openide.DialogDisplayer;
29 import org.openide.NotifyDescriptor;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Jiri Rechtacek
35  */

36 public class ConnectingErrorDialog extends javax.swing.JPanel JavaDoc {
37
38     /** Type of the dialog */
39     private static int type;
40     private static String JavaDoc serverMessage;
41
42     ConnectingErrorDialog () {
43         this (false, null);
44     }
45     
46     /**
47      * Creates new form ConnectingErrorDialog
48      */

49     private ConnectingErrorDialog (boolean hasInner, JButton JavaDoc okButton) {
50         if (hasInner) {
51             assert okButton != null : "okButton must exist if the dialog hasInner";
52             initComponents ();
53             okButton.addActionListener (new ActionListener JavaDoc () {
54                 public void actionPerformed (ActionEvent JavaDoc evt) {
55                     AutoChecker.doCheck ();
56                 }
57             });
58         } else {
59             initComponentsWithoutInner ();
60         }
61     }
62     
63     private void initComponentsWithoutInner () {
64         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
65
66         jLabel1 = new javax.swing.JLabel JavaDoc();
67         jTextArea1 = new javax.swing.JTextArea JavaDoc();
68
69         setLayout(new java.awt.GridBagLayout JavaDoc());
70
71         setName(getDialogTitle (type));
72         getAccessibleContext().setAccessibleName(getDialogTitle (type));
73         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACSD_ConnError"));
74         // don't use deriveFont() - see #49973 for details
75
jLabel1.setFont(ResultsPanel.doDeriveFont(jLabel1.getFont(), Font.BOLD));
76         jLabel1.setLabelFor(jTextArea1);
77         jLabel1.setText (getMessageLabel (type));
78         jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
79         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
80         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
81         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
82         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 4, 0);
83         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_ConnectingErrorDialog_jLabel1"));
84         add(jLabel1, gridBagConstraints);
85
86         jTextArea1.setBackground(jLabel1.getBackground());
87         jTextArea1.setEditable(false);
88         jTextArea1.setLineWrap(true);
89         jTextArea1.setText (getMessageText (type, serverMessage));
90         jTextArea1.setWrapStyleWord(true);
91         jTextArea1.setRows (4);
92         
93         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
95         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
96         gridBagConstraints.weightx = 1.0;
97         gridBagConstraints.weighty = 1.0;
98         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
99         
100         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
101         add(jTextArea1, gridBagConstraints);
102         
103         jTextArea1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACN_ConnectingErrorDialog_jTextArea1"));
104         jTextArea1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_ConnectingErrorDialog_jTextArea1"));
105     }
106     
107     /** This method is called from within the constructor to
108      * initialize the form.
109      * WARNING: Do NOT modify this code. The content of this method is
110      * always regenerated by the Form Editor.
111      */

112     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
113
private void initComponents() {
114         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
115
116         jLabel1 = new javax.swing.JLabel JavaDoc();
117         jTextArea1 = new javax.swing.JTextArea JavaDoc();
118
119         setName(getDialogTitle (type));
120         setPreferredSize(new java.awt.Dimension JavaDoc(200, 100));
121         setLayout(new java.awt.GridBagLayout JavaDoc());
122
123         jLabel1.setLabelFor(jTextArea1);
124         jLabel1.setText(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "CTL_NoNetwork_titleLabel")); // NOI18N
125
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
126         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints.gridx = 0;
128         gridBagConstraints.gridy = 0;
129         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
130         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
131         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 8, 0);
132         add(jLabel1, gridBagConstraints);
133         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_ConnectingErrorDialog_jLabel1")); // NOI18N
134

135         jTextArea1.setBackground(jLabel1.getBackground());
136         jTextArea1.setEditable(false);
137         jTextArea1.setLineWrap(true);
138         jTextArea1.setText(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "CTL_NoNetwork_textLabel")); // NOI18N
139
jTextArea1.setWrapStyleWord(true);
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
141         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
143         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
144         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 6, 0);
145         add(jTextArea1, gridBagConstraints);
146         jTextArea1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACN_NoNetwork_textLabel")); // NOI18N
147
jTextArea1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_NoNetwork_textLabel")); // NOI18N
148

149         getAccessibleContext().setAccessibleName(getDialogTitle (type));
150         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACSD_ConnError")); // NOI18N
151
}// </editor-fold>//GEN-END:initComponents
152

153     
154     // Variables declaration - do not modify//GEN-BEGIN:variables
155
private javax.swing.JLabel JavaDoc jLabel1;
156     private javax.swing.JTextArea JavaDoc jTextArea1;
157     // End of variables declaration//GEN-END:variables
158

159     private static String JavaDoc getDialogTitle (int errorType) {
160         switch (errorType) {
161             case Updates.NO_AVAILABLE_MODULES:
162                 return getBundle ("CTL_Information");
163             case Updates.NO_SERVER_ERROR:
164                 return getBundle ("CTL_Warning");
165             default:
166                 return getBundle ("CTL_Error");
167         }
168     }
169     
170     private static int getDialogIcon (int errorType) {
171         switch (errorType) {
172             case Updates.NO_AVAILABLE_MODULES:
173                 return NotifyDescriptor.INFORMATION_MESSAGE;
174             case Updates.NO_SERVER_ERROR:
175                 return NotifyDescriptor.WARNING_MESSAGE;
176             default:
177                 return NotifyDescriptor.ERROR_MESSAGE;
178         }
179     }
180     
181     static private String JavaDoc getMessageLabel (int errorType) {
182         switch (errorType) {
183             case Updates.NO_AVAILABLE_MODULES:
184                 return getBundle ("CTL_NoAvailableModules_titleLabel");
185             case Updates.NO_SERVER_ERROR:
186                 return getBundle ("CTL_NoServer_titleLabel");
187             case Updates.NO_NETWORK:
188                 return getBundle ("CTL_NoNetwork_titleLabel");
189             case Updates.AUTH_ERROR:
190                 return getBundle ("CTL_Invalid_titleLabel");
191             case Updates.PARSE_ERROR:
192                 return getBundle ("CTL_ParseError_titleLabel");
193             default:
194                 assert false : "Unknown error type " + errorType;
195         }
196         return null;
197     }
198
199     static private String JavaDoc getMessageText (int errorType, String JavaDoc serverMessage) {
200         switch (errorType) {
201             case Updates.NO_AVAILABLE_MODULES:
202                 if (serverMessage == null) {
203                     serverMessage = getBundle ("CTL_DefaultServer");
204                 }
205                 return NbBundle.getMessage (ConnectingErrorDialog.class, "CTL_NoAvailableModules_textLabel", serverMessage);
206             case Updates.NO_SERVER_ERROR:
207                 return getBundle ("CTL_NoServer_textLabel");
208             case Updates.NO_NETWORK:
209                 if (serverMessage != null) {
210                     return serverMessage;
211                 } else {
212                     return getBundle ("CTL_NoNetwork_textLabel");
213                 }
214             case Updates.AUTH_ERROR:
215                 return getBundle ("CTL_Invalid_textLabel");
216             case Updates.PARSE_ERROR:
217                 return getBundle ("CTL_ParseError_textLabel");
218             default:
219                 assert false : "Unknown error type " + errorType;
220         }
221         return null;
222     }
223
224     private static DialogDescriptor createDialogDescriptor (boolean fromAutoCheck) {
225         DialogDescriptor dd;
226         
227         if (Updates.NO_NETWORK == type) {
228             if (fromAutoCheck) {
229                 final JButton JavaDoc continueButton = new JButton JavaDoc ();
230                 continueButton.setEnabled (true);
231                 org.openide.awt.Mnemonics.setLocalizedText (continueButton, getBundle( "CTL_Error_Continue" ));
232                 continueButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_Continue" ) );
233
234                 final JButton JavaDoc cancelButton = new JButton JavaDoc(getBundle( "CTL_Error_Cancel" ) );
235                 cancelButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_Cancel" ) );
236
237                 dd = new DialogDescriptor(
238                      new ConnectingErrorDialog (true, continueButton),
239                      getDialogTitle (type),
240                      true, // Modal
241
new Object JavaDoc [] {continueButton, cancelButton}, // Option list
242
continueButton, // Default
243
DialogDescriptor.DEFAULT_ALIGN, // Align
244
null, //new HelpCtx ( ConnectingErrorDialog.class ), // Help
245
null
246                  );
247                 
248                 JButton JavaDoc showProxyOptions = new JButton JavaDoc ();
249                 org.openide.awt.Mnemonics.setLocalizedText (showProxyOptions, getBundle ("CTL_ShowProxyOptions"));
250                 showProxyOptions.getAccessibleContext().setAccessibleDescription (getBundle ("ACSD_ShowProxyOptions"));
251                 showProxyOptions.addActionListener (new ActionListener JavaDoc () {
252                     public void actionPerformed(ActionEvent JavaDoc arg0) {
253                         OptionsDisplayer.getDefault ().open ("General");
254                     }
255                 });
256                 dd.setAdditionalOptions (new Object JavaDoc[] {showProxyOptions});
257                 dd.setClosingOptions (new Object JavaDoc [] {continueButton, cancelButton});
258                 
259             } else {
260                 // bugfix #40917, mnemonic on default OK button is useless
261
final JButton JavaDoc okButton = new JButton JavaDoc(getBundle( "CTL_Error_OK" ) );
262                 okButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_OK" ) );
263
264                 // default options
265
dd = new DialogDescriptor (
266                      new ConnectingErrorDialog (false, null),
267                      getDialogTitle (type),
268                      true, // Modal
269
new Object JavaDoc [] {okButton}, // Option list
270
okButton, // Default
271
DialogDescriptor.DEFAULT_ALIGN, // Align
272
null, //new HelpCtx ( ConnectingErrorDialog.class ), // Help
273
null
274                  );
275             }
276         } else {
277                 // bugfix #40917, mnemonic on default OK button is useless
278
final JButton JavaDoc okButton = new JButton JavaDoc(getBundle( "CTL_Error_OK" ) );
279                 okButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_OK" ) );
280
281                 // default options
282
dd = new DialogDescriptor (
283                      new ConnectingErrorDialog (false, null),
284                      getDialogTitle (type),
285                      true, // Modal
286
new Object JavaDoc [] {okButton}, // Option list
287
okButton, // Default
288
DialogDescriptor.DEFAULT_ALIGN, // Align
289
null, //new HelpCtx ( ConnectingErrorDialog.class ), // Help
290
null
291                  );
292         }
293         dd.setMessageType (getDialogIcon (type));
294         return dd;
295     }
296     
297     static void showDialog(int type, String JavaDoc serverMessage) {
298         showDialog (type, serverMessage, false);
299     }
300     
301     static void showDialog(int type, String JavaDoc serverMessage, boolean fromAutoCheck) {
302         ConnectingErrorDialog.type = type;
303         ConnectingErrorDialog.serverMessage = serverMessage;
304         DialogDescriptor dd = createDialogDescriptor (fromAutoCheck);
305         java.awt.Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
306         //dialog.setResizable (false);
307
dialog.setVisible (true);
308         dialog.dispose();
309     }
310     
311     private static String JavaDoc getBundle( String JavaDoc key ) {
312         return NbBundle.getMessage( ConnectingErrorDialog.class, key );
313     }
314
315 }
316
Popular Tags