|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.netbeans.api.editor.fold.FoldUtilities
Various utility methods for dealing with the folds.
Note: Until explicitly noted all the utility methods
require a lock to be held on the FoldHierarchy
during execution of the methods.
Method Summary | |
static List |
childrenAsList(Fold fold)
Return children of the given fold as modifiable list. |
static List |
childrenAsList(Fold fold,
int index,
int count)
Return children of the given fold as list. |
static Fold[] |
childrenToArray(Fold fold)
Return children of the given fold as array. |
static Fold[] |
childrenToArray(Fold fold,
int index,
int count)
Return children of the given fold as array. |
static void |
collapse(FoldHierarchy hierarchy,
Collection foldTypes)
Collapse all folds that having any of the fold types in the given collection. |
static void |
collapse(FoldHierarchy hierarchy,
FoldType type)
Collapse all folds of the given type. |
static void |
collapseAll(FoldHierarchy hierarchy)
Collapse all folds in the hierarchy. |
static Iterator |
collapsedFoldIterator(FoldHierarchy hierarchy,
int startOffset,
int endOffset)
Get iterator over the collapsed folds. |
static boolean |
containsOffset(Fold fold,
int offset)
Check whether fold contains the given offset. |
static void |
expand(FoldHierarchy hierarchy,
Collection foldTypes)
Expand all folds of the given type (or all folds if the type is null) found in the whole fold hierarchy. |
static void |
expand(FoldHierarchy hierarchy,
FoldType type)
Expand all folds of the given type. |
static void |
expandAll(FoldHierarchy hierarchy)
Expand all folds in the hierarchy. |
static List |
find(Fold fold,
Collection foldTypes)
Find direct subfolds of the given fold having any of the fold types in the given collection. |
static List |
find(Fold fold,
FoldType foldType)
Find direct subfolds of the given fold having certain type. |
static Fold |
findCollapsedFold(FoldHierarchy hierarchy,
int startOffset,
int endOffset)
Find the first collapsed fold (deep-diving into the hierarchy) in the requested boundaries. |
static int |
findFoldEndIndex(Fold fold,
int offset)
Find index of the first child of the given fold that ends above the given offset ("contains" the offset). |
static int |
findFoldStartIndex(Fold fold,
int offset)
Find index of the child of the given fold that starts right at or below the given offset. |
static Fold |
findNearestFold(FoldHierarchy hierarchy,
int offset)
Find nearest fold that either starts right at or follows the given offset. |
static Fold |
findOffsetFold(FoldHierarchy hierarchy,
int offset)
Find a deepest fold in the hierarchy which contains the offset or has it as one of its boundaries. |
static List |
findRecursive(Fold fold)
Collect all children of the given fold recursively. |
static List |
findRecursive(Fold fold,
Collection foldTypes)
Recursively find any subfolds of the given fold having any of the fold types in the given collection. |
static List |
findRecursive(Fold fold,
FoldType foldType)
Recursively find any subfolds of the given fold having certain type. |
static boolean |
isEmpty(Fold fold)
Check whether the starting offset of the fold is the same like its ending offset. |
static boolean |
isRootFold(Fold fold)
Is the given fold a root fold? |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static boolean isRootFold(Fold fold)
fold
- non-null fold which is either root fold or a regular fold.
public static int findFoldStartIndex(Fold fold, int offset)
This method uses binary search and has log2(n) performance
where n is number of children of the given fold.
The efficiency may drop to linear if there would be many empty folds
at the given offset.
fold
- fold which children will be inspected.offset
- >=0 offset in the document for which the representing
child will be searched.
index
is returned
if offset >= getFold(index).getStartOffset()
and offset <= getFold(index + 1).getStartOffset()
.
-1
is returned
if offset < getFold(0).getStartOffset()
and in case the fold does not have any children.public static int findFoldEndIndex(Fold fold, int offset)
This method uses binary search and has log2(n) performance
where n is number of children of the given fold.
The efficiency may drop to linear if there would be many empty folds
at the given offset.
fold
- fold which children will be inspected.offset
- >=0 offset in the document for which the representing
child will be searched.
index
is returned for which
offset < getFold(index).getEndOffset()
fold.getFoldCount()
in case there is no such fold.public static boolean isEmpty(Fold fold)
fold
- fold that should be checked whether it's empty.
public static void collapseAll(FoldHierarchy hierarchy)
hierarchy
- hierarchy under which all folds should be collapsed.public static void collapse(FoldHierarchy hierarchy, FoldType type)
hierarchy
- hierarchy under which the folds should be collapsed.type
- folds with this type will be collapsed.public static void collapse(FoldHierarchy hierarchy, Collection foldTypes)
hierarchy
- hierarchy under which the folds should be collapsed.foldTypes
- collection of fold types to search for.public static void expandAll(FoldHierarchy hierarchy)
hierarchy
- hierarchy under which all folds should be expanded.public static void expand(FoldHierarchy hierarchy, FoldType type)
hierarchy
- hierarchy under which the folds should be expanded.type
- folds with this type will be expanded.public static void expand(FoldHierarchy hierarchy, Collection foldTypes)
hierarchy
- hierarchy under which the folds should be expanded.foldTypes
- collection of fold types to search for.public static boolean containsOffset(Fold fold, int offset)
fold
- fold to be tested for containing the given offsetoffset
- that will be tested for being contained in the given fold.
offset >= fold.getStartOffset()
&& offset < fold.getEndOffset()
public static Fold[] childrenToArray(Fold fold)
fold
- fold which children will be returned.
public static Fold[] childrenToArray(Fold fold, int index, int count)
fold
- fold which children will be returned.index
- >=0 index of the first child to be returned.count
- >=0 number of children to be returned.
index + count <= Fold.getFoldCount()
.
public static List childrenAsList(Fold fold)
findRecursive(Fold)
can be used
to collect children recursively.
fold
- fold which children will be returned.
public static List childrenAsList(Fold fold, int index, int count)
fold
- fold which children will be returned.index
- >=0 index of the first child to be returned.count
- >=0 number of children to be returned.
index + count <= Fold.getFoldCount()
.
public static List find(Fold fold, FoldType foldType)
fold
- direct children of this fold will be searched.
The search is *not* recursive in grandchildren etc.foldType
- non-null fold type to search for.
public static List find(Fold fold, Collection foldTypes)
fold
- direct children of this fold will be searched.
The search is *not* recursive in grandchildren etc.foldTypes
- collection of fold types to search for.
public static List findRecursive(Fold fold)
fold
- all children of this fold will be collected.
public static List findRecursive(Fold fold, FoldType foldType)
fold
- all children of this fold will be searched.
The search is recursive into grandchildren etc.foldType
- non-null fold type to search for.
public static List findRecursive(Fold fold, Collection foldTypes)
fold
- all children of this fold will be searched.
The search is recursive into grandchildren etc.foldTypes
- collection of fold types to search for.
public static Fold findNearestFold(FoldHierarchy hierarchy, int offset)
offset
- >=0 offset in a document.
public static Fold findOffsetFold(FoldHierarchy hierarchy, int offset)
offset
- >=0 offset in a document.
fold.getStartOffset() >= offset && offset <= fold.getEndOffset()
or null if there is no such fold (except the root fold) satisfying the condition.
public static Fold findCollapsedFold(FoldHierarchy hierarchy, int startOffset, int endOffset)
hierarchy
- hierarchy in which to search.startOffset
- >=0 only fold ending above it will be returned.endOffset
- >=0 only fold starting below it will be returned.
fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset
or null if such fold does not exist.public static Iterator collapsedFoldIterator(FoldHierarchy hierarchy, int startOffset, int endOffset)
hierarchy
- hierarchy in which to search.startOffset
- >=0 only folds ending above it will be returned.endOffset
- >=0 only folds starting before it will be returned.
fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |