1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.awt.Font ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.JButton ; 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 36 public class ConnectingErrorDialog extends javax.swing.JPanel { 37 38 39 private static int type; 40 private static String serverMessage; 41 42 ConnectingErrorDialog () { 43 this (false, null); 44 } 45 46 49 private ConnectingErrorDialog (boolean hasInner, JButton okButton) { 50 if (hasInner) { 51 assert okButton != null : "okButton must exist if the dialog hasInner"; 52 initComponents (); 53 okButton.addActionListener (new ActionListener () { 54 public void actionPerformed (ActionEvent evt) { 55 AutoChecker.doCheck (); 56 } 57 }); 58 } else { 59 initComponentsWithoutInner (); 60 } 61 } 62 63 private void initComponentsWithoutInner () { 64 java.awt.GridBagConstraints gridBagConstraints; 65 66 jLabel1 = new javax.swing.JLabel (); 67 jTextArea1 = new javax.swing.JTextArea (); 68 69 setLayout(new java.awt.GridBagLayout ()); 70 71 setName(getDialogTitle (type)); 72 getAccessibleContext().setAccessibleName(getDialogTitle (type)); 73 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACSD_ConnError")); 74 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 (); 80 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 81 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 82 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (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 112 private void initComponents() { 114 java.awt.GridBagConstraints gridBagConstraints; 115 116 jLabel1 = new javax.swing.JLabel (); 117 jTextArea1 = new javax.swing.JTextArea (); 118 119 setName(getDialogTitle (type)); 120 setPreferredSize(new java.awt.Dimension (200, 100)); 121 setLayout(new java.awt.GridBagLayout ()); 122 123 jLabel1.setLabelFor(jTextArea1); 124 jLabel1.setText(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "CTL_NoNetwork_titleLabel")); jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); 126 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 8, 8, 0); 132 add(jLabel1, gridBagConstraints); 133 jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_ConnectingErrorDialog_jLabel1")); 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")); jTextArea1.setWrapStyleWord(true); 140 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 8, 6, 0); 145 add(jTextArea1, gridBagConstraints); 146 jTextArea1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACN_NoNetwork_textLabel")); jTextArea1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACD_NoNetwork_textLabel")); 149 getAccessibleContext().setAccessibleName(getDialogTitle (type)); 150 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectingErrorDialog.class, "ACSD_ConnError")); } 153 154 private javax.swing.JLabel jLabel1; 156 private javax.swing.JTextArea jTextArea1; 157 159 private static String 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 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 getMessageText (int errorType, String 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 continueButton = new JButton (); 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 cancelButton = new JButton (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, new Object [] {continueButton, cancelButton}, continueButton, DialogDescriptor.DEFAULT_ALIGN, null, null 246 ); 247 248 JButton showProxyOptions = new JButton (); 249 org.openide.awt.Mnemonics.setLocalizedText (showProxyOptions, getBundle ("CTL_ShowProxyOptions")); 250 showProxyOptions.getAccessibleContext().setAccessibleDescription (getBundle ("ACSD_ShowProxyOptions")); 251 showProxyOptions.addActionListener (new ActionListener () { 252 public void actionPerformed(ActionEvent arg0) { 253 OptionsDisplayer.getDefault ().open ("General"); 254 } 255 }); 256 dd.setAdditionalOptions (new Object [] {showProxyOptions}); 257 dd.setClosingOptions (new Object [] {continueButton, cancelButton}); 258 259 } else { 260 final JButton okButton = new JButton (getBundle( "CTL_Error_OK" ) ); 262 okButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_OK" ) ); 263 264 dd = new DialogDescriptor ( 266 new ConnectingErrorDialog (false, null), 267 getDialogTitle (type), 268 true, new Object [] {okButton}, okButton, DialogDescriptor.DEFAULT_ALIGN, null, null 274 ); 275 } 276 } else { 277 final JButton okButton = new JButton (getBundle( "CTL_Error_OK" ) ); 279 okButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Error_OK" ) ); 280 281 dd = new DialogDescriptor ( 283 new ConnectingErrorDialog (false, null), 284 getDialogTitle (type), 285 true, new Object [] {okButton}, okButton, DialogDescriptor.DEFAULT_ALIGN, null, null 291 ); 292 } 293 dd.setMessageType (getDialogIcon (type)); 294 return dd; 295 } 296 297 static void showDialog(int type, String serverMessage) { 298 showDialog (type, serverMessage, false); 299 } 300 301 static void showDialog(int type, String serverMessage, boolean fromAutoCheck) { 302 ConnectingErrorDialog.type = type; 303 ConnectingErrorDialog.serverMessage = serverMessage; 304 DialogDescriptor dd = createDialogDescriptor (fromAutoCheck); 305 java.awt.Dialog dialog = DialogDisplayer.getDefault().createDialog( dd ); 306 dialog.setVisible (true); 308 dialog.dispose(); 309 } 310 311 private static String getBundle( String key ) { 312 return NbBundle.getMessage( ConnectingErrorDialog.class, key ); 313 } 314 315 } 316 | Popular Tags |