1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.awt.Dialog ; 23 import javax.swing.JPanel ; 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 33 class AutoCheckInfo extends javax.swing.JPanel { 34 35 private Settings settings; 36 37 38 private int prefX = 0; 39 40 private java.awt.Dimension prefSize = null; 41 42 43 public AutoCheckInfo( String 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 [] 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 lPanel = new ServerPanel(); 68 java.awt.GridBagConstraints gridBagConstraints4 = new java.awt.GridBagConstraints (); 69 gridBagConstraints4.insets = new java.awt.Insets (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 (NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.configBorder"))); 79 extSettingsPanel.setBorder (new javax.swing.border.TitledBorder (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 96 97 public java.awt.Dimension getPreferredSize() { 98 if ( prefX == 0 ) { 99 return super.getPreferredSize(); 100 } 101 102 prefSize = super.getPreferredSize(); 104 prefSize.width = java.lang.Math.max( prefSize.width, prefX ); 105 106 return prefSize; 107 } 108 109 110 115 private void initComponents() { 117 java.awt.GridBagConstraints gridBagConstraints; 118 119 messagePanel = new javax.swing.JPanel (); 120 iconLabel = new javax.swing.JLabel (); 121 messageText = new javax.swing.JTextArea (); 122 configCheckBox = new javax.swing.JCheckBox (); 123 configPanel = new javax.swing.JPanel (); 124 jLabel2 = new javax.swing.JLabel (); 125 periodComboBox = new javax.swing.JComboBox (); 126 beforeCheckBox = new javax.swing.JCheckBox (); 127 negativCheckBox = new javax.swing.JCheckBox (); 128 extSettingsPanel = new javax.swing.JPanel (); 129 proxyButton = new javax.swing.JButton (); 130 131 FormListener formListener = new FormListener(); 132 133 setLayout(new java.awt.GridBagLayout ()); 134 135 setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); 136 messagePanel.setLayout(new java.awt.GridBagLayout ()); 137 138 iconLabel.setLabelFor(configCheckBox); 139 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 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 (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 (); 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 (8, 18, 0, 0); 164 messagePanel.add(configCheckBox, gridBagConstraints); 165 166 gridBagConstraints = new java.awt.GridBagConstraints (); 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 ()); 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 (); 178 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 179 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 180 gridBagConstraints.insets = new java.awt.Insets (4, 8, 0, 5); 181 configPanel.add(jLabel2, gridBagConstraints); 182 183 periodComboBox.addActionListener(formListener); 184 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 187 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 188 gridBagConstraints.insets = new java.awt.Insets (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 (); 195 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 196 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 197 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (0, 8, 8, 0); 209 configPanel.add(negativCheckBox, gridBagConstraints); 210 211 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 0, 0, 0); 218 add(configPanel, gridBagConstraints); 219 220 extSettingsPanel.setLayout(new java.awt.GridBagLayout ()); 221 222 extSettingsPanel.setPreferredSize(new java.awt.Dimension (350, 200)); 223 org.openide.awt.Mnemonics.setLocalizedText(proxyButton, NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.proxyButton.text")); 224 proxyButton.setPreferredSize(new java.awt.Dimension (139, 27)); 225 proxyButton.addActionListener(formListener); 226 227 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 12, 12, 0); 233 extSettingsPanel.add(proxyButton, gridBagConstraints); 234 235 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 0, 0, 0); 243 add(extSettingsPanel, gridBagConstraints); 244 245 } 246 247 249 private class FormListener implements java.awt.event.ActionListener { 250 public void actionPerformed(java.awt.event.ActionEvent 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 } 269 private void proxyButtonActionPerformed (java.awt.event.ActionEvent evt) { OptionsDisplayer.getDefault ().open ("General"); 271 } 273 private void periodComboBoxActionPerformed (java.awt.event.ActionEvent evt) { settings.setPeriod( periodComboBox.getSelectedIndex() ); 275 } 277 private void negativCheckBoxActionPerformed (java.awt.event.ActionEvent evt) { settings.setNegativeResults( negativCheckBox.isSelected() ); 279 } 281 private void beforeCheckBoxActionPerformed (java.awt.event.ActionEvent evt) { settings.setAskBefore( beforeCheckBox.isSelected() ); 283 } 285 private void configButtonActionPerformed (java.awt.event.ActionEvent evt) { configPanel.setVisible( configCheckBox.isSelected() ); 287 extSettingsPanel.setVisible( configCheckBox.isSelected() ); 288 289 if ( getTopLevelAncestor() instanceof java.awt.Window ) { 290 ((java.awt.Window )getTopLevelAncestor()).pack(); 291 } 292 293 } 295 296 private javax.swing.JCheckBox beforeCheckBox; 298 private javax.swing.JCheckBox configCheckBox; 299 private javax.swing.JPanel configPanel; 300 private javax.swing.JPanel extSettingsPanel; 301 private javax.swing.JLabel iconLabel; 302 private javax.swing.JLabel jLabel2; 303 private javax.swing.JPanel messagePanel; 304 private javax.swing.JTextArea messageText; 305 private javax.swing.JCheckBox negativCheckBox; 306 private javax.swing.JComboBox periodComboBox; 307 private javax.swing.JButton proxyButton; 308 310 boolean showDialog(boolean yesNo) { 311 DialogDescriptor dd = createDialog(yesNo); 313 315 318 Dialog dialog = DialogDisplayer.getDefault().createDialog( dd ); 319 dialog.setVisible(true); 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, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.YES_OPTION, DialogDescriptor.BOTTOM_ALIGN, null, null ); 339 } 340 else { 341 dd = new DialogDescriptor( 342 this, 343 NbBundle.getBundle(AutoCheckInfo.class).getString( "CTL_AutoCheck_Title" ), 344 true, new Object [] { DialogDescriptor.OK_OPTION }, DialogDescriptor.OK_OPTION, DialogDescriptor.BOTTOM_ALIGN, null, null ); 350 dd.setClosingOptions( null ); 351 } 352 return dd; 353 } 354 355 356 357 358 private static javax.swing.Icon 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"); case 1: 365 return javax.swing.UIManager.getIcon("OptionPane.informationIcon"); case 2: 367 return javax.swing.UIManager.getIcon("OptionPane.warningIcon"); case 3: 369 return javax.swing.UIManager.getIcon("OptionPane.questionIcon"); } 371 return null; 372 } 373 } 374 | Popular Tags |