001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *//*
041: * ComplexListDataEvent.java
042: *
043: * Created on May 26, 2003, 5:17 PM
044: */
045:
046: package org.netbeans.swing.tabcontrol.event;
047:
048: import org.netbeans.swing.tabcontrol.TabData;
049:
050: import javax.swing.event.ListDataEvent;
051:
052: /**
053: * An extension to ListDataEvent which can report data about non-contiguous
054: * changes to data.
055: *
056: * Eventually <code>VeryComplexListDataEvent</code> (which can also report
057: * about relocation of items) should be merged into this class; it's currently
058: * slightly crufty.
059: *
060: * @author Tim Boudreau
061: */
062: public class ComplexListDataEvent extends ListDataEvent {
063: private static final int LAST = INTERVAL_REMOVED;
064: /**
065: * ID for events in which non-contiguous elements have been added
066: */
067: public static final int ITEMS_ADDED = LAST + 1;
068: /**
069: * ID for events in which non-contiguous elements have been removed
070: */
071: public static final int ITEMS_REMOVED = LAST + 2;
072: /**
073: * ID for events in which non-contiguous elements have been added, removed
074: * or changed
075: */
076: static final int ITEMS_CHANGED = LAST + 3;
077: private int[] indices;
078: private boolean textChanged;
079: private boolean componentChanged = false;
080:
081: /**
082: * Creates a new instance of ComplexListDataEvent. The index0 and index1
083: * properties will return -1.
084: *
085: * @param source The event source
086: * @param id The type of change
087: * @param indices An array of possibly non-contiguous indices of data
088: * which has changed
089: * @param textChanged True if the change is one that can affect display
090: * (icon width or text changes)
091: */
092: public ComplexListDataEvent(Object source, int id, int[] indices,
093: boolean textChanged) {
094: super (source, id, -1, -1);
095: this .textChanged = textChanged;
096: this .indices = indices;
097: }
098:
099: /**
100: * Passthrough constructor for ListDataEvent. <code>getIndices()</code>
101: * will return null for this event.
102: *
103: * @param source The source of the event
104: * @param id The type of change
105: * @param start The start index for the change
106: * @param end The end index for the change
107: */
108: public ComplexListDataEvent(Object source, int id, int start,
109: int end) {
110: super (source, id, start, end);
111: textChanged = true;
112: indices = null;
113: }
114:
115: public ComplexListDataEvent(Object source, int id, int start,
116: int end, boolean textChanged, boolean compChange) {
117: super (source, id, start, end);
118: textChanged = true;
119: indices = null;
120: componentChanged = compChange;
121: }
122:
123: /**
124: * Passthrough constructor for ListDataEvent. <code>getIndices()</code>
125: * will return null for this event.
126: *
127: * @param source The source of the event
128: * @param id The type of change
129: * @param start The start index of a contiguous change
130: * @param end The end index of a contiguous change
131: * @param textChanged True if the change is one that can affect display
132: * metrics (text or icon size)
133: */
134: public ComplexListDataEvent(Object source, int id, int start,
135: int end, boolean textChanged) {
136: this (source, id, start, end);
137: this .textChanged = textChanged;
138: indices = null;
139: }
140:
141: /**
142: * Get the indices which have changed for this event.
143: *
144: * @return The changed indices, or null for contiguous data changes
145: */
146: public int[] getIndices() {
147: return indices;
148: }
149:
150: /**
151: * Does the change event represent a change that can affect display metrics
152: *
153: * @return True if the change affected text length or icon width
154: */
155: public boolean isTextChanged() {
156: return textChanged;
157: }
158:
159: /**
160: * Does the change event represent a change in components. This should be
161: * true for cases where a component was replaced, added or removed
162: */
163: public boolean isUserObjectChanged() {
164: return componentChanged;
165: }
166:
167: public String toString() {
168: String[] types = new String[] { "CONTENTS_CHANGED",
169: "INTERVAL_ADDED", //NOI18N
170: "INTERVAL_REMOVED", "ITEMS_ADDED", "ITEMS_REMOVED" }; //NOI18N
171: StringBuffer out = new StringBuffer(getClass().getName());
172: out.append(" - " + types[getType()] + " - ");
173: if (getType() <= INTERVAL_REMOVED) {
174: out.append("start=" + getIndex0() + " end=" + getIndex1()
175: + " "); //NOI18N
176: } else {
177: int[] ids = getIndices();
178: if (ids != null) {
179: for (int i = 0; i < ids.length; i++) {
180: out.append(ids[i]);
181: if (i != ids.length - 1) {
182: out.append(','); //NOI18N
183: }
184: }
185: } else {
186: out.append("null"); //NOI18N
187: }
188: }
189: return out.toString();
190: }
191:
192: public void setAffectedItems(TabData[] td) {
193: affectedItems = td;
194: }
195:
196: public TabData[] getAffectedItems() {
197: return affectedItems;
198: }
199:
200: private TabData[] affectedItems = null;
201: }
|