1 19 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import javax.swing.JPanel ; 25 import javax.swing.SpinnerNumberModel ; 26 import javax.swing.SwingUtilities ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 31 import org.openide.util.NbBundle; 32 import org.openide.util.RequestProcessor; 33 34 public final class AddInstanceVisualHostPortPanel extends JPanel { 35 36 private SpinnerNumberModel valueModel = 37 new SpinnerNumberModel (4848,1,65535,1); 38 41 public AddInstanceVisualHostPortPanel() { 42 initComponents(); 43 portValue.setModel(valueModel); 44 portValue.addChangeListener(new ChangeListener () { 45 public void stateChanged(ChangeEvent ev) { 46 fireChangeEvent(); 47 } 48 }); 49 hostName.getDocument().addDocumentListener(new DocumentListener () { 50 public void insertUpdate(DocumentEvent e) { 51 fireChangeEvent(); 52 } 53 54 public void removeUpdate(DocumentEvent e) { 55 fireChangeEvent(); 56 } 57 58 public void changedUpdate(DocumentEvent e) { 59 fireChangeEvent(); 60 } 61 62 }); 63 } 64 65 public String getName() { 66 return NbBundle.getMessage(AddInstanceVisualHostPortPanel.class, 67 "StepName_PickHostAndPort"); } 69 70 String getHost() { 71 return hostName.getText().trim(); 72 } 73 74 int getPort() { 75 return valueModel.getNumber().intValue(); 76 } 77 78 private Set listenrs = new HashSet (); 81 82 void addChangeListener(ChangeListener l) { 83 synchronized (listenrs) { 84 listenrs.add(l); 85 } 86 } 87 88 void removeChangeListener(ChangeListener l ) { 89 synchronized (listenrs) { 90 listenrs.remove(l); 91 } 92 } 93 94 RequestProcessor.Task changeEvent = null; 95 96 private void fireChangeEvent() { 97 if (changeEvent == null) { 100 changeEvent = RequestProcessor.getDefault().post(new Runnable () { 101 public void run() { 102 SwingUtilities.invokeLater(new Runnable () { 103 public void run() { 104 Iterator it; 105 synchronized (listenrs) { 106 it = new HashSet (listenrs).iterator(); 107 } 108 ChangeEvent ev = new ChangeEvent (this); 109 while (it.hasNext()) { 110 ((ChangeListener )it.next()).stateChanged(ev); 111 } 112 } 113 }); 114 115 } 116 }, 100); 117 } else { 118 changeEvent.schedule(100); 119 } 120 } 121 122 123 128 private void initComponents() { 130 java.awt.GridBagConstraints gridBagConstraints; 131 132 description = new javax.swing.JLabel (); 133 hostNameLabel = new javax.swing.JLabel (); 134 hostName = new javax.swing.JTextField (); 135 portValueLabel = new javax.swing.JLabel (); 136 portValue = new javax.swing.JSpinner (); 137 spacingHack = new javax.swing.JLabel (); 138 139 setFocusable(false); 140 setLayout(new java.awt.GridBagLayout ()); 141 142 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/j2ee/ui/Bundle"); description.setText(bundle.getString("TXT_hostPortDescription")); description.setFocusable(false); 145 gridBagConstraints = new java.awt.GridBagConstraints (); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridy = 1; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 159 gridBagConstraints.insets = new java.awt.Insets (6, 0, 5, 6); 160 add(hostNameLabel, gridBagConstraints); 161 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (6, 6, 5, 0); 166 add(hostName, gridBagConstraints); 167 hostName.getAccessibleContext().setAccessibleDescription(bundle.getString("DSC_hostName")); 169 portValueLabel.setLabelFor(portValue); 170 org.openide.awt.Mnemonics.setLocalizedText(portValueLabel, org.openide.util.NbBundle.getMessage(AddInstanceVisualHostPortPanel.class, "LBL_portValueLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 172 gridBagConstraints.gridy = 2; 173 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 174 gridBagConstraints.insets = new java.awt.Insets (6, 0, 5, 6); 175 add(portValueLabel, gridBagConstraints); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridy = 2; 178 gridBagConstraints.gridwidth = 2; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 181 add(portValue, gridBagConstraints); 182 183 spacingHack.setEnabled(false); 184 spacingHack.setFocusable(false); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridx = 0; 187 gridBagConstraints.gridy = 4; 188 gridBagConstraints.weighty = 1.0; 189 add(spacingHack, gridBagConstraints); 190 } 192 193 private javax.swing.JLabel description; 195 private javax.swing.JTextField hostName; 196 private javax.swing.JLabel hostNameLabel; 197 private javax.swing.JSpinner portValue; 198 private javax.swing.JLabel portValueLabel; 199 private javax.swing.JLabel spacingHack; 200 202 } 203 204 | Popular Tags |