1 19 20 package org.netbeans.modules.httpserver; 21 22 import java.awt.event.*; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import org.openide.explorer.propertysheet.PropertyEnv; 26 import org.openide.util.Exceptions; 27 import org.openide.util.HelpCtx; 28 29 33 public class HostPropertyCustomEditor extends javax.swing.JPanel 34 implements HelpCtx.Provider, ActionListener, PropertyChangeListener { 35 private HostPropertyEditor editor; 36 37 38 public HostPropertyCustomEditor (HostPropertyEditor ed, PropertyEnv env) { 39 editor = ed; 40 initComponents (); 41 initAccessibility(); 42 anyRadioButton.addActionListener (this); 43 selectedRadioButton.addActionListener (this); 44 setPreferredSize (new java.awt.Dimension (300, 200)); 45 46 HttpServerSettings.HostProperty hp = (HttpServerSettings.HostProperty)editor.getValue (); 48 if (HttpServerSettings.ANYHOST.equals (hp.getHost ())) { 49 anyRadioButton.setSelected (true); 50 grantTextArea.setText (""); } 52 else if (HttpServerSettings.LOCALHOST.equals (hp.getHost ())) { 53 selectedRadioButton.setSelected (true); 54 grantTextArea.setText (hp.getGrantedAddresses ()); 55 } 56 57 env.setState(PropertyEnv.STATE_NEEDS_VALIDATION); 58 env.addPropertyChangeListener(this); 59 } 60 61 public void actionPerformed (ActionEvent event) { 62 try { 63 if (event.getSource() == anyRadioButton) { 64 grantLabel.setEnabled (false); 65 grantTextArea.setEnabled (false); 66 } 67 else if (event.getSource() == selectedRadioButton) { 68 grantLabel.setEnabled (true); 69 grantTextArea.setEnabled (true); 70 } 71 } catch (Exception e) { 72 Exceptions.printStackTrace(e); 73 } 74 } 75 76 private void initAccessibility() 77 { 78 hostLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_HostLabelA11yDesc")); 79 grantLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_GrantLabelA11yDesc")); 80 grantTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_GrantTextAreaA11yName")); 81 getAccessibleContext().setAccessibleDescription (org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_HostPropertyPanelA11yDesc")); 82 } 83 84 89 private void initComponents() { 91 java.awt.GridBagConstraints gridBagConstraints; 92 93 buttonGroup = new javax.swing.ButtonGroup (); 94 hostLabel = new javax.swing.JLabel (); 95 anyRadioButton = new javax.swing.JRadioButton (); 96 selectedRadioButton = new javax.swing.JRadioButton (); 97 grantLabel = new javax.swing.JLabel (); 98 grantScrollPane = new javax.swing.JScrollPane (); 99 grantTextArea = new javax.swing.JTextArea (); 100 101 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11)); 102 setLayout(new java.awt.GridBagLayout ()); 103 104 org.openide.awt.Mnemonics.setLocalizedText(hostLabel, org.openide.util.NbBundle.getBundle("org/netbeans/modules/httpserver/Bundle").getString("CTL_HostLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 106 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 107 add(hostLabel, gridBagConstraints); 108 109 buttonGroup.add(anyRadioButton); 110 org.openide.awt.Mnemonics.setLocalizedText(anyRadioButton, org.openide.util.NbBundle.getBundle("org/netbeans/modules/httpserver/Bundle").getString("CTL_AnyRadioButton")); anyRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_AnyRadioButtonA11yDesc")); gridBagConstraints = new java.awt.GridBagConstraints (); 113 gridBagConstraints.gridx = 0; 114 gridBagConstraints.gridy = 1; 115 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 116 add(anyRadioButton, gridBagConstraints); 117 118 buttonGroup.add(selectedRadioButton); 119 selectedRadioButton.setSelected(true); 120 org.openide.awt.Mnemonics.setLocalizedText(selectedRadioButton, org.openide.util.NbBundle.getBundle("org/netbeans/modules/httpserver/Bundle").getString("CTL_SelectedRadioButton")); selectedRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_SelectedRadioButtonA11yDesc")); gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.gridx = 0; 124 gridBagConstraints.gridy = 2; 125 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 126 add(selectedRadioButton, gridBagConstraints); 127 128 org.openide.awt.Mnemonics.setLocalizedText(grantLabel, org.openide.util.NbBundle.getBundle("org/netbeans/modules/httpserver/Bundle").getString("CTL_GrantLabel")); grantLabel.setLabelFor(grantTextArea); 130 gridBagConstraints = new java.awt.GridBagConstraints (); 131 gridBagConstraints.gridx = 0; 132 gridBagConstraints.gridy = 3; 133 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 134 gridBagConstraints.insets = new java.awt.Insets (12, 0, 2, 0); 135 add(grantLabel, gridBagConstraints); 136 137 grantTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_GrantTextAreaA11yDesc")); grantScrollPane.setViewportView(grantTextArea); 139 140 gridBagConstraints = new java.awt.GridBagConstraints (); 141 gridBagConstraints.gridx = 0; 142 gridBagConstraints.gridy = 4; 143 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 144 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 145 gridBagConstraints.weightx = 1.0; 146 gridBagConstraints.weighty = 1.0; 147 add(grantScrollPane, gridBagConstraints); 148 } 150 private java.lang.Object getPropertyValue () throws java.lang.IllegalStateException { 151 if (anyRadioButton.isSelected ()) 152 return new HttpServerSettings.HostProperty ("", HttpServerSettings.ANYHOST); else if (selectedRadioButton.isSelected ()) 154 return new HttpServerSettings.HostProperty (grantTextArea.getText (), HttpServerSettings.LOCALHOST); 155 156 throw new IllegalStateException (); 157 } 158 159 160 private javax.swing.JRadioButton anyRadioButton; 162 private javax.swing.ButtonGroup buttonGroup; 163 private javax.swing.JLabel grantLabel; 164 private javax.swing.JScrollPane grantScrollPane; 165 private javax.swing.JTextArea grantTextArea; 166 private javax.swing.JLabel hostLabel; 167 private javax.swing.JRadioButton selectedRadioButton; 168 170 173 public HelpCtx getHelpCtx() { 174 String helpid = HttpServerNode.class.getName()+"_properties"; return new HelpCtx(helpid); 176 } 177 178 public void propertyChange(PropertyChangeEvent evt) { 179 if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName()) && evt.getNewValue() == PropertyEnv.STATE_VALID) { 180 editor.setValue(getPropertyValue()); 181 } 182 } 183 } 184 | Popular Tags |