1 19 20 package org.netbeans.modules.httpserver; 21 22 import java.beans.*; 23 import javax.swing.*; 24 import javax.swing.event.ListSelectionEvent ; 25 import javax.swing.event.ListSelectionListener ; 26 import org.openide.explorer.propertysheet.ExPropertyEditor; 27 import org.openide.explorer.propertysheet.PropertyEnv; 28 29 import org.openide.util.NbBundle; 30 31 35 public class HostPropertyEditor extends PropertyEditorSupport implements ExPropertyEditor { 36 37 private PropertyEnv env; 38 39 40 private static String localhost() { 41 return NbBundle.getMessage(HostPropertyEditor.class, "CTL_Local_host"); 42 } 43 44 45 private static String anyhost() { 46 return NbBundle.getMessage(HostPropertyEditor.class, "CTL_Any_host"); 47 } 48 49 50 public String getAsText () { 51 HttpServerSettings.HostProperty hp = (HttpServerSettings.HostProperty) getValue(); 52 if (hp == null) { 53 return ""; 54 } 55 String host = hp.getHost(); 56 if (host.equals(HttpServerSettings.LOCALHOST)) { 57 return localhost () + hp.getGrantedAddresses (); 58 } 59 else { 60 return anyhost (); 61 } 62 } 63 64 65 public void setAsText (String text) { 66 if (anyhost ().equals (text)) { 67 setValue (new HttpServerSettings.HostProperty ("", HttpServerSettings.ANYHOST)); return; 69 } else if (text != null && text.startsWith(localhost())) { 70 setValue (new HttpServerSettings.HostProperty (text.substring (localhost ().length ()), HttpServerSettings.LOCALHOST)); 71 return; 72 } else if (text != null) { 73 setValue (new HttpServerSettings.HostProperty (text, HttpServerSettings.LOCALHOST)); 74 return; 75 } 76 throw new IllegalArgumentException (text); 77 } 78 79 public boolean supportsCustomEditor () { 80 return true; 81 } 82 83 public java.awt.Component getCustomEditor () { 84 return new HostPropertyCustomEditor (this, env); 85 } 86 87 public void attachEnv(PropertyEnv env) { 88 this.env = env; 89 } 90 91 } 92 | Popular Tags |