Class AbstractSourceTree

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
JavaOutlineTree, JavaScriptOutlineTree, XmlOutlineTree

public abstract class AbstractSourceTree extends JTree
A tree showing the structure of a source file being edited in an RSyntaxTextArea. This can be used to display an "outline view" of the code, for example.

Concrete implementations typically specialize in displaying code structure for a single language, and are registered to listen to code changes in an RSyntaxTextArea instance by calling listenTo(RSyntaxTextArea). They should then listen to document changes and adjust themselves to reflect the code structure of the current content as best as possible.

You should only add instances of SourceTreeNode or subclasses to this tree. You should also provide a no-argument constructor if you wish to use your subclass in GoToMemberAction.

Version:
1.0
See Also:
  • Field Details

    • textArea

      protected org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea
    • sorted

      private boolean sorted
    • pattern

      private Pattern pattern
    • gotoSelectedElementOnClick

      private boolean gotoSelectedElementOnClick
    • showMajorElementsOnly

      private boolean showMajorElementsOnly
  • Constructor Details

    • AbstractSourceTree

      public AbstractSourceTree()
  • Method Details

    • expandInitialNodes

      public abstract void expandInitialNodes()
      Expands all nodes in the specified tree. Subclasses should implement this in a way logical for the language.
    • fastExpandAll

      protected boolean fastExpandAll(TreePath parent, boolean expand)
      An attempt to quickly expand all tree nodes. Only need to expand the "deepest" nodes, as they will auto-expand all parents to make sure they are visible.
      Returns:
      Whether an expandPath was called for the last node in the parent path
    • fastExpandAllImpl

      private boolean fastExpandAllImpl(TreePath parent, boolean expand)
    • filter

      public void filter(String pattern)
      Filters visible tree nodes based on the specified prefix.
      Parameters:
      pattern - The prefix, as a wildcard expression. If this is null, all possible children are shown.
    • getGotoSelectedElementOnClick

      public boolean getGotoSelectedElementOnClick()
      Returns whether, when a source element is selected in this tree, the same source element should be selected in the editor.
      Returns:
      Whether to highlight the source element in the editor.
      See Also:
    • getShowMajorElementsOnly

      public boolean getShowMajorElementsOnly()
      Returns whether only "major" structural elements are shown in this source tree. An example of a "minor" element could be a local variable in a function or method.
      Returns:
      Whether only major elements are shown in this source tree.
      See Also:
    • gotoSelectedElement

      public abstract boolean gotoSelectedElement()
      Highlights the selected source element in the text editor, if any.
      Returns:
      Whether anything was selected in the tree.
    • isSorted

      public boolean isSorted()
      Returns whether the contents of this tree are sorted.
      Returns:
      Whether the contents of this tree are sorted.
      See Also:
    • listenTo

      public abstract void listenTo(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
      Causes this outline tree to reflect the source code in the specified text area.
      Parameters:
      textArea - The text area. This should have been registered with the LanguageSupportFactory, and be editing the language we're interested in.
      See Also:
    • refresh

      public void refresh()
      Refreshes what children are visible in the tree. This should be called manually when updating a source tree with a new root, and is also called internally on filtering and sorting.
    • selectFirstNodeMatchingFilter

      public void selectFirstNodeMatchingFilter()
      Selects the first visible tree node matching the filter text.
    • selectNextVisibleRow

      public void selectNextVisibleRow()
      Selects the next visible row.
      See Also:
    • selectPreviousVisibleRow

      public void selectPreviousVisibleRow()
      Selects the previous visible row.
      See Also:
    • setGotoSelectedElementOnClick

      public void setGotoSelectedElementOnClick(boolean gotoSelectedElement)
      Sets whether, when a source element is selected in this tree, the same source element should be selected in the editor.
      Parameters:
      gotoSelectedElement - Whether to highlight the source element in the editor.
      See Also:
    • setShowMajorElementsOnly

      public void setShowMajorElementsOnly(boolean show)
      Toggles whether only "major" structural elements should be shown in this source tree. An example of a "minor" element could be a local variable in a function or method.
      Parameters:
      show - Whether only major elements are shown in this source tree.
      See Also:
    • setSorted

      public void setSorted(boolean sorted)
      Toggles whether the contents of this tree are sorted.
      Parameters:
      sorted - Whether the contents of this tree are sorted.
      See Also:
    • uninstall

      public abstract void uninstall()
      Makes this outline tree stop listening to its current text area.
      See Also: