1 19 20 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui; 21 22 import java.awt.Component ; 23 import java.net.InetAddress ; 24 import java.net.InetSocketAddress ; 25 import java.net.UnknownHostException ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import javax.swing.event.ChangeEvent ; 30 import javax.swing.event.ChangeListener ; 31 import org.openide.WizardDescriptor; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 35 39 class AddDomainHostPortPanel implements WizardDescriptor.FinishablePanel, 40 ChangeListener { 41 42 46 private AddInstanceVisualHostPortPanel component; 47 private WizardDescriptor wiz; 48 49 public Component getComponent() { 54 if (component == null) { 55 component = new AddInstanceVisualHostPortPanel(); 56 component.addChangeListener(this); 57 58 } 59 return component; 60 } 61 62 public HelpCtx getHelp() { 63 return new HelpCtx("AS_RegServ_EnterRemoteInfo"); } 65 66 73 public boolean isValid() { 74 String h = component.getHost(); 75 if (h.length() < 1) { 76 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 77 NbBundle.getMessage(AddDomainHostPortPanel.class, 78 "MSG_EnterHost",h)); return false; 80 } 81 if (h.indexOf("://") > -1) { 82 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 84 NbBundle.getMessage(AddDomainHostPortPanel.class, 85 "MSG_exclude_protocol",h)); return false; 87 } 88 int p = component.getPort(); 89 try { 90 InetAddress ia = InetAddress.getByName(h); 91 new InetSocketAddress (ia,p); 92 } catch (UnknownHostException uhe) { 93 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 94 NbBundle.getMessage(AddDomainHostPortPanel.class, 95 "MSG_UnknownHost2",h)); return false; 97 } catch (IllegalArgumentException iae) { 98 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 99 NbBundle.getMessage(AddDomainHostPortPanel.class, 100 "Msg_ValidPortNumber")); return false; 102 } 103 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,null); 105 wiz.putProperty(AddDomainWizardIterator.HOST,h); 106 wiz.putProperty(AddDomainWizardIterator.PORT,p+""); 107 return true; 108 } 109 110 private final Set listeners = new HashSet (1); 113 public final void addChangeListener(ChangeListener l) { 114 synchronized (listeners) { 115 listeners.add(l); 116 } 117 } 118 public final void removeChangeListener(ChangeListener l) { 119 synchronized (listeners) { 120 listeners.remove(l); 121 } 122 } 123 protected final void fireChangeEvent() { 124 Iterator it; 125 synchronized (listeners) { 126 it = new HashSet (listeners).iterator(); 127 } 128 ChangeEvent ev = new ChangeEvent (this); 129 while (it.hasNext()) { 130 ((ChangeListener )it.next()).stateChanged(ev); 131 } 132 } 133 134 public void readSettings(Object settings) { 139 wiz = (WizardDescriptor) settings; 140 } 141 public void storeSettings(Object settings) { 142 } 144 145 public void stateChanged(ChangeEvent e) { 146 fireChangeEvent(); 147 } 148 149 151 public boolean isFinishPanel() { 152 return true; 153 } 154 } 155 | Popular Tags |