KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > VisualizerEvent


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 package org.openide.explorer.view;
20
21 import org.openide.nodes.*;
22
23 import java.util.Comparator JavaDoc;
24 import java.util.EventObject JavaDoc;
25 import java.util.LinkedList JavaDoc;
26
27
28 /** Event describing change in a visualizer. Runnable to be added into
29 * the event queue.
30 *
31 * @author Jaroslav Tulach
32 */

33 abstract class VisualizerEvent extends EventObject JavaDoc {
34     /** indicies */
35     int[] array;
36
37     public VisualizerEvent(VisualizerChildren ch, int[] array) {
38         super(ch);
39         this.array = array;
40     }
41
42     /** Getter for changed indexes */
43     public final int[] getArray() {
44         return array;
45     }
46
47     /** Getter for the children list.
48     */

49     public final VisualizerChildren getChildren() {
50         return (VisualizerChildren) getSource();
51     }
52
53     /** Getter for the visualizer.
54     */

55     public final VisualizerNode getVisualizer() {
56         return getChildren().parent;
57     }
58
59     /** Class for notification of adding of nodes that can be passed into
60     * the event queue and in such case notifies all listeners in Swing Dispatch Thread
61     */

62     static final class Added extends VisualizerEvent implements Runnable JavaDoc {
63         static final long serialVersionUID = 5906423476285962043L;
64
65         /** array of newly added nodes */
66         private Node[] added;
67
68         /** Constructor for add of nodes notification.
69         * @param ch children
70         * @param n array of added nodes
71         * @param indx indicies of added nodes
72         */

73         public Added(VisualizerChildren ch, Node[] n, int[] indx) {
74             super(ch, indx);
75             added = n;
76         }
77
78         /** Getter for added nodes.
79         */

80         public Node[] getAdded() {
81             return added;
82         }
83
84         /** Process the event
85         */

86         public void run() {
87             super.getChildren().added(this);
88         }
89     }
90
91     /** Class for notification of removing of nodes that can be passed into
92     * the event queue and in such case notifies all listeners in Swing Dispatch Thread
93     */

94     static final class Removed extends VisualizerEvent implements Runnable JavaDoc {
95         static final long serialVersionUID = 5102881916407672392L;
96
97         /** linked list of removed nodes, that is filled in getChildren ().removed () method
98         */

99         public LinkedList JavaDoc<VisualizerNode> removed = new LinkedList JavaDoc<VisualizerNode>();
100         private Node[] removedNodes;
101
102         /** Constructor for add of nodes notification.
103         * @param ch children
104         * @param n array of added nodes
105         * @param indx indicies of added nodes
106         */

107         public Removed(VisualizerChildren ch, Node[] removedNodes) {
108             super(ch, null);
109             this.removedNodes = removedNodes;
110         }
111
112         public Node[] getRemovedNodes() {
113             return removedNodes;
114         }
115
116         public void setRemovedIndicies(int[] arr) {
117             super.array = arr;
118         }
119
120         /** Process the event
121         */

122         public void run() {
123             super.getChildren().removed(this);
124         }
125     }
126
127     /** Class for notification of reordering of nodes that can be passed into
128     * the event queue and in such case notifies all listeners in Swing Dispatch Thread
129     */

130     static final class Reordered extends VisualizerEvent implements Runnable JavaDoc {
131         static final long serialVersionUID = -4572356079752325870L;
132         private Comparator JavaDoc<VisualizerNode> comparator = null;
133
134         /** Constructor for add of nodes notification.
135         * @param ch children
136         * @param n array of added nodes
137         * @param indx indicies of added nodes
138         */

139         public Reordered(VisualizerChildren ch, int[] indx) {
140             super(ch, indx);
141         }
142
143         //#37802 - provide a way to just send a comparator along to do the
144
//sorting
145
Reordered(VisualizerChildren ch, Comparator JavaDoc<VisualizerNode> comparator) {
146             this(ch, new int[0]);
147             this.comparator = comparator;
148         }
149
150         public Comparator JavaDoc<VisualizerNode> getComparator() {
151             return comparator;
152         }
153
154         /** Process the event
155         */

156         public void run() {
157             super.getChildren().reordered(this);
158         }
159     }
160 }
161
Popular Tags