abbot.tester
Class JTreeLocation

java.lang.Object
  extended by abbot.tester.ComponentLocation
      extended by abbot.tester.JTreeLocation

public class JTreeLocation
extends ComponentLocation

Provides encapsulation of a visible location on a JTree. A row index or a Stringified TreePath (i.e. each TreePath component is a String) or a TreePath of Object may be used to indicate the location. Note that if a TreePath is used, the entire path leading up to the designated node must be viewable at the time the location is used.

See Also:
for a description of the matching algorithm.

Field Summary
 
Fields inherited from class abbot.tester.ComponentLocation
CENTER
 
Constructor Summary
JTreeLocation()
          Create an uninitialized JTreeLocation.
JTreeLocation(int row)
          Create a JTreeLocation corresponding to the given row, by index.
JTreeLocation(int row, boolean inExpansion)
          Create a JTreeLocation corresponding to the given row, by index.
JTreeLocation(Point p)
           
JTreeLocation(TreePath treePath)
          Create a JTreeLocation corresponding to the given TreePath.
JTreeLocation(TreePath treePath, boolean inExpansion)
          Create a JTreeLocation corresponding to the given TreePath.
 
Method Summary
protected  String badFormat(String encoded)
           
 boolean equals(Object o)
          Returns whether the given object is an equivalent ComponentLocation.
static TreePath findMatchingPath(JTree tree, TreePath path)
          Given a TreePath (which may be composed of objects, string representations of objects, or regular expressions), return the equivalent TreePath for the given JTree constructed from objects from the tree's model.
 Rectangle getBounds(Component c)
          Convert the abstract location into a concrete area, relative to the given Component.
(package private)  TreePath getPath(JTree tree)
          Return the path represented by this JTree location.
 Point getPoint(Component c)
          Return a concrete point for the abstract location.
(package private)  int getRow(JTree tree)
          Return the row represented by this JTree location.
 boolean isInExpansion()
           
 ComponentLocation parse(String encoded)
          Convert the given encoding into the proper location.
protected  Point pathToPoint(JTree tree, TreePath path)
          Convert the given path to an x, y coordinate.
protected  Point rowToPoint(JTree tree, int row)
          Convert the given row to an x, y coordinate.
 void setInExpansion(boolean in)
           
 String toString()
           
 
Methods inherited from class abbot.tester.ComponentLocation
encodeIndex, encodeValue, isIndex, isValue, parseIndex, parseValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JTreeLocation

public JTreeLocation()
Create an uninitialized JTreeLocation. If queried for its Point will return the default location.


JTreeLocation

public JTreeLocation(int row)
Create a JTreeLocation corresponding to the given row, by index.


JTreeLocation

public JTreeLocation(int row,
                     boolean inExpansion)
Create a JTreeLocation corresponding to the given row, by index.


JTreeLocation

public JTreeLocation(TreePath treePath)
Create a JTreeLocation corresponding to the given TreePath. The TreePath must consist of usable String representations that can be used in later comparisons. The default <classname>@<hashcode> returned by Object.toString() is not usable; if that is all that is available, refer to the row number instead.


JTreeLocation

public JTreeLocation(TreePath treePath,
                     boolean inExpansion)
Create a JTreeLocation corresponding to the given TreePath. The TreePath must consist of usable String representations that can be used in later comparisons. The default <classname>@<hashcode> format returned by Object.toString() is not usable; if that is all that is available, refer to the row number instead.


JTreeLocation

public JTreeLocation(Point p)
Method Detail

setInExpansion

public void setInExpansion(boolean in)

isInExpansion

public boolean isInExpansion()

rowToPoint

protected Point rowToPoint(JTree tree,
                           int row)
Convert the given row to an x, y coordinate.

Throws:
LocationUnavailableException - if the row is not visible.

pathToPoint

protected Point pathToPoint(JTree tree,
                            TreePath path)
Convert the given path to an x, y coordinate.

Throws:
LocationUnavailableException - if any part of the path is hidden.

getPath

TreePath getPath(JTree tree)
Return the path represented by this JTree location.

Returns:
null if the path can not be found.

getRow

int getRow(JTree tree)
Return the row represented by this JTree location.

Returns:
-1 if the row is not found.

getPoint

public Point getPoint(Component c)
Return a concrete point for the abstract location.

Overrides:
getPoint in class ComponentLocation

getBounds

public Rectangle getBounds(Component c)
Description copied from class: ComponentLocation
Convert the abstract location into a concrete area, relative to the given Component. If a point has been specified, returns a 1x1 rectangle, otherwise returns the a rectangle at (0, 0) of the Component's size.

Overrides:
getBounds in class ComponentLocation

equals

public boolean equals(Object o)
Description copied from class: ComponentLocation
Returns whether the given object is an equivalent ComponentLocation.

Overrides:
equals in class ComponentLocation

toString

public String toString()
Overrides:
toString in class ComponentLocation

parse

public ComponentLocation parse(String encoded)
Description copied from class: ComponentLocation
Convert the given encoding into the proper location. Allowed formats: (x, y)

Overrides:
parse in class ComponentLocation

badFormat

protected String badFormat(String encoded)
Overrides:
badFormat in class ComponentLocation

findMatchingPath

public static TreePath findMatchingPath(JTree tree,
                                        TreePath path)
Given a TreePath (which may be composed of objects, string representations of objects, or regular expressions), return the equivalent TreePath for the given JTree constructed from objects from the tree's model.

For each element, Object.equals(java.lang.Object) is attempted first (a null pattern matches everything), followed by a comparison of the pattern as a String (via Object.toString()). The pattern may be a regular expression bounded by forward slashes.

Throws:
LocationUnavailableException - if no matching path is found.


Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge