public class Navigable extends MetaTraversable
Navigable
class represents a
single tree node. Clicking on that tree node brings up the
UI corresponding to the associated Traversable
.
A Navigable
instance is responsible for building
part of the tree structure through its createTreeNode(NavigableContext)
method. This allows a
particular Navigable
implementation to provide for more
complex ways of determining the structure of its subtree.
Subclasses with additional member fields will also need to override
the copyTo(Object)
and copyToImpl(Navigable)
methods in order to maintain correct copying behavior. Without
the right copying behavior, a Navigable
subclass will
not cooperate properly with a NavigableRegistry
.
Modifier and Type | Class and Description |
---|---|
static class |
Navigable.NavigableComparator
Comparator implementation used for sorting child Navigable instances by label. |
Modifier and Type | Field and Description |
---|---|
static int |
BOLD |
static java.lang.String |
DEFAULT_CHILD_COMPARATOR_KEY
The key to use for looking up the default
Comparator in a
NavigableContext ; the Comparator is used for
sorting Navigable children during a call to createTreeNode(NavigableContext) . |
static int |
ITALIC |
static java.util.Comparator |
NAVIGABLE_COMPARATOR
A standard
Comparator that sorts Navigable instances
by the short label. |
static int |
PLAIN |
Modifier | Constructor and Description |
---|---|
protected |
Navigable()
Should only be used by
copyTo(Object) . |
protected |
Navigable(java.lang.String shortLabel)
Creates a new
Navigable with the specified
label. |
|
Navigable(java.lang.String shortLabel,
java.lang.Class traversableClass)
Creates a new
Navigable with the specified
label and Traversable class. |
|
Navigable(java.lang.String shortLabel,
java.lang.Class traversableClass,
java.lang.Class[] constructorArgTypes,
java.lang.Object[] constructorArgs,
Navigable[] childNavigables) |
|
Navigable(java.lang.String shortLabel,
java.lang.Class traversableClass,
Navigable[] childNavigables)
|
Modifier and Type | Method and Description |
---|---|
void |
addChildNavigable(Navigable childNavigable)
Adds a new
Navigable to the array of child
Navigables. |
protected void |
appendChildNavigables(javax.swing.tree.DefaultMutableTreeNode parent,
NavigableContext nc)
This method calls
getChildNavigables() to get the list of
child Navigable objects. |
protected void |
appendChildNodes(javax.swing.tree.DefaultMutableTreeNode parent,
Navigable[] children,
NavigableContext nc)
This method invokes
createTreeNode(NavigableContext) on each
Navigable specified in children and adds
the resulting DefaultMutableTreeNode (if it is not
null ) to the parent . |
protected void |
appendDetailNavigables(javax.swing.tree.DefaultMutableTreeNode parent,
NavigableContext nc)
This method calls
getDetailNavigables() to get the list
of detail Navigable objects. |
java.lang.Object |
copyTo(java.lang.Object target)
Subclasses must override this method if new member fields are
introduced.
|
protected void |
copyToImpl(Navigable copy)
Subclasses must implement an appropriate variant of this method
if new member fields are introduced.
|
javax.swing.tree.DefaultMutableTreeNode |
createDetailRootNode(NavigableContext nc)
When the
Navigable is used to show detail nodes in a
separate tree, this method is used to construct the detail tree,
using the returned tree node as the root of the detail tree; in
general, only NavigableUIContainer implementations should
call this method directly. |
javax.swing.tree.DefaultMutableTreeNode |
createTreeNode(NavigableContext nc)
This method constructs a
DefaultMutableTreeNode that is
to represent the Navigable in the tree; in general,
only NavigableUIContainer implementations should call this
method directly. |
protected javax.swing.tree.DefaultMutableTreeNode |
createTreeNodeImpl(NavigableContext nc)
This method is the essential method in which a tree node that
represents a
Navigable is created. |
protected java.util.Comparator |
getChildComparator()
Fetch the comparator to use for sorting the child navigables.
|
protected Navigable[] |
getChildNavigables()
By default, this returns the child
Navigable s that were
set when this DefaultNavigable was constructed. |
Navigable[] |
getChildren() |
protected Navigable[] |
getDetailNavigables()
Returns
null by default. |
int |
getDisplayStyle() |
javax.swing.Icon |
getIcon()
This implementation always returns
null . |
java.lang.String |
getLongLabel()
This implementation simply invokes
return getShortLabel() . |
java.lang.String |
getRawShortLabel()
This method returns the entire short label string, including any occurrance
of the mnemonic character, &.
|
java.lang.String |
getShortLabel()
This implementation returns the short label that was specified when
this
Navigable was created. |
java.lang.String |
getToolTipText()
This implementation always returns
null . |
boolean |
includeInDefault() |
protected boolean |
mayHaveChildren(NavigableContext nc)
Overridable method to determine whether a
Navigable may have
children such that a + may be shown next to it in the tree. |
void |
setChildComparator(java.util.Comparator customComparator)
Sets whether the child navigables are sorted or not.
|
protected void |
setChildNavigables(Navigable[] childNavigables)
Accessor for the private data member that stores the
current child
Navigable s. |
protected void |
setDataScope(Namespace dataScope)
Sets the specified
Namespace as the data scope for this
Navigable . |
void |
setDisplayStyle(int displayStyle) |
void |
setShortLabel(java.lang.String shortLabel) |
protected static Navigable[] |
sortNavigables(Navigable[] navigables,
java.util.Comparator comparator)
Sorts the specified
Navigable array using the specified
Comparator , and returns a sorted version of the array. |
java.lang.String |
toString() |
copyToImpl, findHelpID, getTraversableClass, isUsingTraversableDefaultConstructor, newTraversable, newTraversable, setHelpID, setNameLink
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
public static final java.lang.String DEFAULT_CHILD_COMPARATOR_KEY
Comparator
in a
NavigableContext
; the Comparator
is used for
sorting Navigable
children during a call to createTreeNode(NavigableContext)
.public static final java.util.Comparator NAVIGABLE_COMPARATOR
Comparator
that sorts Navigable
instances
by the short label.protected Navigable(java.lang.String shortLabel)
Navigable
with the specified
label. There is no associated Traversable
class, and the
Navigable
has no children. In general, this
constructor will be called by a subclass that overrides MetaTraversable.newTraversable(ApplyNotifier)
, getChildNavigables()
, and/or getDetailNavigables()
.shortLabel
- The short label to display when rendering the
UI for the Navigable
.public Navigable(java.lang.String shortLabel, java.lang.Class traversableClass)
Navigable
with the specified
label and Traversable
class. The Navigable
has no children unless a subclass implementation provides them.shortLabel
- The short label to display when rendering the
UI for the Navigable
.traversableClass
- The Class
of the Traversable
associated with this Navigable
. Since
many usages of Navigable
do not require any
parameters when instantiating the Traversable
, this is
provided as a convenience. Note that if the Traversable
class implements the ApplyListener
interface, instances will
be added as an ApplyListener to the ApplyNotifier
linked
to the NavigableUIContainer
.#newTraversable(ApplyNotifier)}.
public Navigable(java.lang.String shortLabel, java.lang.Class traversableClass, Navigable[] childNavigables)
shortLabel
- The short label to display when rendering the
UI for the Navigable
.traversableClass
- The Class
of the Traversable
associated with this Navigable
. Since
many usages of Navigable
do not require any
parameters when instantiating the Traversable
, this is
provided as a convenience. See MetaTraversable.newTraversable(ApplyNotifier)
.childNavigables
- An array of the children of this
Navigable
. This parameter may be null
if there are no children.public Navigable(java.lang.String shortLabel, java.lang.Class traversableClass, java.lang.Class[] constructorArgTypes, java.lang.Object[] constructorArgs, Navigable[] childNavigables)
protected Navigable()
copyTo(Object)
.public java.lang.Object copyTo(java.lang.Object target)
Copyable
for
details.copyTo
in interface Copyable
copyTo
in class MetaTraversable
target
- The target object to which the state of
this
object should be copied. If target
is null
, then the copyTo
method will
return a new instance of this
class.this
object was copied. If the target
was
non-null
, then the return value is the same as the
target
object that was passed in; otherwise, the
return value is a new instance of this
class.Copyable.copyTo(Object)
protected final void copyToImpl(Navigable copy)
protected final void copyToImpl( copy );
Then, the subclass implementation must first delegate to this
method with a call to:
super.copyToImpl( copy );
This ensures that the copyTo(Object)
method instantiates
the correct class when the target is null
and also
provides an extendable way of implementing copying behavior.copy
- The Navigable
to which this
Navigable
's state should be copied.public java.lang.String getShortLabel()
Navigable
was created. If the mnemonic character
& was present in the short label, this implementation will strip
that character out of the returned string.public java.lang.String getRawShortLabel()
public java.lang.String getLongLabel()
return getShortLabel()
.public javax.swing.Icon getIcon()
null
.public java.lang.String getToolTipText()
null
.public java.lang.String toString()
toString
in class java.lang.Object
public int getDisplayStyle()
public void setDisplayStyle(int displayStyle)
public void setShortLabel(java.lang.String shortLabel)
public void setChildComparator(java.util.Comparator customComparator)
Navigable
instance.customComparator
- comparator to use for sorting, null to
disable sortingprotected java.util.Comparator getChildComparator()
public Navigable[] getChildren()
public javax.swing.tree.DefaultMutableTreeNode createTreeNode(NavigableContext nc)
DefaultMutableTreeNode
that is
to represent the Navigable
in the tree; in general,
only NavigableUIContainer
implementations should call this
method directly. Subclasses may, of course, override the
behavior.
The user object of the returned tree node (and all its descendant
nodes) must be an instance of Navigable
.
If the return value is null
, the
Navigable
is omitted from the tree.
Note: this method returns DefaultMutableTreeNode instead of just MutableTreeNode because the getUserObject(...) method is not specified by MutableTreeNode.
nc
- The NavigableContext
in which this
Navigable
should render the tree node.Navigable
.public javax.swing.tree.DefaultMutableTreeNode createDetailRootNode(NavigableContext nc)
Navigable
is used to show detail nodes in a
separate tree, this method is used to construct the detail tree,
using the returned tree node as the root of the detail tree; in
general, only NavigableUIContainer
implementations should
call this method directly. Subclasses may, of course, override
the behavior.
The root is not actually displayed in the detail tree, so the
user object associated with the root is not important. However,
all descendants of the returned root must also be instances of
DefaultMutableTreeNode
whose user objects are instances
of Navigable
.
It is important that this method return a non-null
value, even if there are no detail root nodes.
nc
- The NavigableContext
in which this
Navigable
should render the tree node.Navigable
has no detail nodes, then
this method must return an empty tree node.public void addChildNavigable(Navigable childNavigable)
Navigable
to the array of child
Navigables.The
- child Navigable
to add.public boolean includeInDefault()
protected void setDataScope(Namespace dataScope)
Namespace
as the data scope for this
Navigable
. This method must be called at some point
before a Navigable
is used in a UI container.
This is a transient property, so it will not be copied in the
copyTo(Object)
or copyToImpl(Navigable)
method.
dataScope
- The Namespace
that represents the data
scope for this Navigable
.protected Navigable[] getChildNavigables()
Navigable
s that were
set when this DefaultNavigable
was constructed.
Subclasses can override this method to specify a custom list of
children. The result of this method is used by
appendChildNavigables(...)
to append
child nodes.Navigable
s of this
Navigable
.protected void setChildNavigables(Navigable[] childNavigables)
Navigable
s.The
- child Navigable
s to associate with this
Navigable
.protected Navigable[] getDetailNavigables()
null
by default. Subclasses should override
this method in order to specify a list of detail Navigable
s. The result of this method is used by appendDetailNavigables(DefaultMutableTreeNode,
NavigableContext)
to append detail nodes.Navigables
representing the
detail for this Navigable
. Detail nodes are
uncommonly used, so in order to specify detail nodes, a subclass
must override this method's implementation in order to provide
a return value other than null
.protected javax.swing.tree.DefaultMutableTreeNode createTreeNodeImpl(NavigableContext nc)
Navigable
is created. It is called from
createTreeNode(NavigableContext)
. This
implementation has been separated to express a specific step in
the Template Method design pattern for creating a
Navigable
tree node.nc
- The NavigableContext
in which this
Navigable
should render the tree node.Navigable
has no detail nodes, then
this method must return an empty tree node.protected void appendChildNavigables(javax.swing.tree.DefaultMutableTreeNode parent, NavigableContext nc)
getChildNavigables()
to get the list of
child Navigable
objects. Then this method calls
appendChildNodes
to append the child
Navigable
s to the specified parent.parent
- The node to which the child nodes will be added.nc
- The NavigableContext
in which this
Navigable
should render the child tree nodes.protected void appendChildNodes(javax.swing.tree.DefaultMutableTreeNode parent, Navigable[] children, NavigableContext nc)
createTreeNode(NavigableContext)
on each
Navigable
specified in children
and adds
the resulting DefaultMutableTreeNode
(if it is not
null
) to the parent
.parent
- The node to which the child nodes will be added.children
- The child Navigable
s whose
DefaultMutableTreeNode
representations are to be added to
the parent
.nc
- The NavigableContext
in which this
Navigable
should render its tree nodes.protected void appendDetailNavigables(javax.swing.tree.DefaultMutableTreeNode parent, NavigableContext nc)
getDetailNavigables()
to get the list
of detail Navigable
objects. Then this method calls
appendChildNodes
to append the detail
Navigable
s to the specified parent
.parent
- The node to which the detail nodes will be added.nc
- The NavigableContext
in which this
Navigable
should render its tree nodes.protected static Navigable[] sortNavigables(Navigable[] navigables, java.util.Comparator comparator)
Navigable
array using the specified
Comparator
, and returns a sorted version of the array. The
input array is never modified; if the array might need sorting, a
copy of the array is sorted and returned instead.protected boolean mayHaveChildren(NavigableContext nc)
Navigable
may have
children such that a + may be shown next to it in the tree.
Implementations can override this when the result is known a priori and a
call to getChildNavigables()
could be expensive. The test
should include detail Navigable
instances as well if the
NavigableContext
specifies that detail nodes should be shown
as childrennc
- The NavigableContext
used to determine the
context of the check