KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.*;
23 import javax.swing.*;
24 import javax.swing.event.ListSelectionEvent JavaDoc;
25 import javax.swing.event.ListSelectionListener JavaDoc;
26 import org.openide.explorer.propertysheet.ExPropertyEditor;
27 import org.openide.explorer.propertysheet.PropertyEnv;
28
29 import org.openide.util.NbBundle;
30
31 /** Property editor for host property of HttpServerSettings class
32 *
33 * @author Ales Novak, Petr Jiricka
34 */

35 public class HostPropertyEditor extends PropertyEditorSupport implements ExPropertyEditor {
36
37     private PropertyEnv env;
38
39     /** localized local (selected) host string*/
40     private static String JavaDoc localhost() {
41         return NbBundle.getMessage(HostPropertyEditor.class, "CTL_Local_host");
42     }
43
44     /** localized any host string*/
45     private static String JavaDoc anyhost() {
46         return NbBundle.getMessage(HostPropertyEditor.class, "CTL_Any_host");
47     }
48
49     /** @return text for the current value */
50     public String JavaDoc getAsText () {
51         HttpServerSettings.HostProperty hp = (HttpServerSettings.HostProperty) getValue();
52         if (hp == null) {
53             return "";
54         }
55         String JavaDoc host = hp.getHost();
56         if (host.equals(HttpServerSettings.LOCALHOST)) {
57             return localhost () + hp.getGrantedAddresses ();
58         }
59         else {
60             return anyhost ();
61         }
62     }
63
64     /** @param text A text for the current value. */
65     public void setAsText (String JavaDoc text) {
66         if (anyhost ().equals (text)) {
67             setValue (new HttpServerSettings.HostProperty ("", HttpServerSettings.ANYHOST)); // NOI18N
68
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 JavaDoc (text);
77     }
78
79     public boolean supportsCustomEditor () {
80         return true;
81     }
82
83     public java.awt.Component JavaDoc 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