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: /*
042: * VeryComplexListDataEvent.java
043: *
044: * Created on November 6, 2003, 10:28 AM
045: */
046:
047: package org.netbeans.swing.tabcontrol.event;
048:
049: import org.netbeans.swing.tabcontrol.TabData;
050:
051: import java.util.Arrays;
052:
053: /**
054: * Event which provides granular data on setTabs() events which may contain
055: * arbitrary differences, moves, additions and removals of array contents (or no
056: * changes at all).
057: * <p>
058: * This event class is used in the case of calls to TabDataModel.setTabs(),
059: * where one array of TabData objects is replaced with a different array of
060: * TabData objects, which may contain additions, removals, deletions or moves.
061: * The heavy lifting is done by <code>ArrayDiff</code>, which provides lists of
062: * the affected indices for those things that are added/removed/changed/
063: * deleted.
064: * <p>
065: * Note that this class should eventually be merged with ComplexListDataEvent, along with
066: * some normalization of how things are done - it was written for expedience, not beauty.
067: *
068: * @author Tim Boudreau
069: * @see org.netbeans.swing.tabcontrol.event.ArrayDiff
070: */
071: public final class VeryComplexListDataEvent extends
072: ComplexListDataEvent {
073: TabData[] old, nue;
074:
075: //XXX, probably the structure of ComplexListDataEvent should eventually
076: //be modified to work more like this; the question is if it's killing
077: //a mosquito with a sledgehammer for simple changes - most changes will
078: //be simple, after all.
079:
080: /**
081: * Creates a new instance of VeryComplexListDataEvent
082: */
083: public VeryComplexListDataEvent(Object source, TabData[] old,
084: TabData[] nue) {
085: super (source, ITEMS_CHANGED, -1, -1);
086: this .old = old;
087: this .nue = nue;
088: }
089:
090: /**
091: * Returns an ArrayDiff object if the two arrays this event was created with
092: * are not identical
093: */
094: public ArrayDiff getDiff() {
095: return ArrayDiff.createDiff(old, nue);
096: }
097:
098: public String toString() {
099: StringBuffer sb = new StringBuffer();
100: sb.append("VeryComplexListEvent - old array: ");
101: sb.append(Arrays.asList(old));
102: sb.append(" new array: ");
103: sb.append(Arrays.asList(nue));
104: sb.append(" diff: ");
105: sb.append(getDiff());
106: return sb.toString();
107: }
108:
109: private static final void arr2str(Object[] o, StringBuffer sb) {
110: for (int i = 0; i < o.length; i++) {
111: sb.append(o[i]);
112: if (i != o.length - 1) {
113: sb.append(","); //NOI18N
114: }
115: }
116: }
117:
118: }
|