org.uispec4j
Class Tree

java.lang.Object
  extended by org.uispec4j.AbstractUIComponent
      extended by org.uispec4j.AbstractSwingUIComponent
          extended by org.uispec4j.Tree
All Implemented Interfaces:
TooltipComponent, UIComponent

public class Tree
extends AbstractSwingUIComponent

Wrapper for JTree components.

The nodes of a tree are identified using stringified paths. For instance, for the tree below:


 root
   |
   +- child
   |  |
   |  +- subChild
   |
   +- otherChild
      |
      +- otherSubChild
 
the "subChild" element is identified with the following path:

   child/subChild
 
Note that when defining paths the root element name is always omitted. The root node path itself is denoted by an empty string ("").

The default path separator is "/". However, this separator can be customized as follows:

When using paths, it is also possible to use substrings from the displayed node names. For instance, instead of writing:

   otherChild/otherSubChild
 
one can write:

   other/sub
 

The contents of the tree can be checked with contentEquals(String), which is used as follows:


 assertTrue(jTree.contentEquals("root\n" +
                                "  child1\n" +
                                "    child1_1\n" +
                                "  child2"));
 

The conversion between the values (Strings) given in the tests and the values actually displayed by the JTree renderer is performed by a dedicated TreeCellValueConverter, which retrieves the graphical component that draws the tree nodes and determines the displayed value accordingly. A DefaultTreeCellValueConverter is used by default by the Tree component.


Field Summary
static java.lang.Class[] SWING_CLASSES
           
static java.lang.String TYPE_NAME
           
 
Constructor Summary
Tree(javax.swing.JTree jTree)
           
 
Method Summary
 void addToSelection(java.lang.String path)
          Expands the current jTree selection with a given node.
 void addToSelection(java.lang.String parentPath, int childIndex)
          Expands the current jTree selection with a node identified by its position in its parent node.
 void clearSelection()
          Removes the current selection.
 void click(java.lang.String path)
          Simulates a user left-click on a given node.
 Assertion contains(java.lang.String path)
          Checks that a node identified by the given path is present in the jTree.
 Assertion contentEquals(java.lang.String expectedContents)
          Checks the nodes structure displayed by the jTree.
 void doubleClick(java.lang.String path)
           
 void expand(java.lang.String path, boolean expand)
          Expands or collapses a given node.
 void expandAll()
          Expands all the nodes of the jTree.
 Assertion foregroundEquals(java.lang.String path, java.lang.String color)
          Checks the font color used on a given node.
 javax.swing.JTree getAwtComponent()
          Returns the Java GUI component represented by this object.
 int getChildCount(java.lang.String path)
          Returns the number of children of a given node.
 java.lang.String getDescriptionTypeName()
          Returns the name of the component as it will appear in the XML representation returned by UIComponent.getDescription().
 javax.swing.JTree getJTree()
          Returns the JTree wrapped by this component.
 java.lang.String getSeparator()
          Returns the separator currently used for specifying node paths in this jTree instance.
 Assertion pathIsExpanded(java.lang.String path)
          Checks that the a given node of the jTree is expanded - i.e.
 void removeFromSelection(java.lang.String path)
          Removes the given node from the current jTree selection.
 void rightClick(java.lang.String path)
          Simulates a user right-click on a given node.
 void rightClickInSelection()
          Right-clicks on the first selected node.
 void select(java.lang.String path)
          Sets the selection on the given node.
 void select(java.lang.String[] paths)
           
 void select(java.lang.String parentPath, int childIndex)
          Sets the jTree selection on a node identified by its position in its parent node.
 void select(java.lang.String parentPath, java.lang.String childSubstring)
          Selects under a given parent all the nodes whose name contains a given substring.
 Assertion selectionEquals(java.lang.String path)
          Checks that a given node is selected, and that is is the only selection.
 Assertion selectionEquals(java.lang.String[] paths)
          Checks the selection contents.
 Assertion selectionIsEmpty()
          Checks that the selection is empty.
 void selectRoot()
          Selects the root node of the jTree.
 void setCellValueConverter(TreeCellValueConverter converter)
          Sets a new converter for retrieving the text displayed on the tree cells.
static void setDefaultSeparator(java.lang.String separator)
          Sets the separator to be used for specifying node paths in new jTree instances.
 void setSeparator(java.lang.String separator)
          Sets the separator to be used for specifying node paths in this jTree instance.
 java.lang.String toString()
           
 Trigger triggerClick(java.lang.String path)
           
 Trigger triggerDoubleClick(java.lang.String path)
           
 Trigger triggerRightClick(java.lang.String path)
           
 Trigger triggerRightClickInSelection()
           
 
Methods inherited from class org.uispec4j.AbstractSwingUIComponent
tooltipContains, tooltipEquals
 
Methods inherited from class org.uispec4j.AbstractUIComponent
addAttributes, backgroundEquals, backgroundNear, foregroundEquals, foregroundNear, getContainer, getContainer, getDescription, getDescription, getLabel, getName, getSubDescription, isEnabled, isVisible, pressKey, releaseKey, typeKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_NAME

public static final java.lang.String TYPE_NAME
See Also:
Constant Field Values

SWING_CLASSES

public static final java.lang.Class[] SWING_CLASSES
Constructor Detail

Tree

public Tree(javax.swing.JTree jTree)
Method Detail

getDescriptionTypeName

public java.lang.String getDescriptionTypeName()
Description copied from interface: UIComponent
Returns the name of the component as it will appear in the XML representation returned by UIComponent.getDescription().


getAwtComponent

public javax.swing.JTree getAwtComponent()
Description copied from interface: UIComponent
Returns the Java GUI component represented by this object.

Specified by:
getAwtComponent in interface UIComponent
Specified by:
getAwtComponent in class AbstractSwingUIComponent

getJTree

public javax.swing.JTree getJTree()
Returns the JTree wrapped by this component.


setSeparator

public void setSeparator(java.lang.String separator)
Sets the separator to be used for specifying node paths in this jTree instance.


getSeparator

public java.lang.String getSeparator()
Returns the separator currently used for specifying node paths in this jTree instance.


setDefaultSeparator

public static void setDefaultSeparator(java.lang.String separator)
Sets the separator to be used for specifying node paths in new jTree instances.


setCellValueConverter

public void setCellValueConverter(TreeCellValueConverter converter)
Sets a new converter for retrieving the text displayed on the tree cells.


contentEquals

public Assertion contentEquals(java.lang.String expectedContents)
Checks the nodes structure displayed by the jTree.

The expected contents is a newline (\n) separated string where nodes are indented with two-space steps. For instance:

 assertTrue(jTree.contentEquals("root\n" +
                                "  child1\n" +
                                "    child1_1\n" +
                                "  child2"));
 
Text display properties such as boldness and color can be checked using a "#(...)" specifier. For instance:
 assertTrue(jTree.contentEquals("root\n" +
                                "  child1 #(bold)\n" +
                                "    child1_1 #(bold,color=red)\n" +
                                "  child2"));
 
The properties are defined as follows:


contains

public Assertion contains(java.lang.String path)
Checks that a node identified by the given path is present in the jTree.


selectRoot

public void selectRoot()
Selects the root node of the jTree.


addToSelection

public void addToSelection(java.lang.String path)
Expands the current jTree selection with a given node.


removeFromSelection

public void removeFromSelection(java.lang.String path)
Removes the given node from the current jTree selection.


addToSelection

public void addToSelection(java.lang.String parentPath,
                           int childIndex)
Expands the current jTree selection with a node identified by its position in its parent node.

This method is preferred over addToSelection(String) when there are several nodes with the same name under a given parent.


clearSelection

public void clearSelection()
Removes the current selection.


select

public void select(java.lang.String path)
Sets the selection on the given node.


select

public void select(java.lang.String parentPath,
                   int childIndex)
Sets the jTree selection on a node identified by its position in its parent node.

This method is preferred over select(String) when there are several nodes with the same name under a given parent.


select

public void select(java.lang.String parentPath,
                   java.lang.String childSubstring)
Selects under a given parent all the nodes whose name contains a given substring. This method will throw an exception if no the parent path was invalid or if no children were found.


select

public void select(java.lang.String[] paths)

click

public void click(java.lang.String path)
Simulates a user left-click on a given node.


rightClick

public void rightClick(java.lang.String path)
Simulates a user right-click on a given node.


doubleClick

public void doubleClick(java.lang.String path)

rightClickInSelection

public void rightClickInSelection()
Right-clicks on the first selected node.


triggerClick

public Trigger triggerClick(java.lang.String path)

triggerRightClick

public Trigger triggerRightClick(java.lang.String path)

triggerRightClickInSelection

public Trigger triggerRightClickInSelection()

triggerDoubleClick

public Trigger triggerDoubleClick(java.lang.String path)

getChildCount

public int getChildCount(java.lang.String path)
Returns the number of children of a given node.


selectionEquals

public Assertion selectionEquals(java.lang.String path)
Checks that a given node is selected, and that is is the only selection.


selectionEquals

public Assertion selectionEquals(java.lang.String[] paths)
Checks the selection contents.


selectionIsEmpty

public Assertion selectionIsEmpty()
Checks that the selection is empty.


foregroundEquals

public Assertion foregroundEquals(java.lang.String path,
                                  java.lang.String color)
Checks the font color used on a given node.


pathIsExpanded

public Assertion pathIsExpanded(java.lang.String path)
Checks that the a given node of the jTree is expanded - i.e. that its children are made visible.

Parameters:
path - a String identifying the path to be expanded or collapsed

expand

public void expand(java.lang.String path,
                   boolean expand)
Expands or collapses a given node.

Parameters:
path - a String identifying the path to be expanded or collapsed
expand - if true, expand the node, and collapse it otherwise

expandAll

public void expandAll()
Expands all the nodes of the jTree.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2004-2010. All Rights Reserved.