KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > susebox > jtopas > TokenizerPropertyEvent


1 /*
2  * TokenizerPropertyEvent.java: tokenizer property change event.
3  *
4  * Copyright (C) 2002 Heiko Blau
5  *
6  * This file belongs to the JTopas Library.
7  * JTopas is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License along
18  * with JTopas. If not, write to the
19  *
20  * Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330,
22  * Boston, MA 02111-1307
23  * USA
24  *
25  * or check the Internet: http://www.fsf.org
26  *
27  * Contact:
28  * email: heiko@susebox.de
29  */

30
31 package de.susebox.jtopas;
32
33 //-----------------------------------------------------------------------------
34
// Imports
35
//
36

37
38 //-----------------------------------------------------------------------------
39
// class TokenizerPropertyEvent
40
//
41

42 /**<p>
43  * The class <code>TokenizerPropertyEvent</code> describes changes in
44  * {@link TokenizerProperties} objects. Instances of this class are produced by
45  * <code>TokenizerProperties</code> and passed to {@link TokenizerPropertyListener}
46  * objects that are registered with the issuing <code>TokenizerProperties</code>
47  * instance.
48  *</p>
49  *
50  * @see TokenizerProperties
51  * @see TokenizerPropertyListener
52  * @author Heiko Blau
53  */

54 public class TokenizerPropertyEvent {
55   
56   //---------------------------------------------------------------------------
57
// constants
58
//
59

60   /**
61    * A property has been added.
62    */

63   public static final byte PROPERTY_ADDED = 1;
64   
65   /**
66    * A property has been removed.
67    */

68   public static final byte PROPERTY_REMOVED = 2;
69   
70   /**
71    * A property has been modified.
72    */

73   public static final byte PROPERTY_MODIFIED = 3;
74   
75   
76   //---------------------------------------------------------------------------
77
// constructors
78
//
79

80   /**
81    * The standard constructor initializes an emtpy event.
82    */

83   public TokenizerPropertyEvent() {
84     this(0, null);
85   }
86   
87   /**
88    * This constructor takes the type of the event and the {@link TokenizerProperty}
89    * that changed.
90    *
91    * @param type type of the event, one of the <code>PROPERTY_...</code> constants
92    * @param property the property that was added, removed or the new value of a modified one
93    */

94   public TokenizerPropertyEvent(int type, TokenizerProperty property) {
95     setType(type);
96     setProperty(property);
97     setOldProperty(null);
98   }
99   
100   /**
101    * This constructor takes the type of the event and the {@link TokenizerProperty}
102    * that changed together with its old value.
103    *
104    * @param type type of the event, one of the <code>PROPERTY_...</code> constants
105    * @param property the property that was added, removed or the new value of a modified one
106    * @param oldProperty the old value of the property that modified
107    */

108   public TokenizerPropertyEvent(int type, TokenizerProperty property, TokenizerProperty oldProperty) {
109     setType(type);
110     setProperty(property);
111     setOldProperty(null);
112   }
113   
114   //---------------------------------------------------------------------------
115
// getter and setter methods
116
//
117

118   /**
119    * Setting the event type. Use one of the <code>PROPERTY_...</code> constants
120    * for the parameter.
121    *
122    * @param type the event type
123    * @see #getType
124    * @see #PROPERTY_ADDED
125    * @see #PROPERTY_REMOVED
126    * @see #PROPERTY_MODIFIED
127    */

128   public void setType(int type) {
129     _type = type;
130   }
131   
132   /**
133    * Retrieving the event type. This will usually be one of the <code>PROPERTY_...</code>
134    * constants.
135    *
136    * @return the type of the event
137    */

138   public int getType() {
139     return _type;
140   }
141   
142   /**
143    * Setting the {@link TokenizerProperty} the event is about.
144    *
145    * @param property the added, removed or modified {@link TokenizerProperty}
146    */

147   public void setProperty(TokenizerProperty property) {
148     _property = property;
149   }
150   
151   /**
152    * Retrieving the property this event is reporting.
153    *
154    * @return the {@link TokenizerProperty} that is added, removed or modified
155    */

156   public TokenizerProperty getProperty() {
157     return _property;
158   }
159
160   /**
161    * Setting the {@link TokenizerProperty} that was changed. This is a valid
162    * method for the event {@link #PROPERTY_MODIFIED}.
163    *
164    * @param property the previously set {@link TokenizerProperty}
165    */

166   public void setOldProperty(TokenizerProperty property) {
167     _oldProperty = property;
168   }
169   
170   /**
171    * Retrieving the property that was set before the modification. The method
172    * returns <code>null</code> when the event is <strong>NOT</strong> {@link #PROPERTY_MODIFIED}.
173    *
174    * @return the {@link TokenizerProperty} set before the modification
175    */

176   public TokenizerProperty getOldProperty() {
177     return _oldProperty;
178   }
179
180   //---------------------------------------------------------------------------
181
// overloaded methods
182
//
183

184   /**
185    * Redefinition of the well-known {@link java.lang.Object#equals} method.
186    *
187    * @param that compare this instance with that object
188    * @return <code>true</code> if the two object describe the same property,
189    * <code>false</code> otherwise
190    */

191   public boolean equals(Object JavaDoc that) {
192     // primitive tests
193
if (that == null) {
194       return false;
195     } else if (that == this) {
196       return true;
197     } else if ( ! (that instanceof TokenizerPropertyEvent)) {
198       return false;
199     }
200     
201     // compare contents
202
TokenizerPropertyEvent thatEvent = (TokenizerPropertyEvent)that;
203     TokenizerProperty thatProp = thatEvent.getProperty();
204     TokenizerProperty thatOldProp = thatEvent.getOldProperty();
205     
206     if ( getType() == thatEvent.getType()
207         && (_property == thatProp || (_property != null && _property.equals(thatProp)))
208         && (_oldProperty == thatOldProp || (_oldProperty != null && _oldProperty.equals(thatOldProp)))) {
209       return true;
210     } else {
211       return false;
212     }
213   }
214     
215   /**
216    * Redefinition of the well-known {@link java.lang.Object#toString} method.
217    *
218    * @return a string representation of this <code>TokenizerProperty</code>
219    */

220   public String JavaDoc toString() {
221     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
222     
223     buffer.append(getClass().getName());
224     buffer.append(": ");
225
226     switch (_type) {
227     case PROPERTY_ADDED:
228       buffer.append("added ");
229       break;
230     case PROPERTY_REMOVED:
231       buffer.append("removed ");
232       break;
233     case PROPERTY_MODIFIED:
234       buffer.append("modified ");
235       break;
236     default:
237       buffer.append("<unknown type> ");
238     }
239     
240     if (getProperty() != null) {
241       buffer.append(getProperty().toString());
242     } else {
243       buffer.append("<no property>");
244     }
245     return buffer.toString();
246   }
247   
248   //---------------------------------------------------------------------------
249
// members
250
//
251
private int _type = 0;
252   private TokenizerProperty _property = null;
253   private TokenizerProperty _oldProperty = null;
254 }
255
Popular Tags