Class DefaultFoldManager
java.lang.Object
org.fife.ui.rsyntaxtextarea.folding.DefaultFoldManager
- All Implemented Interfaces:
FoldManager
The default implementation of a fold manager. Besides keeping track of
folds, this class behaves as follows:
- If text containing a newline is inserted in a collapsed fold, that fold, and any ancestor folds, are expanded. This ensures that modified text is always visible to the user.
- If the text area's
RSyntaxTextArea.SYNTAX_STYLE_PROPERTYchanges, the current fold parser is uninstalled, and one appropriate for the new language, if any, is installed.
FoldParserManager.- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classListens for events in the text editor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate FoldParserprivate DefaultFoldManager.Listenerprivate Parserprivate PropertyChangeSupportprivate RSyntaxTextAreaFields inherited from interface org.fife.ui.rsyntaxtextarea.folding.FoldManager
PROPERTY_FOLDS_UPDATED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a property change listener to this fold manager.voidclear()Removes all folds.booleanensureOffsetNotInClosedFold(int offs) Ensures that the specified offset is not hidden in a collapsed fold.getDeepestFoldContaining(int offs) Returns the "deepest" nested fold containing the specified offset.getDeepestOpenFoldContaining(int offs) Returns the "deepest" open fold containing the specified offset.getFold(int index) Returns a specific top-level fold, which may have child folds.intReturns the number of top-level folds.getFoldForLine(int line) Returns the fold region that starts at the specified line.private FoldgetFoldForLineImpl(Fold parent, List<Fold> folds, int line) intReturns the total number of hidden (folded) lines.intgetHiddenLineCountAbove(int line) Returns the number of lines "hidden" by collapsed folds above the specified line.intgetHiddenLineCountAbove(int line, boolean physical) Returns the number of lines "hidden" by collapsed folds above the specified line.private intgetHiddenLineCountAboveImpl(Fold fold, int line, boolean physical) Returns the number of lines "hidden" by collapsed folds above the specified line.intReturns the last visible line in the text area, taking into account folds.intgetVisibleLineAbove(int line) Returns the visible line above a specified line.intgetVisibleLineBelow(int line) Returns the visible line below a specified line.booleanReturns whether code folding is enabled.booleanReturnstrueif and only if code folding is enabled for this text area, AND folding is supported for the language it is editing.booleanisFoldStartLine(int line) Returns whether the specified line contains the start of a fold region.booleanisLineHidden(int line) Returns whether a line is hidden in a collapsed fold.private booleanisLineHiddenImpl(Fold parent, int line) private voidkeepFoldState(Fold newFold, List<Fold> oldFolds) private voidkeepFoldStates(List<Fold> newFolds, List<Fold> oldFolds) voidRemoves a property change listener from this fold manager.voidreparse()Forces an immediate reparsing for folds, if folding is enabled.voidsetCodeFoldingEnabled(boolean enabled) Sets whether code folding is enabled.voidSets the folds for this fold manager.private voidUpdates the fold parser to be the one appropriate for the language currently being highlighted.
-
Field Details
-
textArea
-
rstaParser
-
foldParser
-
folds
-
codeFoldingEnabled
private boolean codeFoldingEnabled -
support
-
l
-
-
Constructor Details
-
DefaultFoldManager
Constructor.- Parameters:
textArea- The text area whose folds we are managing.
-
-
Method Details
-
addPropertyChangeListener
Description copied from interface:FoldManagerAdds a property change listener to this fold manager.- Specified by:
addPropertyChangeListenerin interfaceFoldManager- Parameters:
l- The new listener.- See Also:
-
clear
public void clear()Description copied from interface:FoldManagerRemoves all folds.- Specified by:
clearin interfaceFoldManager
-
ensureOffsetNotInClosedFold
public boolean ensureOffsetNotInClosedFold(int offs) Description copied from interface:FoldManagerEnsures that the specified offset is not hidden in a collapsed fold. Any folds containing this offset that are collapsed will be expanded.- Specified by:
ensureOffsetNotInClosedFoldin interfaceFoldManager- Parameters:
offs- The offset.- Returns:
- Whether any folds had to be opened.
- See Also:
-
getDeepestFoldContaining
Description copied from interface:FoldManagerReturns the "deepest" nested fold containing the specified offset.- Specified by:
getDeepestFoldContainingin interfaceFoldManager- Parameters:
offs- The offset.- Returns:
- The deepest fold containing the offset, or
nullif no fold contains the offset.
-
getDeepestOpenFoldContaining
Description copied from interface:FoldManagerReturns the "deepest" open fold containing the specified offset.- Specified by:
getDeepestOpenFoldContainingin interfaceFoldManager- Parameters:
offs- The offset.- Returns:
- The fold, or
nullif no open fold contains the offset.
-
getFold
Description copied from interface:FoldManagerReturns a specific top-level fold, which may have child folds.- Specified by:
getFoldin interfaceFoldManager- Parameters:
index- The index of the fold.- Returns:
- The fold.
- See Also:
-
getFoldCount
public int getFoldCount()Description copied from interface:FoldManagerReturns the number of top-level folds.- Specified by:
getFoldCountin interfaceFoldManager- Returns:
- The number of top-level folds.
- See Also:
-
getFoldForLine
Description copied from interface:FoldManagerReturns the fold region that starts at the specified line.- Specified by:
getFoldForLinein interfaceFoldManager- Parameters:
line- The line number.- Returns:
- The fold, or
nullif the line is not the start of a fold region. - See Also:
-
getFoldForLineImpl
-
getHiddenLineCount
public int getHiddenLineCount()Description copied from interface:FoldManagerReturns the total number of hidden (folded) lines.- Specified by:
getHiddenLineCountin interfaceFoldManager- Returns:
- The total number of hidden (folded) lines.
- See Also:
-
getHiddenLineCountAbove
public int getHiddenLineCountAbove(int line) Description copied from interface:FoldManagerReturns the number of lines "hidden" by collapsed folds above the specified line.- Specified by:
getHiddenLineCountAbovein interfaceFoldManager- Parameters:
line- The line. This is the line number for a logical line. For the line number of a physical line (i.e. visible, not folded), usegetHiddenLineCountAbove(int, true).- Returns:
- The number of lines hidden in folds above
line. - See Also:
-
getHiddenLineCountAbove
public int getHiddenLineCountAbove(int line, boolean physical) Description copied from interface:FoldManagerReturns the number of lines "hidden" by collapsed folds above the specified line.- Specified by:
getHiddenLineCountAbovein interfaceFoldManager- Parameters:
line- The line.physical- Whetherlineis the number of a physical line (i.e. visible, not code-folded), or a logical one (i.e. any line from the model). Iflinewas determined by a raw line calculation (i.e.(visibleTopY / lineHeight)), this value should betrue. It should befalsewhen it was calculated from an offset in the document (for example).- Returns:
- The number of lines hidden in folds above
line.
-
getHiddenLineCountAboveImpl
Returns the number of lines "hidden" by collapsed folds above the specified line.- Parameters:
fold- The current fold in the recursive algorithm. It and its children are examined.line- The line.physical- Whetherlineis the number of a physical line (i.e. visible, not code-folded), or a logical one (i.e. any line from the model). Iflinewas determined by a raw line calculation (i.e.(visibleTopY / lineHeight)), this value should betrue. It should befalsewhen it was calculated from an offset in the document (for example).- Returns:
- The number of lines hidden in folds that are descendants of
fold, orfolditself, aboveline.
-
getLastVisibleLine
public int getLastVisibleLine()Description copied from interface:FoldManagerReturns the last visible line in the text area, taking into account folds.- Specified by:
getLastVisibleLinein interfaceFoldManager- Returns:
- The last visible line.
-
getVisibleLineAbove
public int getVisibleLineAbove(int line) Description copied from interface:FoldManagerReturns the visible line above a specified line.- Specified by:
getVisibleLineAbovein interfaceFoldManager- Parameters:
line- The line to check.- Returns:
- The visible line above the specified line.
- See Also:
-
getVisibleLineBelow
public int getVisibleLineBelow(int line) Description copied from interface:FoldManagerReturns the visible line below a specified line.- Specified by:
getVisibleLineBelowin interfaceFoldManager- Parameters:
line- The line to check.- Returns:
- The visible line below the specified line.
- See Also:
-
isCodeFoldingEnabled
public boolean isCodeFoldingEnabled()Description copied from interface:FoldManagerReturns whether code folding is enabled. Note that only certain languages support code folding; those that do not will ignore this property.- Specified by:
isCodeFoldingEnabledin interfaceFoldManager- Returns:
- Whether code folding is enabled.
- See Also:
-
isCodeFoldingSupportedAndEnabled
public boolean isCodeFoldingSupportedAndEnabled()Description copied from interface:FoldManagerReturnstrueif and only if code folding is enabled for this text area, AND folding is supported for the language it is editing. Whether folding is supported for a language depends on whether a fold parser is registered for that language with theFoldParserManager.- Specified by:
isCodeFoldingSupportedAndEnabledin interfaceFoldManager- Returns:
- Whether folding is supported and enabled for this text area.
- See Also:
-
isFoldStartLine
public boolean isFoldStartLine(int line) Description copied from interface:FoldManagerReturns whether the specified line contains the start of a fold region.- Specified by:
isFoldStartLinein interfaceFoldManager- Parameters:
line- The line.- Returns:
- Whether the line contains the start of a fold region.
- See Also:
-
isLineHidden
public boolean isLineHidden(int line) Description copied from interface:FoldManagerReturns whether a line is hidden in a collapsed fold.- Specified by:
isLineHiddenin interfaceFoldManager- Parameters:
line- The line to check.- Returns:
- Whether the line is hidden in a collapsed fold.
-
isLineHiddenImpl
-
keepFoldState
-
keepFoldStates
-
removePropertyChangeListener
Description copied from interface:FoldManagerRemoves a property change listener from this fold manager.- Specified by:
removePropertyChangeListenerin interfaceFoldManager- Parameters:
l- The listener to remove.- See Also:
-
reparse
public void reparse()Description copied from interface:FoldManagerForces an immediate reparsing for folds, if folding is enabled. This usually does not need to be called by the programmer, since fold parsing is done automatically by RSTA.- Specified by:
reparsein interfaceFoldManager
-
setCodeFoldingEnabled
public void setCodeFoldingEnabled(boolean enabled) Description copied from interface:FoldManagerSets whether code folding is enabled. Note that only certain languages will support code folding out of the box. Those languages which do not support folding will ignore this property.- Specified by:
setCodeFoldingEnabledin interfaceFoldManager- Parameters:
enabled- Whether code folding should be enabled.- See Also:
-
setFolds
Description copied from interface:FoldManagerSets the folds for this fold manager.- Specified by:
setFoldsin interfaceFoldManager- Parameters:
folds- The new folds. This should not benull.
-
updateFoldParser
private void updateFoldParser()Updates the fold parser to be the one appropriate for the language currently being highlighted.
-