~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to openide/explorer/src/org/openide/explorer/view/VisualizerEvent.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.openide.explorer.view;
 
42
 
 
43
import org.openide.nodes.*;
 
44
 
 
45
import java.util.Comparator;
 
46
import java.util.EventObject;
 
47
import java.util.LinkedList;
 
48
 
 
49
 
 
50
/** Event describing change in a visualizer. Runnable to be added into
 
51
* the event queue.
 
52
*
 
53
* @author Jaroslav Tulach
 
54
*/
 
55
abstract class VisualizerEvent extends EventObject {
 
56
    /** indicies */
 
57
    int[] array;
 
58
 
 
59
    public VisualizerEvent(VisualizerChildren ch, int[] array) {
 
60
        super(ch);
 
61
        this.array = array;
 
62
    }
 
63
 
 
64
    /** Getter for changed indexes */
 
65
    public final int[] getArray() {
 
66
        return array;
 
67
    }
 
68
 
 
69
    /** Getter for the children list.
 
70
    */
 
71
    public final VisualizerChildren getChildren() {
 
72
        return (VisualizerChildren) getSource();
 
73
    }
 
74
 
 
75
    /** Getter for the visualizer.
 
76
    */
 
77
    public final VisualizerNode getVisualizer() {
 
78
        return getChildren().parent;
 
79
    }
 
80
 
 
81
    /** Class for notification of adding of nodes that can be passed into
 
82
    * the event queue and in such case notifies all listeners in Swing Dispatch Thread
 
83
    */
 
84
    static final class Added extends VisualizerEvent implements Runnable {
 
85
        static final long serialVersionUID = 5906423476285962043L;
 
86
 
 
87
        /** array of newly added nodes */
 
88
        private Node[] added;
 
89
 
 
90
        /** Constructor for add of nodes notification.
 
91
        * @param ch children
 
92
        * @param n array of added nodes
 
93
        * @param indx indicies of added nodes
 
94
        */
 
95
        public Added(VisualizerChildren ch, Node[] n, int[] indx) {
 
96
            super(ch, indx);
 
97
            added = n;
 
98
        }
 
99
 
 
100
        /** Getter for added nodes.
 
101
        */
 
102
        public Node[] getAdded() {
 
103
            return added;
 
104
        }
 
105
 
 
106
        /** Process the event
 
107
        */
 
108
        public void run() {
 
109
            super.getChildren().added(this);
 
110
        }
 
111
    }
 
112
 
 
113
    /** Class for notification of removing of nodes that can be passed into
 
114
    * the event queue and in such case notifies all listeners in Swing Dispatch Thread
 
115
    */
 
116
    static final class Removed extends VisualizerEvent implements Runnable {
 
117
        static final long serialVersionUID = 5102881916407672392L;
 
118
 
 
119
        /** linked list of removed nodes, that is filled in getChildren ().removed () method
 
120
        */
 
121
        public LinkedList<VisualizerNode> removed = new LinkedList<VisualizerNode>();
 
122
        private Node[] removedNodes;
 
123
 
 
124
        /** Constructor for add of nodes notification.
 
125
        * @param ch children
 
126
        * @param n array of added nodes
 
127
        * @param indx indicies of added nodes
 
128
        */
 
129
        public Removed(VisualizerChildren ch, Node[] removedNodes) {
 
130
            super(ch, null);
 
131
            this.removedNodes = removedNodes;
 
132
        }
 
133
 
 
134
        public Node[] getRemovedNodes() {
 
135
            return removedNodes;
 
136
        }
 
137
 
 
138
        public void setRemovedIndicies(int[] arr) {
 
139
            super.array = arr;
 
140
        }
 
141
 
 
142
        /** Process the event
 
143
        */
 
144
        public void run() {
 
145
            super.getChildren().removed(this);
 
146
        }
 
147
    }
 
148
 
 
149
    /** Class for notification of reordering of nodes that can be passed into
 
150
    * the event queue and in such case notifies all listeners in Swing Dispatch Thread
 
151
    */
 
152
    static final class Reordered extends VisualizerEvent implements Runnable {
 
153
        static final long serialVersionUID = -4572356079752325870L;
 
154
        private Comparator<VisualizerNode> comparator = null;
 
155
 
 
156
        /** Constructor for add of nodes notification.
 
157
        * @param ch children
 
158
        * @param n array of added nodes
 
159
        * @param indx indicies of added nodes
 
160
        */
 
161
        public Reordered(VisualizerChildren ch, int[] indx) {
 
162
            super(ch, indx);
 
163
        }
 
164
 
 
165
        //#37802 - provide a way to just send a comparator along to do the 
 
166
        //sorting
 
167
        Reordered(VisualizerChildren ch, Comparator<VisualizerNode> comparator) {
 
168
            this(ch, new int[0]);
 
169
            this.comparator = comparator;
 
170
        }
 
171
 
 
172
        public Comparator<VisualizerNode> getComparator() {
 
173
            return comparator;
 
174
        }
 
175
 
 
176
        /** Process the event
 
177
        */
 
178
        public void run() {
 
179
            super.getChildren().reordered(this);
 
180
        }
 
181
    }
 
182
}