KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > editor > fold > FoldHierarchyEvent


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 package org.netbeans.api.editor.fold;
21
22 /**
23  * Event describing the changes done in the hierarchy.
24  * <br>
25  * The structural changes are described by the lists of added and removed folds.
26  * <br>
27  * State changes are described by a list of {@link FoldStateChange}s.
28  * <br>
29  * In addition there is a description of the offset range that was
30  * affected by the change. This is useful for the editor
31  * to recreate the affected views and repaint the affected area.
32  * <p>
33  * Added folds can have either collapsed or expanded initial state.
34  *
35  * @author Miloslav Metelka
36  * @version 1.00
37  */

38
39 public final class FoldHierarchyEvent extends java.util.EventObject JavaDoc {
40     
41     private Fold[] removedFolds;
42     
43     private Fold[] addedFolds;
44     
45     private FoldStateChange[] foldStateChanges;
46
47     private int affectedStartOffset;
48     
49     private int affectedEndOffset;
50
51     /**
52      * Create new FoldHierarchyEvent.
53      * <br>
54      * It's guaranteed that no passed arrays contents will be modified.
55      *
56      * @param source FoldHierarchy for which this event gets created.
57      * @param removedFolds non-null array of removed folds.
58      * @param addedFolds non-null array of added folds.
59      * @param foldStateChanges changes describing changes in the state
60      * of particular folds.
61      * @param affectedStartOffset first offset in the document affected by this change.
62      * @param affectedEndOffset end of the offset area affected by this change.
63      */

64     FoldHierarchyEvent(FoldHierarchy source,
65     Fold[] removedFolds, Fold[] addedFolds,
66     FoldStateChange[] foldStateChanges, int affectedStartOffset, int affectedEndOffset) {
67
68         super(source);
69
70         this.removedFolds = removedFolds;
71         this.addedFolds = addedFolds;
72         this.foldStateChanges = foldStateChanges;
73         this.affectedStartOffset = affectedStartOffset;
74         this.affectedEndOffset = affectedEndOffset;
75     }
76     
77     /**
78      * Get the number of folds removed from the hierarchy.
79      *
80      * @return &gt;=0 number of removed folds.
81      */

82     public int getRemovedFoldCount() {
83         return removedFolds.length;
84     }
85
86     /**
87      * Get the fold with the given index removed
88      * from the fold hierarchy.
89      *
90      * @param removedFoldIndex &gt;=0 and &lt;{@link #getRemovedFoldCount()}
91      * index of the removed fold.
92      */

93     public Fold getRemovedFold(int removedFoldIndex) {
94         return removedFolds[removedFoldIndex];
95     }
96
97     /**
98      * Get the number of folds that were added to the hierarchy.
99      *
100      * @return &gt;=0 number of added folds.
101      */

102     public int getAddedFoldCount() {
103         return addedFolds.length;
104     }
105
106     /**
107      * Get the fold with the given index added
108      * to the hierarchy.
109      *
110      * @param addedFoldIndex &gt;=0 and &lt;{@link #getAddedFoldCount()}
111      * index of the added fold.
112      */

113     public Fold getAddedFold(int addedFoldIndex) {
114         return addedFolds[addedFoldIndex];
115     }
116
117     /**
118      * Get the number of the fold state changes contained in this event.
119      *
120      * @return &gt;=0 number of fold state changes.
121      */

122     public int getFoldStateChangeCount() {
123         return foldStateChanges.length;
124     }
125     
126     /**
127      * Get the fold state change at the given index.
128      *
129      * @param index &gt;=0 and &lt;{@link #getFoldStateChangeCount()}
130      * index of the fold state change.
131      */

132     public FoldStateChange getFoldStateChange(int index) {
133         return foldStateChanges[index];
134     }
135     
136     /**
137      * Get the first offset in the underlying document affected
138      * by this change.
139      *
140      * @return &gt;=0 first offset affected by the change.
141      */

142     public int getAffectedStartOffset() {
143         return affectedStartOffset;
144     }
145     
146     /**
147      * Get the ending offset in the offset area affected
148      * by this change.
149      *
150      * @return &gt;={@link #getAffectedStartOffset()}
151      * end of the offset area affected by the change.
152      */

153     public int getAffectedEndOffset() {
154         return affectedEndOffset;
155     }
156
157     public String JavaDoc toString() {
158         return org.netbeans.modules.editor.fold.FoldUtilitiesImpl.foldHierarchyEventToString(this);
159     }
160
161 }
162
Popular Tags