KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > event > ComplexListDataEvent


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  * ComplexListDataEvent.java
20  *
21  * Created on May 26, 2003, 5:17 PM
22  */

23
24 package org.netbeans.swing.tabcontrol.event;
25
26 import org.netbeans.swing.tabcontrol.TabData;
27
28 import javax.swing.event.ListDataEvent JavaDoc;
29
30 /**
31  * An extension to ListDataEvent which can report data about non-contiguous
32  * changes to data.
33  *
34  * Eventually <code>VeryComplexListDataEvent</code> (which can also report
35  * about relocation of items) should be merged into this class; it's currently
36  * slightly crufty.
37  *
38  * @author Tim Boudreau
39  */

40 public class ComplexListDataEvent extends ListDataEvent JavaDoc {
41     private static final int LAST = INTERVAL_REMOVED;
42     /**
43      * ID for events in which non-contiguous elements have been added
44      */

45     public static final int ITEMS_ADDED = LAST + 1;
46     /**
47      * ID for events in which non-contiguous elements have been removed
48      */

49     public static final int ITEMS_REMOVED = LAST + 2;
50     /**
51      * ID for events in which non-contiguous elements have been added, removed
52      * or changed
53      */

54     static final int ITEMS_CHANGED = LAST + 3;
55     private int[] indices;
56     private boolean textChanged;
57     private boolean componentChanged = false;
58
59     /**
60      * Creates a new instance of ComplexListDataEvent. The index0 and index1
61      * properties will return -1.
62      *
63      * @param source The event source
64      * @param id The type of change
65      * @param indices An array of possibly non-contiguous indices of data
66      * which has changed
67      * @param textChanged True if the change is one that can affect display
68      * (icon width or text changes)
69      */

70     public ComplexListDataEvent(Object JavaDoc source, int id, int[] indices,
71                                 boolean textChanged) {
72         super(source, id, -1, -1);
73         this.textChanged = textChanged;
74         this.indices = indices;
75     }
76
77     /**
78      * Passthrough constructor for ListDataEvent. <code>getIndices()</code>
79      * will return null for this event.
80      *
81      * @param source The source of the event
82      * @param id The type of change
83      * @param start The start index for the change
84      * @param end The end index for the change
85      */

86     public ComplexListDataEvent(Object JavaDoc source, int id, int start, int end) {
87         super(source, id, start, end);
88         textChanged = true;
89         indices = null;
90     }
91
92     public ComplexListDataEvent(Object JavaDoc source, int id, int start, int end,
93                                 boolean textChanged, boolean compChange) {
94         super(source, id, start, end);
95         textChanged = true;
96         indices = null;
97         componentChanged = compChange;
98     }
99
100     /**
101      * Passthrough constructor for ListDataEvent. <code>getIndices()</code>
102      * will return null for this event.
103      *
104      * @param source The source of the event
105      * @param id The type of change
106      * @param start The start index of a contiguous change
107      * @param end The end index of a contiguous change
108      * @param textChanged True if the change is one that can affect display
109      * metrics (text or icon size)
110      */

111     public ComplexListDataEvent(Object JavaDoc source, int id, int start, int end,
112                                 boolean textChanged) {
113         this(source, id, start, end);
114         this.textChanged = textChanged;
115         indices = null;
116     }
117
118     /**
119      * Get the indices which have changed for this event.
120      *
121      * @return The changed indices, or null for contiguous data changes
122      */

123     public int[] getIndices() {
124         return indices;
125     }
126
127     /**
128      * Does the change event represent a change that can affect display metrics
129      *
130      * @return True if the change affected text length or icon width
131      */

132     public boolean isTextChanged() {
133         return textChanged;
134     }
135
136     /**
137      * Does the change event represent a change in components. This should be
138      * true for cases where a component was replaced, added or removed
139      */

140     public boolean isUserObjectChanged() {
141         return componentChanged;
142     }
143
144     public String JavaDoc toString() {
145         String JavaDoc[] types = new String JavaDoc[]{
146             "CONTENTS_CHANGED", "INTERVAL_ADDED", //NOI18N
147
"INTERVAL_REMOVED", "ITEMS_ADDED",
148             "ITEMS_REMOVED"}; //NOI18N
149
StringBuffer JavaDoc out = new StringBuffer JavaDoc(getClass().getName());
150         out.append(" - " + types[getType()] + " - ");
151         if (getType() <= INTERVAL_REMOVED) {
152             out.append("start=" + getIndex0() + " end=" + getIndex1() + " "); //NOI18N
153
} else {
154             int[] ids = getIndices();
155             if (ids != null) {
156                 for (int i = 0; i < ids.length; i++) {
157                     out.append(ids[i]);
158                     if (i != ids.length - 1) {
159                         out.append(','); //NOI18N
160
}
161                 }
162             } else {
163                 out.append("null"); //NOI18N
164
}
165         }
166         return out.toString();
167     }
168
169     public void setAffectedItems(TabData[] td) {
170         affectedItems = td;
171     }
172
173     public TabData[] getAffectedItems() {
174         return affectedItems;
175     }
176
177     private TabData[] affectedItems = null;
178 }
179
Popular Tags