Class Fold
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.folding.Fold
-
- All Implemented Interfaces:
Comparable<Fold>
public class Fold extends Object implements Comparable<Fold>
Information about a foldable region.A
Foldhas zero or more children, andFoldsthus 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
Foldinstances 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.
-
-
Constructor Summary
Constructors Constructor Description Fold(int type, RSyntaxTextArea textArea, int startOffs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Fold otherFold)Two folds are considered equal if they start at the same offset.booleancontainsLine(int line)Returns whether the specified line would be hidden in this fold.booleancontainsOffset(int offs)Returns whether the specified offset is "inside" the fold.booleancontainsOrStartsOnLine(int line)Returns whether the given line is in the range[getStartLine(), getEndLine()], inclusive.FoldcreateChild(int type, int startOffs)Creates a fold that is a child of this one.booleanequals(Object otherFold)Two folds are considered equal if they have the same starting offset.FoldgetChild(int index)Returns a specific child fold.intgetChildCount()Returns the number of child folds.intgetCollapsedLineCount()Returns the number of collapsed lines under this fold.intgetEndLine()Returns the end line of this fold.intgetEndOffset()Returns the end offset of this fold.intgetFoldType()Returns the type of fold this is.booleangetHasChildFolds()Returns whether this fold has any child folds.FoldgetLastChild()Returns the last child fold.intgetLineCount()Returns the number of lines that are hidden when this fold is collapsed.FoldgetParent()Returns the parent fold of this one.intgetStartLine()Returns the starting line of this fold region.intgetStartOffset()Returns the starting offset of this fold region.inthashCode()booleanisCollapsed()Returns whether this fold is collapsed.booleanisOnSingleLine()Returns whether this fold is entirely on a single line.booleanremoveFromParent()Removes this fold from its parent.voidsetCollapsed(boolean collapsed)Sets whether thisFoldis collapsed.voidsetEndOffset(int endOffs)Sets the ending offset of this fold, such as the closing curly brace of a code block in C or Java.voidtoggleCollapsedState()Toggles the collapsed state of this fold.StringtoString()Overridden for debugging purposes.
-
-
-
Constructor Detail
-
Fold
public Fold(int type, RSyntaxTextArea textArea, int startOffs) throws BadLocationException- Throws:
BadLocationException
-
-
Method Detail
-
createChild
public Fold createChild(int type, int startOffs) throws BadLocationException
Creates a fold that is a child of this one.- Parameters:
type- The type of fold.startOffs- The starting offset of the fold.- Returns:
- The child fold.
- Throws:
BadLocationException- IfstartOffsis invalid.- See Also:
FoldType
-
compareTo
public int compareTo(Fold otherFold)
Two folds are considered equal if they start at the same offset.- Specified by:
compareToin interfaceComparable<Fold>- Parameters:
otherFold- Another fold to compare this one to.- Returns:
- How this fold compares to the other.
-
containsLine
public boolean containsLine(int line)
Returns whether the specified line would be hidden in this fold. Since RSTA displays the "first" line in a fold, this means that the line must must be between(getStartLine()+1)andgetEndLine(), inclusive.- Parameters:
line- The line to check.- Returns:
- Whether the line would be hidden if this fold is collapsed.
- See Also:
containsOffset(int),containsOrStartsOnLine(int)
-
containsOrStartsOnLine
public boolean containsOrStartsOnLine(int line)
Returns whether the given line is in the range[getStartLine(), getEndLine()], inclusive.- Parameters:
line- The line to check.- Returns:
- Whether this fold contains, or starts on, the line.
- See Also:
containsLine(int)
-
containsOffset
public boolean containsOffset(int offs)
Returns whether the specified offset is "inside" the fold. This method returnstrueif the offset is greater than the fold start offset, and no further than the last offset of the last folded line.- Parameters:
offs- The offset to check.- Returns:
- Whether the offset is "inside" the fold.
- See Also:
containsLine(int)
-
equals
public boolean equals(Object otherFold)
Two folds are considered equal if they have the same starting offset.- Overrides:
equalsin classObject- Parameters:
otherFold- Another fold to compare this one to.- Returns:
- Whether the two folds are equal.
- See Also:
compareTo(Fold)
-
getChild
public Fold getChild(int index)
Returns a specific child fold.- Parameters:
index- The index of the child fold.- Returns:
- The child fold.
- See Also:
getChildCount()
-
getChildCount
public int getChildCount()
Returns the number of child folds.- Returns:
- The number of child folds.
- See Also:
getChild(int)
-
getCollapsedLineCount
public int getCollapsedLineCount()
Returns the number of collapsed lines under this fold. If this fold is collapsed, this method returnsgetLineCount(), 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.
- Returns:
- The number of collapsed lines under this fold.
-
getEndLine
public int getEndLine()
Returns the end line of this fold. For example, in languages such as C and Java, this might be the line containing the closing curly brace of a code block.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.
- Returns:
- The end line of this code block.
- See Also:
getEndOffset(),getStartLine()
-
getEndOffset
public int getEndOffset()
Returns the end offset of this fold. For example, in languages such as C and Java, this might be the offset of the closing curly brace of a code block.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.
- Returns:
- The end offset of this code block, or
Integer.MAX_VALUEif this fold region isn't closed properly. The latter causes this fold to collapsed all lines through the end of the file. - See Also:
getEndLine(),getStartOffset()
-
getFoldType
public int getFoldType()
Returns the type of fold this is. This will be one of the values inFoldType, or a user-defined value.- Returns:
- The type of fold this is.
-
getHasChildFolds
public boolean getHasChildFolds()
Returns whether this fold has any child folds.- Returns:
- Whether this fold has any children.
- See Also:
getChildCount()
-
getLastChild
public Fold getLastChild()
Returns the last child fold.- Returns:
- The last child fold, or
nullif this fold does not have any children. - See Also:
getChild(int),getHasChildFolds()
-
getLineCount
public int getLineCount()
Returns the number of lines that are hidden when this fold is collapsed.- Returns:
- The number of lines hidden.
- See Also:
getStartLine(),getEndLine()
-
getParent
public Fold getParent()
Returns the parent fold of this one.- Returns:
- The parent fold, or
nullif this is a top-level fold.
-
getStartLine
public int getStartLine()
Returns the starting line of this fold region. This is the only line in the fold region that is not hidden when a fold is collapsed.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.
- Returns:
- The starting line of the code block.
- See Also:
getEndLine(),getStartOffset()
-
getStartOffset
public int getStartOffset()
Returns the starting offset of this fold region. For example, for languages such as C and Java, this would be the offset of the opening curly brace of a code block.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.
- Returns:
- The start offset of this fold.
- See Also:
getStartLine(),getEndOffset()
-
isCollapsed
public boolean isCollapsed()
Returns whether this fold is collapsed.- Returns:
- Whether this fold is collapsed.
- See Also:
setCollapsed(boolean),toggleCollapsedState()
-
isOnSingleLine
public boolean isOnSingleLine()
Returns whether this fold is entirely on a single line. In general, aFoldParsershould not remember fold regions all on a single line, since there's really nothing to fold.- Returns:
- Whether this fold is on a single line.
- See Also:
removeFromParent()
-
removeFromParent
public boolean removeFromParent()
Removes this fold from its parent. This should only be called byFoldParserimplementations if they determine that a fold is all on a single line (and thus shouldn't be remembered) after creating it.- Returns:
- Whether this fold had a parent to be removed from.
- See Also:
isOnSingleLine()
-
setCollapsed
public void setCollapsed(boolean collapsed)
Sets whether thisFoldis collapsed. Calling this method will update both the text area and allGuttercomponents.- Parameters:
collapsed- Whether this fold should be collapsed.- See Also:
isCollapsed(),toggleCollapsedState()
-
setEndOffset
public void setEndOffset(int endOffs) throws BadLocationExceptionSets the ending offset of this fold, such as the closing curly brace of a code block in C or Java.FoldParserimplementations should call this on an existingFoldupon finding its end. If this method isn't called, then thisFoldis considered to have no end, i.e., it will collapse everything to the end of the file.- Parameters:
endOffs- The end offset of this fold.- Throws:
BadLocationException- IfendOffsis not a valid location in the text area.
-
toggleCollapsedState
public void toggleCollapsedState()
Toggles the collapsed state of this fold.- See Also:
setCollapsed(boolean)
-
-