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: package org.openide.explorer.view;
042:
043: import org.openide.nodes.*;
044:
045: import java.util.Comparator;
046: import java.util.EventObject;
047: import java.util.LinkedList;
048:
049: /** Event describing change in a visualizer. Runnable to be added into
050: * the event queue.
051: *
052: * @author Jaroslav Tulach
053: */
054: abstract class VisualizerEvent extends EventObject {
055: /** indicies */
056: int[] array;
057:
058: public VisualizerEvent(VisualizerChildren ch, int[] array) {
059: super (ch);
060: this .array = array;
061: }
062:
063: /** Getter for changed indexes */
064: public final int[] getArray() {
065: return array;
066: }
067:
068: /** Getter for the children list.
069: */
070: public final VisualizerChildren getChildren() {
071: return (VisualizerChildren) getSource();
072: }
073:
074: /** Getter for the visualizer.
075: */
076: public final VisualizerNode getVisualizer() {
077: return getChildren().parent;
078: }
079:
080: /** Class for notification of adding of nodes that can be passed into
081: * the event queue and in such case notifies all listeners in Swing Dispatch Thread
082: */
083: static final class Added extends VisualizerEvent implements
084: Runnable {
085: static final long serialVersionUID = 5906423476285962043L;
086:
087: /** array of newly added nodes */
088: private Node[] added;
089:
090: /** Constructor for add of nodes notification.
091: * @param ch children
092: * @param n array of added nodes
093: * @param indx indicies of added nodes
094: */
095: public Added(VisualizerChildren ch, Node[] n, int[] indx) {
096: super (ch, indx);
097: added = n;
098: }
099:
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
117: Runnable {
118: static final long serialVersionUID = 5102881916407672392L;
119:
120: /** linked list of removed nodes, that is filled in getChildren ().removed () method
121: */
122: public LinkedList<VisualizerNode> removed = new LinkedList<VisualizerNode>();
123: private Node[] removedNodes;
124:
125: /** Constructor for add of nodes notification.
126: * @param ch children
127: * @param n array of added nodes
128: * @param indx indicies of added nodes
129: */
130: public Removed(VisualizerChildren ch, Node[] removedNodes) {
131: super (ch, null);
132: this .removedNodes = removedNodes;
133: }
134:
135: public Node[] getRemovedNodes() {
136: return removedNodes;
137: }
138:
139: public void setRemovedIndicies(int[] arr) {
140: super .array = arr;
141: }
142:
143: /** Process the event
144: */
145: public void run() {
146: super .getChildren().removed(this );
147: }
148: }
149:
150: /** Class for notification of reordering of nodes that can be passed into
151: * the event queue and in such case notifies all listeners in Swing Dispatch Thread
152: */
153: static final class Reordered extends VisualizerEvent implements
154: Runnable {
155: static final long serialVersionUID = -4572356079752325870L;
156: private Comparator<VisualizerNode> comparator = null;
157:
158: /** Constructor for add of nodes notification.
159: * @param ch children
160: * @param n array of added nodes
161: * @param indx indicies of added nodes
162: */
163: public Reordered(VisualizerChildren ch, int[] indx) {
164: super (ch, indx);
165: }
166:
167: //#37802 - provide a way to just send a comparator along to do the
168: //sorting
169: Reordered(VisualizerChildren ch,
170: Comparator<VisualizerNode> comparator) {
171: this (ch, new int[0]);
172: this .comparator = comparator;
173: }
174:
175: public Comparator<VisualizerNode> getComparator() {
176: return comparator;
177: }
178:
179: /** Process the event
180: */
181: public void run() {
182: super.getChildren().reordered(this);
183: }
184: }
185: }
|