KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > settings > convertors > FooSetting


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 2002 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.settings.convertors;
21
22 import java.util.Properties JavaDoc;
23
24 /**
25  *
26  * @author Jan Pokorsky
27  */

28 public class FooSetting {
29     private final static String JavaDoc PROP_PROPERTY1 = "property1";
30     private final static String JavaDoc PROP_NAME = "name";
31
32     /** Holds value of property property1. */
33     private String JavaDoc property1;
34
35     /** Holds value of property name. */
36     private String JavaDoc name = "defaultName";
37
38     /** Utility field used by bound properties. */
39     private java.beans.PropertyChangeSupport JavaDoc propertyChangeSupport = new java.beans.PropertyChangeSupport JavaDoc(this);
40
41     private int listenerCount = 0;
42     
43     /** Creates a new instance of FooSetting */
44     public FooSetting() {
45     }
46     public FooSetting(String JavaDoc txt) {
47         this.property1 = txt;
48     }
49     
50     /** Adds a PropertyChangeListener to the listener list.
51      * @param l The listener to add.
52      */

53     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
54         propertyChangeSupport.addPropertyChangeListener(l);
55         listenerCount++;
56     }
57     
58     /** Removes a PropertyChangeListener from the listener list.
59      * @param l The listener to remove.
60      */

61     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
62         propertyChangeSupport.removePropertyChangeListener(l);
63         listenerCount--;
64     }
65     
66     int getListenerCount() {
67         return listenerCount;
68     }
69
70     /** Getter for property property1.
71      * @return Value of property property1.
72      */

73     public String JavaDoc getProperty1() {
74         return this.property1;
75     }
76     
77     /** Setter for property property1.
78      * @param property1 New value of property property1.
79      */

80     public void setProperty1(String JavaDoc property1) {
81         String JavaDoc oldProperty1 = this.property1;
82         this.property1 = property1;
83         propertyChangeSupport.firePropertyChange(PROP_PROPERTY1, oldProperty1, property1);
84     }
85     
86     /** Getter for property name.
87      * @return Value of property name.
88      */

89     public String JavaDoc getName() {
90         return this.name;
91     }
92     
93     /** Setter for property name.
94      * @param name New value of property name.
95      */

96     public void setName(String JavaDoc name) {
97         String JavaDoc oldName = this.name;
98         this.name = name;
99         propertyChangeSupport.firePropertyChange(PROP_NAME, oldName, name);
100     }
101     
102     private void readProperties(Properties JavaDoc p) {
103         property1 = p.getProperty(PROP_PROPERTY1);
104         String JavaDoc _name = p.getProperty(PROP_NAME);
105         if (_name != null) name = _name;
106     }
107     
108     private void writeProperties(Properties JavaDoc p) {
109         if (property1 != null) {
110             p.setProperty(PROP_PROPERTY1, property1);
111         }
112         if (name != null) {
113             p.setProperty(PROP_NAME, name);
114         }
115     }
116     
117     public String JavaDoc toString() {
118         return this.getClass().getName() + '@' +
119             Integer.toHexString(System.identityHashCode(this)) +
120             '[' + property1 + ", " + name + ']';
121     }
122     
123     public boolean equals(Object JavaDoc obj) {
124         if (obj == null || !(obj instanceof FooSetting)) return false;
125         FooSetting foo = (FooSetting) obj;
126         if (property1 == null || foo.property1 == null) {
127             return property1 == foo.property1;
128         }
129         return property1.equals(foo.property1);
130     }
131     
132 }
133
Popular Tags