Class DefaultFoldManager
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.folding.DefaultFoldManager
-
- All Implemented Interfaces:
FoldManager
public class DefaultFoldManager extends java.lang.Object implements 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 Classes Modifier and Type Class Description private classDefaultFoldManager.ListenerListens for events in the text editor.
-
Field Summary
Fields Modifier and Type Field Description private booleancodeFoldingEnabledprivate FoldParserfoldParserprivate java.util.List<Fold>foldsprivate DefaultFoldManager.Listenerlprivate ParserrstaParserprivate java.beans.PropertyChangeSupportsupportprivate RSyntaxTextAreatextArea-
Fields inherited from interface org.fife.ui.rsyntaxtextarea.folding.FoldManager
PROPERTY_FOLDS_UPDATED
-
-
Constructor Summary
Constructors Constructor Description DefaultFoldManager(RSyntaxTextArea textArea)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)Adds 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.FoldgetDeepestFoldContaining(int offs)Returns the "deepest" nested fold containing the specified offset.FoldgetDeepestOpenFoldContaining(int offs)Returns the "deepest" open fold containing the specified offset.FoldgetFold(int index)Returns a specific top-level fold, which may have child folds.intgetFoldCount()Returns the number of top-level folds.FoldgetFoldForLine(int line)Returns the fold region that starts at the specified line.private FoldgetFoldForLineImpl(Fold parent, java.util.List<Fold> folds, int line)intgetHiddenLineCount()Returns 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.intgetLastVisibleLine()Returns 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.booleanisCodeFoldingEnabled()Returns whether code folding is enabled.booleanisCodeFoldingSupportedAndEnabled()Returnstrueif 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, java.util.List<Fold> oldFolds)private voidkeepFoldStates(java.util.List<Fold> newFolds, java.util.List<Fold> oldFolds)voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)Removes 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.voidsetFolds(java.util.List<Fold> folds)Sets the folds for this fold manager.private voidupdateFoldParser()Updates the fold parser to be the one appropriate for the language currently being highlighted.
-
-
-
Field Detail
-
textArea
private RSyntaxTextArea textArea
-
rstaParser
private Parser rstaParser
-
foldParser
private FoldParser foldParser
-
folds
private java.util.List<Fold> folds
-
codeFoldingEnabled
private boolean codeFoldingEnabled
-
support
private java.beans.PropertyChangeSupport support
-
l
private DefaultFoldManager.Listener l
-
-
Constructor Detail
-
DefaultFoldManager
public DefaultFoldManager(RSyntaxTextArea textArea)
Constructor.- Parameters:
textArea- The text area whose folds we are managing.
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Description copied from interface:FoldManagerAdds a property change listener to this fold manager.- Specified by:
addPropertyChangeListenerin interfaceFoldManager- Parameters:
l- The new listener.- See Also:
FoldManager.removePropertyChangeListener(PropertyChangeListener)
-
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:
FoldManager.getDeepestFoldContaining(int)
-
getDeepestFoldContaining
public Fold getDeepestFoldContaining(int offs)
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
public Fold getDeepestOpenFoldContaining(int offs)
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
public Fold getFold(int index)
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:
FoldManager.getFoldCount()
-
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:
FoldManager.getFold(int)
-
getFoldForLine
public Fold getFoldForLine(int line)
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:
FoldManager.isFoldStartLine(int)
-
getFoldForLineImpl
private Fold getFoldForLineImpl(Fold parent, java.util.List<Fold> folds, int line)
-
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:
FoldManager.getHiddenLineCountAbove(int)
-
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:
FoldManager.getHiddenLineCountAbove(int, boolean)
-
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
private int getHiddenLineCountAboveImpl(Fold fold, int line, boolean physical)
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:
FoldManager.getVisibleLineBelow(int)
-
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:
FoldManager.getVisibleLineAbove(int)
-
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:
FoldManager.setCodeFoldingEnabled(boolean)
-
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:
FoldParserManager
-
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:
FoldManager.getFoldForLine(int)
-
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
private boolean isLineHiddenImpl(Fold parent, int line)
-
keepFoldStates
private void keepFoldStates(java.util.List<Fold> newFolds, java.util.List<Fold> oldFolds)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
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:
FoldManager.addPropertyChangeListener(PropertyChangeListener)
-
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:
FoldManager.isCodeFoldingEnabled()
-
setFolds
public void setFolds(java.util.List<Fold> folds)
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.
-
-