01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.propertysheet;
18:
19: import java.beans.PropertyChangeListener;
20: import java.beans.PropertyChangeSupport;
21: import java.io.IOException;
22:
23: /**
24: * AbstractProperty. <br>
25: *
26: */
27: public abstract class AbstractProperty implements Property {
28:
29: private Object value;
30:
31: // PropertyChangeListeners are not serialized.
32: private transient PropertyChangeSupport listeners = new PropertyChangeSupport(
33: this );
34:
35: public Object getValue() {
36: return value;
37: }
38:
39: public Object clone() {
40: AbstractProperty clone = null;
41: try {
42: clone = (AbstractProperty) super .clone();
43: return clone;
44: } catch (CloneNotSupportedException e) {
45: throw new RuntimeException(e);
46: }
47: }
48:
49: public void setValue(Object value) {
50: Object oldValue = this .value;
51: this .value = value;
52: if (value != oldValue
53: && (value == null || !value.equals(oldValue)))
54: firePropertyChange(oldValue, getValue());
55: }
56:
57: protected void initializeValue(Object value) {
58: this .value = value;
59: }
60:
61: public void addPropertyChangeListener(
62: PropertyChangeListener listener) {
63: listeners.addPropertyChangeListener(listener);
64: Property[] subProperties = getSubProperties();
65: if (subProperties != null)
66: for (int i = 0; i < subProperties.length; ++i)
67: subProperties[i].addPropertyChangeListener(listener);
68: }
69:
70: public void removePropertyChangeListener(
71: PropertyChangeListener listener) {
72: listeners.removePropertyChangeListener(listener);
73: Property[] subProperties = getSubProperties();
74: if (subProperties != null)
75: for (int i = 0; i < subProperties.length; ++i)
76: subProperties[i].removePropertyChangeListener(listener);
77: }
78:
79: protected void firePropertyChange(Object oldValue, Object newValue) {
80: listeners.firePropertyChange("value", oldValue, newValue);
81: }
82:
83: private void readObject(java.io.ObjectInputStream in)
84: throws IOException, ClassNotFoundException {
85: in.defaultReadObject();
86: listeners = new PropertyChangeSupport(this );
87: }
88:
89: public Property getParentProperty() {
90: return null;
91: }
92:
93: public Property[] getSubProperties() {
94: return null;
95: }
96: }
|