KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Information about state changes made in a particular fold.
24  * <br>
25  * Zero or more of the state change instances can be part of a particular
26  * {@link FoldHierarchyEvent}.
27  *
28  * <p>
29  * It can be extended to carry additional information specific to particular fold
30  * types.
31  *
32  * @author Miloslav Metelka
33  * @version 1.00
34  */

35
36 public final class FoldStateChange {
37
38     private static final int COLLAPSED_CHANGED_BIT = 1;
39
40     private static final int START_OFFSET_CHANGED_BIT = 2;
41
42     private static final int END_OFFSET_CHANGED_BIT = 4;
43     
44     private static final int DESCRIPTION_CHANGED_BIT = 8;
45
46
47     private Fold fold;
48
49     private int stateChangeBits;
50     
51     private int originalStartOffset = -1;
52
53     private int originalEndOffset = -1;
54     
55     /**
56      * Construct state change.
57      * @param fold fold being changed.
58      */

59     FoldStateChange(Fold fold) {
60         this.fold = fold;
61     }
62     
63     /**
64      * Get the fold that has changed its state.
65      */

66     public Fold getFold() {
67         return fold;
68     }
69
70     /**
71      * Has the collapsed flag of the fold
72      * (returned by <code>getFold()</code>) changed?
73      *
74      * @return true if the collapsed flag has changed in the fold
75      * or false otherwise.
76      */

77     public boolean isCollapsedChanged() {
78         return ((stateChangeBits & COLLAPSED_CHANGED_BIT) != 0);
79     }
80     
81     /**
82      * Has the start offset of the fold
83      * (returned by <code>getFold()</code>) changed?
84      *
85      * @return true if the start offset has changed in the fold
86      * or false otherwise.
87      */

88     public boolean isStartOffsetChanged() {
89         return ((stateChangeBits & START_OFFSET_CHANGED_BIT) != 0);
90     }
91     
92     /**
93      * Return the original start offset of the fold prior
94      * to change to the current start offset that the fold has now.
95      * <br>
96      * @return original start offset or -1 if the start offset was not changed
97      * for the fold.
98      */

99     public int getOriginalStartOffset() {
100         return originalStartOffset;
101     }
102
103     /**
104      * Has the end offset of the fold
105      * (returned by <code>getFold()</code>) changed?
106      *
107      * @return true if the end offset has changed in the fold
108      * or false otherwise.
109      */

110     public boolean isEndOffsetChanged() {
111         return ((stateChangeBits & END_OFFSET_CHANGED_BIT) != 0);
112     }
113     
114     /**
115      * Return the original end offset of the fold prior
116      * to change to the current end offset that the fold has now.
117      * <br>
118      * @return original end offset or -1 if the end offset was not changed
119      * for the fold.
120      */

121     public int getOriginalEndOffset() {
122         return originalEndOffset;
123     }
124
125     /**
126      * Has the text description of the collapsed fold
127      * (returned by <code>getFold()</code>) changed?
128      *
129      * @return true if the collapsed text description has changed in the fold
130      * or false otherwise.
131      */

132     public boolean isDescriptionChanged() {
133         return ((stateChangeBits & DESCRIPTION_CHANGED_BIT) != 0);
134     }
135
136     /**
137      * Mark that collapsed flag has changed
138      * for the fold.
139      */

140     void collapsedChanged() {
141         stateChangeBits |= COLLAPSED_CHANGED_BIT;
142     }
143     
144     /**
145      * Mark that start offset has changed
146      * for the fold.
147      */

148     void startOffsetChanged(int originalStartOffset) {
149         stateChangeBits |= START_OFFSET_CHANGED_BIT;
150         this.originalStartOffset = originalStartOffset;
151     }
152     
153     /**
154      * Subclasses can mark that end offset has changed
155      * for the fold.
156      */

157     void endOffsetChanged(int originalEndOffset) {
158         stateChangeBits |= END_OFFSET_CHANGED_BIT;
159         this.originalEndOffset = originalEndOffset;
160     }
161     
162     /**
163      * Subclasses can mark that collapsed flag has changed
164      * for the fold.
165      */

166     void descriptionChanged() {
167         stateChangeBits |= DESCRIPTION_CHANGED_BIT;
168     }
169     
170     public String JavaDoc toString() {
171         return org.netbeans.modules.editor.fold.FoldUtilitiesImpl.foldStateChangeToString(this);
172     }
173
174 }
175
Popular Tags