public class Fold extends java.lang.Object implements java.lang.Comparable<Fold>
A Fold
has zero or more children, and Folds
thus
form a hierarchical structure, with "parent" folds containing the info about
any "child" folds they contain.
Fold regions are denoted by a starting and ending offset, but the actual
folding is done on a per-line basis, so Fold
instances provide
methods for retrieving both starting and ending offsets and lines. The
starting and ending offsets/lines are "sticky" and correctly track their
positions even as the document is modified.
构造器和说明 |
---|
Fold(int type,
RSyntaxTextArea textArea,
int startOffs) |
限定符和类型 | 方法和说明 |
---|---|
int |
compareTo(Fold otherFold)
Two folds are considered equal if they start at the same offset.
|
boolean |
containsLine(int line)
Returns whether the specified line would be hidden in this fold.
|
boolean |
containsOffset(int offs)
Returns whether the specified offset is "inside" the fold.
|
boolean |
containsOrStartsOnLine(int line)
Returns whether the given line is in the range
[getStartLine(), getEndLine()] , inclusive. |
Fold |
createChild(int type,
int startOffs)
Creates a fold that is a child of this one.
|
boolean |
equals(java.lang.Object otherFold)
Two folds are considered equal if they have the same starting offset.
|
Fold |
getChild(int index)
Returns a specific child fold.
|
int |
getChildCount()
Returns the number of child folds.
|
int |
getCollapsedLineCount()
Returns the number of collapsed lines under this fold.
|
int |
getEndLine()
Returns the end line of this fold.
|
int |
getEndOffset()
Returns the end offset of this fold.
|
int |
getFoldType()
Returns the type of fold this is.
|
boolean |
getHasChildFolds()
Returns whether this fold has any child folds.
|
Fold |
getLastChild()
Returns the last child fold.
|
int |
getLineCount()
Returns the number of lines that are hidden when this fold is
collapsed.
|
Fold |
getParent()
Returns the parent fold of this one.
|
int |
getStartLine()
Returns the starting line of this fold region.
|
int |
getStartOffset()
Returns the starting offset of this fold region.
|
int |
hashCode() |
boolean |
isCollapsed()
Returns whether this fold is collapsed.
|
boolean |
isOnSingleLine()
Returns whether this fold is entirely on a single line.
|
boolean |
removeFromParent()
Removes this fold from its parent.
|
void |
setCollapsed(boolean collapsed)
Sets whether this
Fold is collapsed. |
void |
setEndOffset(int endOffs)
Sets the ending offset of this fold, such as the closing curly brace
of a code block in C or Java.
|
void |
toggleCollapsedState()
Toggles the collapsed state of this fold.
|
java.lang.String |
toString()
Overridden for debugging purposes.
|
public Fold(int type, RSyntaxTextArea textArea, int startOffs) throws javax.swing.text.BadLocationException
javax.swing.text.BadLocationException
public Fold createChild(int type, int startOffs) throws javax.swing.text.BadLocationException
type
- The type of fold.startOffs
- The starting offset of the fold.javax.swing.text.BadLocationException
- If startOffs
is invalid.FoldType
public int compareTo(Fold otherFold)
compareTo
在接口中 java.lang.Comparable<Fold>
otherFold
- Another fold to compare this one to.public boolean containsLine(int line)
(getStartLine()+1)
and
getEndLine()
, inclusive.line
- The line to check.containsOffset(int)
,
containsOrStartsOnLine(int)
public boolean containsOrStartsOnLine(int line)
[getStartLine(), getEndLine()]
, inclusive.line
- The line to check.containsLine(int)
public boolean containsOffset(int offs)
true
if the offset is greater than the fold start
offset, and no further than the last offset of the last folded line.offs
- The offset to check.containsLine(int)
public boolean equals(java.lang.Object otherFold)
equals
在类中 java.lang.Object
otherFold
- Another fold to compare this one to.compareTo(Fold)
public Fold getChild(int index)
index
- The index of the child fold.getChildCount()
public int getChildCount()
getChild(int)
public int getCollapsedLineCount()
getLineCount()
, otherwise
it returns the sum of all collapsed lines of all child folds of this
one.The value returned is cached, so this method returns quickly and shouldn't affect performance.
public int getEndLine()
The value returned by this method will automatically update as the text area's contents are modified, to track the ending line of the code block.
getEndOffset()
,
getStartLine()
public int getEndOffset()
The value returned by this method will automatically update as the text area's contents are modified, to track the ending offset of the code block.
Integer.MAX_VALUE
if this fold region isn't closed properly. The latter causes
this fold to collapsed all lines through the end of the file.getEndLine()
,
getStartOffset()
public int getFoldType()
FoldType
, or a user-defined value.public boolean getHasChildFolds()
getChildCount()
public Fold getLastChild()
null
if this fold does not
have any children.getChild(int)
,
getHasChildFolds()
public int getLineCount()
getStartLine()
,
getEndLine()
public Fold getParent()
null
if this is a top-level
fold.public int getStartLine()
The value returned by this method will automatically update as the text area's contents are modified, to track the starting line of the code block.
getEndLine()
,
getStartOffset()
public int getStartOffset()
The value returned by this method will automatically update as the text area's contents are modified, to track the starting offset of the code block.
getStartLine()
,
getEndOffset()
public int hashCode()
hashCode
在类中 java.lang.Object
public boolean isCollapsed()
setCollapsed(boolean)
,
toggleCollapsedState()
public boolean isOnSingleLine()
FoldParser
should not remember fold regions all on a single
line, since there's really nothing to fold.removeFromParent()
public boolean removeFromParent()
FoldParser
implementations if they determine that a fold is all
on a single line (and thus shouldn't be remembered) after creating it.isOnSingleLine()
public void setCollapsed(boolean collapsed)
Fold
is collapsed. Calling this method
will update both the text area and all Gutter
components.collapsed
- Whether this fold should be collapsed.isCollapsed()
,
toggleCollapsedState()
public void setEndOffset(int endOffs) throws javax.swing.text.BadLocationException
FoldParser
implementations should
call this on an existing Fold
upon finding its end. If
this method isn't called, then this Fold
is considered to
have no end, i.e., it will collapse everything to the end of the file.endOffs
- The end offset of this fold.javax.swing.text.BadLocationException
- If endOffs
is not a valid
location in the text area.public void toggleCollapsedState()
public java.lang.String toString()
toString
在类中 java.lang.Object
Fold
.