KickJava   Java API By Example, From Geeks To Geeks.

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


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  * VeryComplexListDataEvent.java
21  *
22  * Created on November 6, 2003, 10:28 AM
23  */

24
25 package org.netbeans.swing.tabcontrol.event;
26
27 import org.netbeans.swing.tabcontrol.TabData;
28
29 import java.util.Arrays JavaDoc;
30
31 /**
32  * Event which provides granular data on setTabs() events which may contain
33  * arbitrary differences, moves, additions and removals of array contents (or no
34  * changes at all).
35  * <p>
36  * This event class is used in the case of calls to TabDataModel.setTabs(),
37  * where one array of TabData objects is replaced with a different array of
38  * TabData objects, which may contain additions, removals, deletions or moves.
39  * The heavy lifting is done by <code>ArrayDiff</code>, which provides lists of
40  * the affected indices for those things that are added/removed/changed/
41  * deleted.
42  * <p>
43  * Note that this class should eventually be merged with ComplexListDataEvent, along with
44  * some normalization of how things are done - it was written for expedience, not beauty.
45  *
46  * @author Tim Boudreau
47  * @see org.netbeans.swing.tabcontrol.event.ArrayDiff
48  */

49 public final class VeryComplexListDataEvent extends ComplexListDataEvent {
50     TabData[] old, nue;
51     
52     //XXX, probably the structure of ComplexListDataEvent should eventually
53
//be modified to work more like this; the question is if it's killing
54
//a mosquito with a sledgehammer for simple changes - most changes will
55
//be simple, after all.
56

57     /**
58      * Creates a new instance of VeryComplexListDataEvent
59      */

60     public VeryComplexListDataEvent(Object JavaDoc source, TabData[] old,
61                                     TabData[] nue) {
62         super(source, ITEMS_CHANGED, -1, -1);
63         this.old = old;
64         this.nue = nue;
65     }
66
67     /**
68      * Returns an ArrayDiff object if the two arrays this event was created with
69      * are not identical
70      */

71     public ArrayDiff getDiff() {
72         return ArrayDiff.createDiff(old, nue);
73     }
74
75     public String JavaDoc toString() {
76         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
77         sb.append("VeryComplexListEvent - old array: ");
78         sb.append(Arrays.asList(old));
79         sb.append(" new array: ");
80         sb.append(Arrays.asList(nue));
81         sb.append(" diff: ");
82         sb.append(getDiff());
83         return sb.toString();
84     }
85
86     private static final void arr2str(Object JavaDoc[] o, StringBuffer JavaDoc sb) {
87         for (int i = 0; i < o.length; i++) {
88             sb.append(o[i]);
89             if (i != o.length - 1) {
90                 sb.append(","); //NOI18N
91
}
92         }
93     }
94
95 }
96
Popular Tags