KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > nodes > NodeReorderEvent


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.nodes;
20
21
22 /** Event describing change in the list of a node's children.
23 *
24 * @author Jaroslav Tulach
25 */

26 public final class NodeReorderEvent extends NodeEvent {
27     static final long serialVersionUID = 4479234495493767448L;
28
29     /** list of new nodes indexes on the original positions */
30     private int[] newIndices;
31
32     /** Package private constructor to allow construction only
33     * @param node the node that has changed
34     * @param newIndices new indexes of the nodes
35     */

36     NodeReorderEvent(Node n, int[] newIndices) {
37         super(n);
38         this.newIndices = newIndices;
39     }
40
41     /** Get the new position of the child that had been at a given position.
42     * @param i the original position of the child
43     * @return the new position of the child
44     */

45     public int newIndexOf(int i) {
46         return newIndices[i];
47     }
48
49     /** Get the permutation used for reordering.
50     * @return array of integers used for reordering
51     */

52     public int[] getPermutation() {
53         return newIndices;
54     }
55
56     /** Get the number of children reordered.
57      * @return size of the permutation array */

58     public int getPermutationSize() {
59         return newIndices.length;
60     }
61
62     /** Human presentable information about the event */
63     public String JavaDoc toString() {
64         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
65         sb.append(getClass().getName());
66         sb.append("[node="); // NOI18N
67
sb.append(getSource());
68         sb.append(", permutation = ("); // NOI18N
69

70         int[] perm = getPermutation();
71
72         for (int i = 0; i < perm.length;) {
73             sb.append(perm[i]);
74
75             if (++i < perm.length) {
76                 sb.append(", "); // NOI18N
77
}
78         }
79
80         sb.append(")]"); // NOI18N
81

82         return sb.toString();
83     }
84 }
85
Popular Tags