KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > ui > AddInstanceVisualHostPortPanel


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 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui;
20
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.SpinnerNumberModel JavaDoc;
26 import javax.swing.SwingUtilities JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import javax.swing.event.DocumentEvent JavaDoc;
30 import javax.swing.event.DocumentListener JavaDoc;
31 import org.openide.util.NbBundle;
32 import org.openide.util.RequestProcessor;
33
34 public final class AddInstanceVisualHostPortPanel extends JPanel JavaDoc {
35
36     private SpinnerNumberModel JavaDoc valueModel =
37             new SpinnerNumberModel JavaDoc(4848,1,65535,1);
38     /**
39      * Creates new form AddInstanceVisualHostPortPanel
40      */

41     public AddInstanceVisualHostPortPanel() {
42         initComponents();
43         portValue.setModel(valueModel);
44         portValue.addChangeListener(new ChangeListener JavaDoc() {
45             public void stateChanged(ChangeEvent JavaDoc ev) {
46                 fireChangeEvent();
47             }
48         });
49         hostName.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
50             public void insertUpdate(DocumentEvent JavaDoc e) {
51                 fireChangeEvent();
52             }
53
54             public void removeUpdate(DocumentEvent JavaDoc e) {
55                 fireChangeEvent();
56             }
57
58             public void changedUpdate(DocumentEvent JavaDoc e) {
59                 fireChangeEvent();
60             }
61             
62         });
63     }
64
65     public String JavaDoc getName() {
66         return NbBundle.getMessage(AddInstanceVisualHostPortPanel.class,
67                 "StepName_PickHostAndPort"); // NOI18N
68
}
69     
70     String JavaDoc getHost() {
71         return hostName.getText().trim();
72     }
73     
74     int getPort() {
75         return valueModel.getNumber().intValue();
76     }
77     
78     // Event Handling
79
//
80
private Set JavaDoc/*<ChangeListener.*/ listenrs = new HashSet JavaDoc/*<Changelisteners.*/();
81
82     void addChangeListener(ChangeListener JavaDoc l) {
83         synchronized (listenrs) {
84             listenrs.add(l);
85         }
86     }
87     
88     void removeChangeListener(ChangeListener JavaDoc l ) {
89         synchronized (listenrs) {
90             listenrs.remove(l);
91         }
92     }
93
94     RequestProcessor.Task changeEvent = null;
95     
96     private void fireChangeEvent() {
97         // don't go so fast here, since this can get called a lot from the
98
// document listener
99
if (changeEvent == null) {
100             changeEvent = RequestProcessor.getDefault().post(new Runnable JavaDoc() {
101                 public void run() {
102                     SwingUtilities.invokeLater(new Runnable JavaDoc() {
103                         public void run() {
104                             Iterator JavaDoc it;
105                             synchronized (listenrs) {
106                                 it = new HashSet JavaDoc(listenrs).iterator();
107                             }
108                             ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
109                             while (it.hasNext()) {
110                                 ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
111                             }
112                         }
113                     });
114                     
115                 }
116             }, 100);
117         } else {
118             changeEvent.schedule(100);
119         }
120     }
121     
122     
123     /** This method is called from within the constructor to
124      * initialize the form.
125      * WARNING: Do NOT modify this code. The content of this method is
126      * always regenerated by the Form Editor.
127      */

128     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
129
private void initComponents() {
130         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
131
132         description = new javax.swing.JLabel JavaDoc();
133         hostNameLabel = new javax.swing.JLabel JavaDoc();
134         hostName = new javax.swing.JTextField JavaDoc();
135         portValueLabel = new javax.swing.JLabel JavaDoc();
136         portValue = new javax.swing.JSpinner JavaDoc();
137         spacingHack = new javax.swing.JLabel JavaDoc();
138
139         setFocusable(false);
140         setLayout(new java.awt.GridBagLayout JavaDoc());
141
142         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/j2ee/ui/Bundle"); // NOI18N
143
description.setText(bundle.getString("TXT_hostPortDescription")); // NOI18N
144
description.setFocusable(false);
145         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
146         gridBagConstraints.gridx = 0;
147         gridBagConstraints.gridy = 0;
148         gridBagConstraints.gridwidth = 4;
149         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
151         gridBagConstraints.weightx = 1.0;
152         add(description, gridBagConstraints);
153
154         hostNameLabel.setLabelFor(hostName);
155         org.openide.awt.Mnemonics.setLocalizedText(hostNameLabel, org.openide.util.NbBundle.getMessage(AddInstanceVisualHostPortPanel.class, "LBL_hostNameLabel")); // NOI18N
156
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridy = 1;
158         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 5, 6);
160         add(hostNameLabel, gridBagConstraints);
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridy = 1;
163         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
166         add(hostName, gridBagConstraints);
167         hostName.getAccessibleContext().setAccessibleDescription(bundle.getString("DSC_hostName")); // NOI18N
168

169         portValueLabel.setLabelFor(portValue);
170         org.openide.awt.Mnemonics.setLocalizedText(portValueLabel, org.openide.util.NbBundle.getMessage(AddInstanceVisualHostPortPanel.class, "LBL_portValueLabel")); // NOI18N
171
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
172         gridBagConstraints.gridy = 2;
173         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 5, 6);
175         add(portValueLabel, gridBagConstraints);
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridy = 2;
178         gridBagConstraints.gridwidth = 2;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
181         add(portValue, gridBagConstraints);
182
183         spacingHack.setEnabled(false);
184         spacingHack.setFocusable(false);
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridx = 0;
187         gridBagConstraints.gridy = 4;
188         gridBagConstraints.weighty = 1.0;
189         add(spacingHack, gridBagConstraints);
190     }// </editor-fold>//GEN-END:initComponents
191

192
193     // Variables declaration - do not modify//GEN-BEGIN:variables
194
private javax.swing.JLabel JavaDoc description;
195     private javax.swing.JTextField JavaDoc hostName;
196     private javax.swing.JLabel JavaDoc hostNameLabel;
197     private javax.swing.JSpinner JavaDoc portValue;
198     private javax.swing.JLabel JavaDoc portValueLabel;
199     private javax.swing.JLabel JavaDoc spacingHack;
200     // End of variables declaration//GEN-END:variables
201

202 }
203
204
Popular Tags