KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > settings > examples > ProxySettings


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.settings.examples;
21
22 import java.util.Properties JavaDoc;
23
24 /**
25  *
26  * @author Jan Pokorsky
27  */

28 public final class ProxySettings {
29     private final static String JavaDoc PROP_PROXYHOST = "proxyHost"; //NOI18N
30
private final static String JavaDoc PROP_PROXYPORT = "proxyPort"; //NOI18N
31

32     /** Holds value of property proxyHost. */
33     private String JavaDoc proxyHost;
34
35     /** Utility field used by bound properties. */
36     private java.beans.PropertyChangeSupport JavaDoc propertyChangeSupport = new java.beans.PropertyChangeSupport JavaDoc(this);
37
38     /** Holds value of property proxyPort. */
39     private int proxyPort;
40     
41     /** Creates a new instance of ProxySettings */
42     public ProxySettings() {
43     }
44     
45     /** Adds a PropertyChangeListener to the listener list.
46      * @param l The listener to add.
47      */

48     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
49         propertyChangeSupport.addPropertyChangeListener(l);
50     }
51     
52     /** Removes a PropertyChangeListener from the listener list.
53      * @param l The listener to remove.
54      */

55     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
56         propertyChangeSupport.removePropertyChangeListener(l);
57     }
58     
59     /** Getter for property proxyHost.
60      * @return Value of property proxyHost.
61      */

62     public String JavaDoc getProxyHost() {
63         return (proxyHost == null)? "default": proxyHost;
64     }
65     
66     /** Setter for property proxyHost.
67      * @param proxyHost New value of property proxyHost.
68      */

69     public void setProxyHost(String JavaDoc proxyHost) {
70         String JavaDoc oldProxyHost = this.proxyHost;
71         this.proxyHost = proxyHost;
72         propertyChangeSupport.firePropertyChange(PROP_PROXYHOST, oldProxyHost, proxyHost); //NOI18N
73
}
74     
75     /** Getter for property proxyPort.
76      * @return Value of property proxyPort.
77      */

78     public int getProxyPort() {
79         return this.proxyPort;
80     }
81     
82     /** Setter for property proxyPort.
83      * @param proxyPort New value of property proxyPort.
84      */

85     public void setProxyPort(int proxyPort) {
86         int oldProxyPort = this.proxyPort;
87         this.proxyPort = proxyPort;
88         propertyChangeSupport.firePropertyChange(PROP_PROXYPORT, new Integer JavaDoc(oldProxyPort), new Integer JavaDoc(proxyPort));
89     }
90     
91     private void readProperties(Properties JavaDoc p) {
92         this.proxyHost = p.getProperty(PROP_PROXYHOST); //NOI18N
93
try {
94             this.proxyPort = Integer.parseInt(p.getProperty(PROP_PROXYPORT));
95         } catch (NumberFormatException JavaDoc ex) {
96             this.proxyPort = 0;
97         }
98     }
99     
100     private void writeProperties(Properties JavaDoc p) {
101         p.setProperty(PROP_PROXYHOST, proxyHost);
102         p.setProperty(PROP_PROXYPORT, String.valueOf(proxyPort));
103     }
104 }
105
Popular Tags