Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ModificationEvent |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2003-2004 The Apache Software Foundation | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.apache.commons.events.observable; | |
17 | ||
18 | import java.util.Collection; | |
19 | import java.util.EventObject; | |
20 | ||
21 | /** | |
22 | * Base event class extended by each class that encapsulates event information. | |
23 | * <p> | |
24 | * This class can be used as is, but generally it is subclassed. | |
25 | * | |
26 | * @since Commons Events 1.0 | |
27 | * @version $Revision: 155443 $ $Date: 2005-02-26 13:19:51 +0000 (Sat, 26 Feb 2005) $ | |
28 | * | |
29 | * @author Stephen Colebourne | |
30 | */ | |
31 | public class ModificationEvent extends EventObject { | |
32 | ||
33 | /** The source collection */ | |
34 | protected final ObservableCollection collection; | |
35 | /** The handler */ | |
36 | protected final ModificationHandler handler; | |
37 | /** The event code */ | |
38 | protected final int type; | |
39 | ||
40 | // Constructor | |
41 | //----------------------------------------------------------------------- | |
42 | /** | |
43 | * Constructor. | |
44 | * | |
45 | * @param obsCollection the event source | |
46 | * @param handler the handler | |
47 | * @param type the event type | |
48 | */ | |
49 | public ModificationEvent( | |
50 | final ObservableCollection obsCollection, | |
51 | final ModificationHandler handler, | |
52 | final int type) { | |
53 | ||
54 | 0 | super(obsCollection); |
55 | 0 | this.collection = obsCollection; |
56 | 0 | this.handler = handler; |
57 | 0 | this.type = type; |
58 | 0 | } |
59 | ||
60 | // Basic info | |
61 | //----------------------------------------------------------------------- | |
62 | /** | |
63 | * Gets the collection the event is reporting on. | |
64 | * <p> | |
65 | * Using this collection will bypass any decorators that have been added | |
66 | * to the <code>ObservableCollection</code>. For example, if a synchronized | |
67 | * decorator was added it will not be called by changes to this collection. | |
68 | * <p> | |
69 | * For the synchronization case, you are normally OK however. If you | |
70 | * process the event in the same thread as the original change then your | |
71 | * code will be protected by the original synchronized decorator and this | |
72 | * collection may be used freely. | |
73 | * | |
74 | * @return the collection | |
75 | */ | |
76 | public ObservableCollection getObservedCollection() { | |
77 | 0 | return collection; |
78 | } | |
79 | ||
80 | /** | |
81 | * Gets the base collection underlying the observable collection. | |
82 | * <p> | |
83 | * Using this collection will bypass the event sending mechanism. | |
84 | * It will also bypass any other decorators, such as synchronization. | |
85 | * Use with care. | |
86 | * | |
87 | * @return the collection | |
88 | */ | |
89 | public Collection getBaseCollection() { | |
90 | 0 | return handler.getBaseCollection(); |
91 | } | |
92 | ||
93 | /** | |
94 | * Gets the handler of the events. | |
95 | * | |
96 | * @return the handler | |
97 | */ | |
98 | public ModificationHandler getHandler() { | |
99 | 0 | return handler; |
100 | } | |
101 | ||
102 | /** | |
103 | * Gets the event type constant. | |
104 | * <p> | |
105 | * This is one of the <i>method</i> constants from {@link ModificationEventType}. | |
106 | * | |
107 | * @return the method event type constant | |
108 | */ | |
109 | public int getType() { | |
110 | 0 | return type; |
111 | } | |
112 | ||
113 | // toString | |
114 | //----------------------------------------------------------------------- | |
115 | /** | |
116 | * Gets a debugging string version of the event. | |
117 | * | |
118 | * @return a debugging string | |
119 | */ | |
120 | public String toString() { | |
121 | 0 | StringBuffer buf = new StringBuffer(64); |
122 | 0 | buf.append("ModificationEvent[type="); |
123 | 0 | buf.append(ModificationEventType.toString(type)); |
124 | 0 | buf.append(']'); |
125 | 0 | return buf.toString(); |
126 | } | |
127 | ||
128 | } |