001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.event;
017:
018: import org.geotools.event.GTComponent;
019: import org.geotools.event.GTDelta;
020:
021: /**
022: * Provides basic StyleEvent notification, may be used in conjuction with
023: * StyleList during event handling.
024: *
025: * <p>
026: * This class has package scope to prevent user code mistaking it for something
027: * important. It is only used to assist in the construction of this one
028: * implementation of StyleEvents. Basically this is NOT API :-)
029: * </p>
030: *
031: * @since 2.2.M3
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/event/AbstractGTComponent.java $
033: */
034: public abstract class AbstractGTComponent implements GTComponent {
035: // GTComponent notificationParent = GTRoot.NO_PARENT;
036: // protected String notificationName = "";
037: // protected int notificationPosition = GTDelta.NO_INDEX;
038: protected GTNote notification = new GTNoteImpl(GTRoot.NO_PARENT,
039: "", GTDelta.NO_INDEX);
040:
041: protected Object clone() throws CloneNotSupportedException {
042: AbstractGTComponent copy = (AbstractGTComponent) super .clone();
043:
044: // copy.notificationParent = GTRoot.NO_PARENT;
045: // copy.notificationName = "";
046: // copy.notificationPosition = GTDelta.NO_INDEX;
047: copy.notification = new GTNoteImpl(GTRoot.NO_PARENT, "",
048: GTDelta.NO_INDEX);
049:
050: return copy;
051: }
052:
053: /**
054: * Provide notification based on the provided delta.
055: *
056: * <p>
057: * Delta must come from this StyleComponent.
058: * </p>
059: *
060: * @param childDelta object containing change information protected void
061: * fire(GTDelta delta){ parent.changed(delta); }
062: */
063: /**
064: * Used to pass on "something is about to change" notification from
065: * children.
066: *
067: * @param childDelta object containing change information
068: */
069: public void removed(GTDelta childDelta) {
070: GTDelta delta = new GTDeltaImpl(notification,
071: GTDelta.Kind.NO_CHANGE, this , null, childDelta);
072: notification.getParent().removed(delta);
073: }
074:
075: /**
076: * Used to pass on "We changed" notification from children.
077: *
078: * @param childDelta object containing change information
079: */
080: public void changed(GTDelta childDelta) {
081: GTDelta delta = new GTDeltaImpl(notification,
082: GTDelta.Kind.NO_CHANGE, this , null, childDelta);
083: notification.getParent().changed(delta);
084: }
085:
086: /**
087: * Simple notification that we changed.
088: *
089: * <p>
090: * Change will be passed on to parent.changed( delta ).
091: * </p>
092: */
093: protected void fireChanged() {
094: GTDelta delta = new GTDeltaImpl(notification,
095: GTDelta.Kind.CHANGED, this , null);
096: notification.getParent().changed(delta);
097: }
098:
099: /**
100: * Create a child delta and send it off.
101: *
102: * <p>
103: * Use this for changes to simple types like int and Color.
104: * </p>
105: *
106: * @param name the String used to name the child (often bean propertyName or map key)
107: * @param child
108: * @param oldValue
109: */
110: protected synchronized void fireChildChanged(String name,
111: Object child, Object oldValue) {
112: GTNote here = new GTNoteImpl(this , name, GTDelta.NO_INDEX);
113:
114: if (oldValue instanceof GTComponent) {
115: GTNote note = new GTNoteImpl(GTRoot.NO_PARENT, "",
116: GTDelta.NO_INDEX);
117:
118: GTComponent myDeath = (GTComponent) oldValue;
119: myDeath.setNote(note);
120: }
121:
122: if (child instanceof GTComponent) {
123: GTComponent myChild = (GTComponent) child;
124: myChild.setNote(here);
125: }
126:
127: if (child == null) {
128: fireChanged(); // well something changed
129: } else {
130: GTDelta delta;
131: delta = new GTDeltaImpl(here, GTDelta.Kind.CHANGED, child,
132: oldValue); // <-- child delta
133: changed(delta);
134: }
135: }
136:
137: public GTComponent getParent() {
138: return notification.getParent();
139: }
140:
141: // public void setParent(GTComponent newParent) {
142: // if( newParent == null ) {
143: // newParent = GTRoot.NO_PARENT;
144: // }
145: // if( notificationParent != GTRoot.NO_PARENT ){
146: // // TODO: Freek out if Construct is adopted by a new parent
147: // // Previous parents need to disown children beforehand
148: // throw new IllegalStateException("Please remove from existing parent first");
149: // }
150: // notificationParent = newParent;
151: // }
152: //
153: // public void setNotificationName(String name) {
154: // if( name == null ) name = "";
155: // notificationName = name;
156: // }
157: //
158: // public String getNotificationName() {
159: // return notificationName;
160: // }
161: //
162: // public void setNotificationPosition(int index) {
163: // notificationPosition = index;
164: // }
165: //
166: // public int getNotificationPosition() {
167: // return notificationPosition;
168: // }
169: public GTNote getNote() {
170: return notification;
171: }
172:
173: public void setNote(GTNote container) {
174: notification = container;
175: }
176: }
|