KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > httpserver > HostPropertyCustomEditor


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.httpserver;
21
22 import java.awt.event.*;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import org.openide.explorer.propertysheet.PropertyEnv;
26 import org.openide.util.Exceptions;
27 import org.openide.util.HelpCtx;
28
29 /**
30  *
31  * @author Gabriel Tichy
32  */

33 public class HostPropertyCustomEditor extends javax.swing.JPanel JavaDoc
34         implements HelpCtx.Provider, ActionListener, PropertyChangeListener JavaDoc {
35     private HostPropertyEditor editor;
36
37     /** Creates new form HostEditorPanel */
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 JavaDoc (300, 200));
45         
46         // set values from PropertyEditor
47
HttpServerSettings.HostProperty hp = (HttpServerSettings.HostProperty)editor.getValue ();
48         if (HttpServerSettings.ANYHOST.equals (hp.getHost ())) {
49             anyRadioButton.setSelected (true);
50             grantTextArea.setText (""); // NOI18N
51
}
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 JavaDoc 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     /** This method is called from within the constructor to
85      * initialize the form.
86      * WARNING: Do NOT modify this code. The content of this method is
87      * always regenerated by the Form Editor.
88      */

89     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
90
private void initComponents() {
91         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
92
93         buttonGroup = new javax.swing.ButtonGroup JavaDoc();
94         hostLabel = new javax.swing.JLabel JavaDoc();
95         anyRadioButton = new javax.swing.JRadioButton JavaDoc();
96         selectedRadioButton = new javax.swing.JRadioButton JavaDoc();
97         grantLabel = new javax.swing.JLabel JavaDoc();
98         grantScrollPane = new javax.swing.JScrollPane JavaDoc();
99         grantTextArea = new javax.swing.JTextArea JavaDoc();
100
101         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
102         setLayout(new java.awt.GridBagLayout JavaDoc());
103
104         org.openide.awt.Mnemonics.setLocalizedText(hostLabel, org.openide.util.NbBundle.getBundle("org/netbeans/modules/httpserver/Bundle").getString("CTL_HostLabel")); // NOI18N
105
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
111
anyRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_AnyRadioButtonA11yDesc")); // NOI18N
112
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
121
selectedRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_SelectedRadioButtonA11yDesc")); // NOI18N
122
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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")); // NOI18N
129
grantLabel.setLabelFor(grantTextArea);
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 0;
132         gridBagConstraints.gridy = 3;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 2, 0);
135         add(grantLabel, gridBagConstraints);
136
137         grantTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(HostPropertyCustomEditor.class).getString("ACS_GrantTextAreaA11yDesc")); // NOI18N
138
grantScrollPane.setViewportView(grantTextArea);
139
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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     }// </editor-fold>//GEN-END:initComponents
149

150     private java.lang.Object JavaDoc getPropertyValue () throws java.lang.IllegalStateException JavaDoc {
151         if (anyRadioButton.isSelected ())
152             return new HttpServerSettings.HostProperty ("", HttpServerSettings.ANYHOST); // NOI18N
153
else if (selectedRadioButton.isSelected ())
154             return new HttpServerSettings.HostProperty (grantTextArea.getText (), HttpServerSettings.LOCALHOST);
155         
156         throw new IllegalStateException JavaDoc ();
157     }
158
159
160     // Variables declaration - do not modify//GEN-BEGIN:variables
161
private javax.swing.JRadioButton JavaDoc anyRadioButton;
162     private javax.swing.ButtonGroup JavaDoc buttonGroup;
163     private javax.swing.JLabel JavaDoc grantLabel;
164     private javax.swing.JScrollPane JavaDoc grantScrollPane;
165     private javax.swing.JTextArea JavaDoc grantTextArea;
166     private javax.swing.JLabel JavaDoc hostLabel;
167     private javax.swing.JRadioButton JavaDoc selectedRadioButton;
168     // End of variables declaration//GEN-END:variables
169

170     /** Help context where to find more about the paste type action.
171      * @return the help context for this action
172      */

173     public HelpCtx getHelpCtx() {
174         String JavaDoc helpid = HttpServerNode.class.getName()+"_properties"; //NOI18N
175
return new HelpCtx(helpid);
176     }
177
178     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
179         if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName()) && evt.getNewValue() == PropertyEnv.STATE_VALID) {
180             editor.setValue(getPropertyValue());
181         }
182     }
183 }
184
Popular Tags