001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.httpserver;
043:
044: import java.awt.event.*;
045: import java.beans.PropertyChangeEvent;
046: import java.beans.PropertyChangeListener;
047: import org.openide.explorer.propertysheet.PropertyEnv;
048: import org.openide.util.Exceptions;
049: import org.openide.util.HelpCtx;
050:
051: /**
052: *
053: * @author Gabriel Tichy
054: */
055: public class HostPropertyCustomEditor extends javax.swing.JPanel
056: implements HelpCtx.Provider, ActionListener,
057: PropertyChangeListener {
058: private HostPropertyEditor editor;
059:
060: /** Creates new form HostEditorPanel */
061: public HostPropertyCustomEditor(HostPropertyEditor ed,
062: PropertyEnv env) {
063: editor = ed;
064: initComponents();
065: initAccessibility();
066: anyRadioButton.addActionListener(this );
067: selectedRadioButton.addActionListener(this );
068: setPreferredSize(new java.awt.Dimension(300, 200));
069:
070: // set values from PropertyEditor
071: HttpServerSettings.HostProperty hp = (HttpServerSettings.HostProperty) editor
072: .getValue();
073: if (HttpServerSettings.ANYHOST.equals(hp.getHost())) {
074: anyRadioButton.setSelected(true);
075: grantTextArea.setText(""); // NOI18N
076: } else if (HttpServerSettings.LOCALHOST.equals(hp.getHost())) {
077: selectedRadioButton.setSelected(true);
078: grantTextArea.setText(hp.getGrantedAddresses());
079: }
080:
081: env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
082: env.addPropertyChangeListener(this );
083: }
084:
085: public void actionPerformed(ActionEvent event) {
086: try {
087: if (event.getSource() == anyRadioButton) {
088: grantLabel.setEnabled(false);
089: grantTextArea.setEnabled(false);
090: } else if (event.getSource() == selectedRadioButton) {
091: grantLabel.setEnabled(true);
092: grantTextArea.setEnabled(true);
093: }
094: } catch (Exception e) {
095: Exceptions.printStackTrace(e);
096: }
097: }
098:
099: private void initAccessibility() {
100: hostLabel.getAccessibleContext().setAccessibleDescription(
101: org.openide.util.NbBundle.getBundle(
102: HostPropertyCustomEditor.class).getString(
103: "ACS_HostLabelA11yDesc"));
104: grantLabel.getAccessibleContext().setAccessibleDescription(
105: org.openide.util.NbBundle.getBundle(
106: HostPropertyCustomEditor.class).getString(
107: "ACS_GrantLabelA11yDesc"));
108: grantTextArea.getAccessibleContext().setAccessibleName(
109: org.openide.util.NbBundle.getBundle(
110: HostPropertyCustomEditor.class).getString(
111: "ACS_GrantTextAreaA11yName"));
112: getAccessibleContext().setAccessibleDescription(
113: org.openide.util.NbBundle.getBundle(
114: HostPropertyCustomEditor.class).getString(
115: "ACS_HostPropertyPanelA11yDesc"));
116: }
117:
118: /** This method is called from within the constructor to
119: * initialize the form.
120: * WARNING: Do NOT modify this code. The content of this method is
121: * always regenerated by the Form Editor.
122: */
123: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124: private void initComponents() {
125: java.awt.GridBagConstraints gridBagConstraints;
126:
127: buttonGroup = new javax.swing.ButtonGroup();
128: hostLabel = new javax.swing.JLabel();
129: anyRadioButton = new javax.swing.JRadioButton();
130: selectedRadioButton = new javax.swing.JRadioButton();
131: grantLabel = new javax.swing.JLabel();
132: grantScrollPane = new javax.swing.JScrollPane();
133: grantTextArea = new javax.swing.JTextArea();
134:
135: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
136: 11, 11));
137: setLayout(new java.awt.GridBagLayout());
138:
139: org.openide.awt.Mnemonics.setLocalizedText(hostLabel,
140: org.openide.util.NbBundle.getBundle(
141: "org/netbeans/modules/httpserver/Bundle")
142: .getString("CTL_HostLabel")); // NOI18N
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
145: add(hostLabel, gridBagConstraints);
146:
147: buttonGroup.add(anyRadioButton);
148: org.openide.awt.Mnemonics.setLocalizedText(anyRadioButton,
149: org.openide.util.NbBundle.getBundle(
150: "org/netbeans/modules/httpserver/Bundle")
151: .getString("CTL_AnyRadioButton")); // NOI18N
152: anyRadioButton.setToolTipText(org.openide.util.NbBundle
153: .getBundle(HostPropertyCustomEditor.class).getString(
154: "ACS_AnyRadioButtonA11yDesc")); // NOI18N
155: gridBagConstraints = new java.awt.GridBagConstraints();
156: gridBagConstraints.gridx = 0;
157: gridBagConstraints.gridy = 1;
158: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159: add(anyRadioButton, gridBagConstraints);
160:
161: buttonGroup.add(selectedRadioButton);
162: selectedRadioButton.setSelected(true);
163: org.openide.awt.Mnemonics.setLocalizedText(selectedRadioButton,
164: org.openide.util.NbBundle.getBundle(
165: "org/netbeans/modules/httpserver/Bundle")
166: .getString("CTL_SelectedRadioButton")); // NOI18N
167: selectedRadioButton.setToolTipText(org.openide.util.NbBundle
168: .getBundle(HostPropertyCustomEditor.class).getString(
169: "ACS_SelectedRadioButtonA11yDesc")); // NOI18N
170: gridBagConstraints = new java.awt.GridBagConstraints();
171: gridBagConstraints.gridx = 0;
172: gridBagConstraints.gridy = 2;
173: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174: add(selectedRadioButton, gridBagConstraints);
175:
176: org.openide.awt.Mnemonics.setLocalizedText(grantLabel,
177: org.openide.util.NbBundle.getBundle(
178: "org/netbeans/modules/httpserver/Bundle")
179: .getString("CTL_GrantLabel")); // NOI18N
180: grantLabel.setLabelFor(grantTextArea);
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 0;
183: gridBagConstraints.gridy = 3;
184: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185: gridBagConstraints.insets = new java.awt.Insets(12, 0, 2, 0);
186: add(grantLabel, gridBagConstraints);
187:
188: grantTextArea.setToolTipText(org.openide.util.NbBundle
189: .getBundle(HostPropertyCustomEditor.class).getString(
190: "ACS_GrantTextAreaA11yDesc")); // NOI18N
191: grantScrollPane.setViewportView(grantTextArea);
192:
193: gridBagConstraints = new java.awt.GridBagConstraints();
194: gridBagConstraints.gridx = 0;
195: gridBagConstraints.gridy = 4;
196: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
198: gridBagConstraints.weightx = 1.0;
199: gridBagConstraints.weighty = 1.0;
200: add(grantScrollPane, gridBagConstraints);
201: }// </editor-fold>//GEN-END:initComponents
202:
203: private java.lang.Object getPropertyValue()
204: throws java.lang.IllegalStateException {
205: if (anyRadioButton.isSelected())
206: return new HttpServerSettings.HostProperty("",
207: HttpServerSettings.ANYHOST); // NOI18N
208: else if (selectedRadioButton.isSelected())
209: return new HttpServerSettings.HostProperty(grantTextArea
210: .getText(), HttpServerSettings.LOCALHOST);
211:
212: throw new IllegalStateException();
213: }
214:
215: // Variables declaration - do not modify//GEN-BEGIN:variables
216: private javax.swing.JRadioButton anyRadioButton;
217: private javax.swing.ButtonGroup buttonGroup;
218: private javax.swing.JLabel grantLabel;
219: private javax.swing.JScrollPane grantScrollPane;
220: private javax.swing.JTextArea grantTextArea;
221: private javax.swing.JLabel hostLabel;
222: private javax.swing.JRadioButton selectedRadioButton;
223:
224: // End of variables declaration//GEN-END:variables
225:
226: /** Help context where to find more about the paste type action.
227: * @return the help context for this action
228: */
229: public HelpCtx getHelpCtx() {
230: String helpid = HostPropertyCustomEditor.class.getName()
231: + "_properties"; //NOI18N
232: return new HelpCtx(helpid);
233: }
234:
235: public void propertyChange(PropertyChangeEvent evt) {
236: if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName())
237: && evt.getNewValue() == PropertyEnv.STATE_VALID) {
238: editor.setValue(getPropertyValue());
239: }
240: }
241: }
|