001: /*
002: * TokenizerPropertyEvent.java: tokenizer property change event.
003: *
004: * Copyright (C) 2002 Heiko Blau
005: *
006: * This file belongs to the JTopas Library.
007: * JTopas is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as published by the
009: * Free Software Foundation; either version 2.1 of the License, or (at your
010: * option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE.
015: * See the GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License along
018: * with JTopas. If not, write to the
019: *
020: * Free Software Foundation, Inc.
021: * 59 Temple Place, Suite 330,
022: * Boston, MA 02111-1307
023: * USA
024: *
025: * or check the Internet: http://www.fsf.org
026: *
027: * Contact:
028: * email: heiko@susebox.de
029: */
030:
031: package de.susebox.jtopas;
032:
033: //-----------------------------------------------------------------------------
034: // Imports
035: //
036:
037: //-----------------------------------------------------------------------------
038: // class TokenizerPropertyEvent
039: //
040:
041: /**<p>
042: * The class <code>TokenizerPropertyEvent</code> describes changes in
043: * {@link TokenizerProperties} objects. Instances of this class are produced by
044: * <code>TokenizerProperties</code> and passed to {@link TokenizerPropertyListener}
045: * objects that are registered with the issuing <code>TokenizerProperties</code>
046: * instance.
047: *</p>
048: *
049: * @see TokenizerProperties
050: * @see TokenizerPropertyListener
051: * @author Heiko Blau
052: */
053: public class TokenizerPropertyEvent {
054:
055: //---------------------------------------------------------------------------
056: // constants
057: //
058:
059: /**
060: * A property has been added.
061: */
062: public static final byte PROPERTY_ADDED = 1;
063:
064: /**
065: * A property has been removed.
066: */
067: public static final byte PROPERTY_REMOVED = 2;
068:
069: /**
070: * A property has been modified.
071: */
072: public static final byte PROPERTY_MODIFIED = 3;
073:
074: //---------------------------------------------------------------------------
075: // constructors
076: //
077:
078: /**
079: * The standard constructor initializes an emtpy event.
080: */
081: public TokenizerPropertyEvent() {
082: this (0, null);
083: }
084:
085: /**
086: * This constructor takes the type of the event and the {@link TokenizerProperty}
087: * that changed.
088: *
089: * @param type type of the event, one of the <code>PROPERTY_...</code> constants
090: * @param property the property that was added, removed or the new value of a modified one
091: */
092: public TokenizerPropertyEvent(int type, TokenizerProperty property) {
093: setType(type);
094: setProperty(property);
095: setOldProperty(null);
096: }
097:
098: /**
099: * This constructor takes the type of the event and the {@link TokenizerProperty}
100: * that changed together with its old value.
101: *
102: * @param type type of the event, one of the <code>PROPERTY_...</code> constants
103: * @param property the property that was added, removed or the new value of a modified one
104: * @param oldProperty the old value of the property that modified
105: */
106: public TokenizerPropertyEvent(int type, TokenizerProperty property,
107: TokenizerProperty oldProperty) {
108: setType(type);
109: setProperty(property);
110: setOldProperty(null);
111: }
112:
113: //---------------------------------------------------------------------------
114: // getter and setter methods
115: //
116:
117: /**
118: * Setting the event type. Use one of the <code>PROPERTY_...</code> constants
119: * for the parameter.
120: *
121: * @param type the event type
122: * @see #getType
123: * @see #PROPERTY_ADDED
124: * @see #PROPERTY_REMOVED
125: * @see #PROPERTY_MODIFIED
126: */
127: public void setType(int type) {
128: _type = type;
129: }
130:
131: /**
132: * Retrieving the event type. This will usually be one of the <code>PROPERTY_...</code>
133: * constants.
134: *
135: * @return the type of the event
136: */
137: public int getType() {
138: return _type;
139: }
140:
141: /**
142: * Setting the {@link TokenizerProperty} the event is about.
143: *
144: * @param property the added, removed or modified {@link TokenizerProperty}
145: */
146: public void setProperty(TokenizerProperty property) {
147: _property = property;
148: }
149:
150: /**
151: * Retrieving the property this event is reporting.
152: *
153: * @return the {@link TokenizerProperty} that is added, removed or modified
154: */
155: public TokenizerProperty getProperty() {
156: return _property;
157: }
158:
159: /**
160: * Setting the {@link TokenizerProperty} that was changed. This is a valid
161: * method for the event {@link #PROPERTY_MODIFIED}.
162: *
163: * @param property the previously set {@link TokenizerProperty}
164: */
165: public void setOldProperty(TokenizerProperty property) {
166: _oldProperty = property;
167: }
168:
169: /**
170: * Retrieving the property that was set before the modification. The method
171: * returns <code>null</code> when the event is <strong>NOT</strong> {@link #PROPERTY_MODIFIED}.
172: *
173: * @return the {@link TokenizerProperty} set before the modification
174: */
175: public TokenizerProperty getOldProperty() {
176: return _oldProperty;
177: }
178:
179: //---------------------------------------------------------------------------
180: // overloaded methods
181: //
182:
183: /**
184: * Redefinition of the well-known {@link java.lang.Object#equals} method.
185: *
186: * @param that compare this instance with that object
187: * @return <code>true</code> if the two object describe the same property,
188: * <code>false</code> otherwise
189: */
190: public boolean equals(Object that) {
191: // primitive tests
192: if (that == null) {
193: return false;
194: } else if (that == this ) {
195: return true;
196: } else if (!(that instanceof TokenizerPropertyEvent)) {
197: return false;
198: }
199:
200: // compare contents
201: TokenizerPropertyEvent thatEvent = (TokenizerPropertyEvent) that;
202: TokenizerProperty thatProp = thatEvent.getProperty();
203: TokenizerProperty thatOldProp = thatEvent.getOldProperty();
204:
205: if (getType() == thatEvent.getType()
206: && (_property == thatProp || (_property != null && _property
207: .equals(thatProp)))
208: && (_oldProperty == thatOldProp || (_oldProperty != null && _oldProperty
209: .equals(thatOldProp)))) {
210: return true;
211: } else {
212: return false;
213: }
214: }
215:
216: /**
217: * Redefinition of the well-known {@link java.lang.Object#toString} method.
218: *
219: * @return a string representation of this <code>TokenizerProperty</code>
220: */
221: public String toString() {
222: StringBuffer buffer = new StringBuffer();
223:
224: buffer.append(getClass().getName());
225: buffer.append(": ");
226:
227: switch (_type) {
228: case PROPERTY_ADDED:
229: buffer.append("added ");
230: break;
231: case PROPERTY_REMOVED:
232: buffer.append("removed ");
233: break;
234: case PROPERTY_MODIFIED:
235: buffer.append("modified ");
236: break;
237: default:
238: buffer.append("<unknown type> ");
239: }
240:
241: if (getProperty() != null) {
242: buffer.append(getProperty().toString());
243: } else {
244: buffer.append("<no property>");
245: }
246: return buffer.toString();
247: }
248:
249: //---------------------------------------------------------------------------
250: // members
251: //
252: private int _type = 0;
253: private TokenizerProperty _property = null;
254: private TokenizerProperty _oldProperty = null;
255: }
|