- All Known Subinterfaces:
UrlTocTree
- All Known Implementing Classes:
HtmlWithTocPane
,ObjTocPane
,UrlTocPane
public interface TocTree
Interface for Table of Contents.
A table of contents is a hierarchical mapping between a series
of names and and a set of objects. The hierarchy is a tree.
The method
addEntry
should be called to create the
root of a tree, followed by a call to nextLevel
to
add children to the tree. Each call to nextLevel
must be balanced by a call to prevLevel
. A call to
the method entriesCompleted
indicates that the
table of contents is complete. One may select particular rows
by calling setSelectionWithAction
, whose argument
is an index into the displayable nodes in the tree, indexed by
the order of entry. See JTree
for a definition of
displayable versus visible. A call to clearSelection
clears the current selection, and a call to clearToc()
clears the contents and puts the object in a state where a new
set of entries can be added.
The interface also supports action listeners, using the methods
addActionListener
and removeActionListener
.
The source of an action listener is an instance of the class
TocEntry
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an action listener.void
Add a new node to the tree, giving it a name.void
Clear the selection.void
clearToc()
Clear the table of contents and puts it in a state where entries can be added.void
collapseRow
(int row) Ensures that the node in the specified row is collapsed.void
Assert that no more entries will be added.void
entriesCompleted
(boolean expand) Assert that no more entries will be added.void
expandRow
(int row) Ensures that the node in the specified row is expanded and viewable.boolean
isCollapsed
(int row) Returns true if the node at the specified display row is collapsed.boolean
isExpanded
(int row) Returns true if the node at the specified display row is currently expanded.void
Add a new level to the tree rooted at the last node entered.void
Return to the previous level in the tree.void
Remove an action listener.void
setSelectionWithAction
(int row) Set the selection and perform an action.
-
Method Details
-
addActionListener
Add an action listener.- Parameters:
l
- the action listener to add.
-
removeActionListener
Remove an action listener.- Parameters:
l
- the action listener to remove.
-
clearSelection
void clearSelection()Clear the selection. This method also generates action events with the source set to an entry with a null title and a null object. -
addEntry
Add a new node to the tree, giving it a name.- Parameters:
name
- A string naming the node.obj
- The object that represents the value of the node.- Throws:
IllegalStateException
- if this method was called after a call toentriesCompleted
.- See Also:
-
nextLevel
void nextLevel()Add a new level to the tree rooted at the last node entered.- Throws:
IllegalStateException
- if this method was called after a call toentriedCompleted
.- See Also:
-
prevLevel
void prevLevel()Return to the previous level in the tree.- Throws:
IllegalStateException
- if this method was called after a call toentriesCompleted
or if it was called more times thannextLevel
- See Also:
-
entriesCompleted
void entriesCompleted()Assert that no more entries will be added. A call to this method will complete construction of the tree. It is equivalent to callingentriesCompleted(false)
.- Throws:
IllegalStateException
- if this method was already called.- See Also:
-
entriesCompleted
void entriesCompleted(boolean expand) Assert that no more entries will be added. A call to this method will complete construction of the tree.- Parameters:
expand
-true
if all nodes should be expanded before the tree is displayed; false if no nodes should be expanded- Throws:
IllegalStateException
- if this method was already called.- See Also:
-
setSelectionWithAction
void setSelectionWithAction(int row) Set the selection and perform an action. This method should be called after the call toentriesCompleted
. It sets the selected object and callsfireActionPerformed()
. Rows are indexed with 0 indicating the first visible node and with only visible nodes counted, regardless of whether these nodes are displayable. Expanding or collapsing nodes changes the indexing. Changing the portion of the pane that is shown in the display does not change the indexing. At the time this description was written, the JTree documentation was somewhat obscure regarding how this indexing works.- Parameters:
row
- the row to select.- Throws:
IllegalStateException
- if this method was called beforeentriesCompleted
.
-
collapseRow
void collapseRow(int row) Ensures that the node in the specified row is collapsed. If row is < 0 or ≥ getRowCount this will have no effect.- Parameters:
row
- an integer specifying a row, where 0 is the first viewable row.
-
expandRow
void expandRow(int row) Ensures that the node in the specified row is expanded and viewable. If row is < 0 or ≥ getRowCount this will have no effect.- Parameters:
row
- an integer specifying a display row, where 0 is the first viewable row.
-
isCollapsed
boolean isCollapsed(int row) Returns true if the node at the specified display row is collapsed.- Parameters:
row
- the row to check, where 0 is the first viewable row.- Returns:
- true if the node is currently collapsed, otherwise false
-
isExpanded
boolean isExpanded(int row) Returns true if the node at the specified display row is currently expanded.- Parameters:
row
- he row to check, where 0 is the first viewable row.- Returns:
- true if the node is currently expanded, otherwise false
-
clearToc
void clearToc()Clear the table of contents and puts it in a state where entries can be added.
-