KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > PropertyBundleEvent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.properties;
21
22 import java.util.EventObject JavaDoc;
23
24 /**
25  * Notification of a change in a property bundle.
26  *
27  * @author Petr Jiricka
28  */

29 public class PropertyBundleEvent extends EventObject JavaDoc {
30
31     static final long serialVersionUID = 1702449038200791321L;
32
33     /** type of change - structure of the bundle may have been changed */
34     public static final int CHANGE_STRUCT = 1;
35
36     /** type of change - all data may have been changed */
37     public static final int CHANGE_ALL = 2;
38
39     /** type of change - single entry has changed */
40     public static final int CHANGE_FILE = 3;
41
42     /** type of change - single item has changed */
43     public static final int CHANGE_ITEM = 4;
44
45     /** name of the changed entry */
46     protected String JavaDoc entryName;
47
48     /** key of the changed item */
49     protected String JavaDoc itemName;
50
51     /** type of the change */
52     protected int changeType;
53
54     /**
55      * Creates an event representing a generic change.
56      *
57      * @param source source of the change
58      * @param changeType type of the change
59      * - one of the <code>CHANGE_xxx</code> constants
60      */

61     public PropertyBundleEvent(Object JavaDoc source, int changeType) {
62         super(source);
63         this.changeType = changeType;
64     }
65
66     /**
67      * Creates an event representing a change in a single entry.
68      *
69      * @param source source of the change
70      * @param entryName name of the changed entry
71      */

72     public PropertyBundleEvent(Object JavaDoc source, String JavaDoc entryName) {
73         super(source);
74         this.entryName = entryName;
75         changeType = CHANGE_FILE;
76     }
77
78     /**
79      * Creates an event representing a change in a single item of a single
80      * entry.
81      *
82      * @param source source of the change
83      * @param entryName name of the changed entry
84      * @param itemName name of the changed item
85      */

86     public PropertyBundleEvent(Object JavaDoc source, String JavaDoc entryName, String JavaDoc itemName) {
87         super(source);
88         this.entryName = entryName;
89         this.itemName = itemName;
90         changeType = CHANGE_ITEM;
91     }
92
93     /**
94      * Returns the type of this notification.
95      *
96      * @return one of the <code>CHANGE_xxx</code> constants defined
97      * in this class
98      */

99     public int getChangeType() {
100         return changeType;
101     }
102
103     /**
104      * Returns name of the modified entry.
105      *
106      * @return name of the modified entry; or <code>null</code> if the change
107      * may have touched multiple entries
108      */

109     public String JavaDoc getEntryName() {
110         return entryName;
111     }
112
113     /**
114      * Returns name of the modified item.
115      *
116      * @return name of the modified item; or <code>null</code> if the change
117      * may have changed multiple items
118      */

119     public String JavaDoc getItemName() {
120         return itemName;
121     }
122
123     /**
124      * @return full description (English only) of this event
125      */

126     public String JavaDoc toString() {
127         try {
128             String JavaDoc bundleName;
129             Object JavaDoc source = getSource();
130             bundleName = source instanceof BundleStructure
131                     ? ((BundleStructure) source).obj.getPrimaryFile().getName()
132                     : ""; //NOI18N
133

134             String JavaDoc changeType;
135             switch (getChangeType()) {
136                 case CHANGE_STRUCT : changeType = "STRUCT"; break; //NOI18N
137
case CHANGE_ALL : changeType = "ALL"; break; //NOI18N
138
case CHANGE_FILE : changeType = "FILE"; break; //NOI18N
139
case CHANGE_ITEM : changeType = "ITEM"; break; //NOI18N
140
default : changeType = "?"; break; //NOI18N
141
}
142
143             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(80);
144             buf.append("PropertyBundleEvent: bundle ") //NOI18N
145
.append(bundleName);
146             buf.append(", changeType ").append(changeType); //NOI18N
147
buf.append(", entry ").append(getEntryName()); //NOI18N
148
buf.append(", item ").append(getItemName()); //NOI18N
149
return buf.toString();
150         }
151         catch (Exception JavaDoc e) {
152             return "some PropertyBundleEvent exception (" //NOI18N
153
+ e.toString() + ") occurred"; //NOI18N
154
}
155     }
156
157 }
158
Popular Tags