torero.gui
Class MyTreeUI

java.lang.Object
  |
  +--javax.swing.plaf.ComponentUI
        |
        +--javax.swing.plaf.TreeUI
              |
              +--torero.gui.MyTreeUI

public class MyTreeUI
extends TreeUI

Pluggable Look&Feel Component for a horizontal layout of the JTree. This code is compatible to the SWING version bundeled with JDK 1.2.2, but it cannot be guaranted that it is compatible with later SWING versions. It implements the appropriate methods of a TreeUI, but it was not possible to implement all. The original swing implementation is mainly dependent on (table) rows but this implementation is not, therefore the implementation is different. MyTreeUI is designed to work with the NodeWrapper class, but with a few changes it would also work with the standard TreeNode interfaces.

See Also:
NodeWrapper, TreeUI

Inner Class Summary
 class MyTreeUI.ComponentHandler
          Updates the preferred size when scrolling (if necessary).
 class MyTreeUI.MouseHandler
          TreeMouseListener is responsible for updating the selection based on mouse events.
 class MyTreeUI.MouseInputHandler
          MouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.
 class MyTreeUI.SelectionModelPropertyChangeHandler
          Listener on the TreeSelectionModel, resets the row selection if any of the properties of the model change.
 class MyTreeUI.TreeExpansionHandler
          Updates the TreeState in response to nodes expanding/collapsing.
 class MyTreeUI.TreeModelHandler
          Forwards all TreeModel events to the Tree's state.
 class MyTreeUI.TreeSelectionHandler
          Listens for changes in the selection model and updates the display accordingly.
 
Field Summary
protected  TreeSelectionModel currenttsm
          The current TreeSelectionModel, derived from the JTree.
protected  boolean initialized
          Field indicating if the TreeUI has already been initialized.
protected  CellRendererPane rendererPane
          The current CellRendererPane
protected  TreeNode root
          The root Treenode.
protected  MyTreeUI.TreeExpansionHandler teh
          Reference to an inner class, that is not used now and does only exists for compatibility.
 
Constructor Summary
MyTreeUI()
          Creates a new TreeUI.
 
Method Summary
 void cancelEditing(JTree tree)
          Not implemented, because this TreeUI doesn't support editing.
static ComponentUI createUI(JComponent c)
          It returns an instance of MyTreeUI as the original BasicTreeUI implementation does.
 TreePath getClosestPathForLocation(JTree tree, int x, int y)
          Implementation different to original SWING BasicTreeUI.
 TreePath getEditingPath(JTree tree)
          Not implemeted.
 Dimension getMaximumSize(JComponent c)
          Returns the preferred size of the component.
 Dimension getMinimumSize(JComponent c)
          Returns the preferred size of the component.
 Rectangle getPathBounds(JTree tree, TreePath path)
          Not implemented correct.
 TreePath getPathForRow(JTree tree, int row)
          Implementation different to original SWING BasicTreeUI.
 Dimension getPreferredSize(JComponent c)
          Returns the preferred size of the component.
 int getRowCount(JTree tree)
          Not implemented, because rows don't make sense in this TreeUI.
 int getRowForPath(JTree tree, TreePath path)
          Not implemented, because rows don't make sense in this TreeUI.
protected  void installListeners()
          Installs the MouseHandler, TreeExpansionHandler and the TreeModelhandler.
 void installUI(JComponent c)
          This method ist called by the JTree, it is an undocumented call and therefore is is possible that other implementations of Swing dont call this method.
 boolean isEditing(JTree tree)
          Returns tree.isEditing() whatever that means.
 void paint(Graphics g, JComponent c)
          This method is invoked by Swing to draw components.
 void startEditingAtPath(JTree tree, TreePath path)
          Not implemented, because this TreeUI doesn't support editing.
 boolean stopEditing(JTree tree)
          Not implemented, because this TreeUI doesn't support editing.
 void uninstallUI(JComponent c)
          This method only calls the super.uninstallUI(c).
protected  void updateRenderer()
          Messaged from the tree we're in when the renderer has changed.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rendererPane

protected CellRendererPane rendererPane
The current CellRendererPane

currenttsm

protected TreeSelectionModel currenttsm
The current TreeSelectionModel, derived from the JTree.

teh

protected MyTreeUI.TreeExpansionHandler teh
Reference to an inner class, that is not used now and does only exists for compatibility.

root

protected TreeNode root
The root Treenode.

initialized

protected boolean initialized
Field indicating if the TreeUI has already been initialized.
Constructor Detail

MyTreeUI

public MyTreeUI()
Creates a new TreeUI. Does nothing (empty).
Method Detail

createUI

public static ComponentUI createUI(JComponent c)
It returns an instance of MyTreeUI as the original BasicTreeUI implementation does. We dont't know if this method is necessary, because it was never called by the JTree during our tests. It's a TreeUI - Interface method.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferred size of the component. If it was not initialized before, it returns a new (invalid) dimension object.
Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - not used. Not documented in the JavaDoc.
Returns:
the preferred size of the component.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Returns the preferred size of the component. If it was not initialized before, it returns a new (invalid) dimension object. It was never called by the JTree during the tests.
Overrides:
getMaximumSize in class ComponentUI
Parameters:
c - not used. Not documented in the JavaDoc.
Returns:
the preferred size of the component.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Returns the preferred size of the component. If it was not initialized before, it returns a new (invalid) dimension object. It was never called by the JTree during the tests.
Overrides:
getMinimumSize in class ComponentUI
Parameters:
c - not used. Not documented in the JavaDoc.
Returns:
the preferred size of the component.

cancelEditing

public void cancelEditing(JTree tree)
Not implemented, because this TreeUI doesn't support editing.
Overrides:
cancelEditing in class TreeUI

getClosestPathForLocation

public TreePath getClosestPathForLocation(JTree tree,
                                          int x,
                                          int y)
Implementation different to original SWING BasicTreeUI. Computes and returns a TreePath of NodeWrapper objects, from the root node to this node. It was never called by the JTree during our tests.
Overrides:
getClosestPathForLocation in class TreeUI
Parameters:
tree - ignored.
x,y - ignored.

getEditingPath

public TreePath getEditingPath(JTree tree)
Not implemeted.
Overrides:
getEditingPath in class TreeUI
Returns:
returns null.

getPathBounds

public Rectangle getPathBounds(JTree tree,
                               TreePath path)
Not implemented correct. Was never called during the tests. Returns a Rectagle of preferredHeight and PreferredWidth.
Overrides:
getPathBounds in class TreeUI
Parameters:
tree - ignored.
path - ignored.
Returns:
the Rectagle of preferredHeight and PreferredWidth.

getPathForRow

public TreePath getPathForRow(JTree tree,
                              int row)
Implementation different to original SWING BasicTreeUI. Computes and returns a TreePath of NodeWrapper objects, from the root node to this node. It was never called by the JTree during our tests.
Overrides:
getPathForRow in class TreeUI
Parameters:
tree - ignored.
row - ignored.
Returns:
The computed TreePath

getRowCount

public int getRowCount(JTree tree)
Not implemented, because rows don't make sense in this TreeUI.
Overrides:
getRowCount in class TreeUI
Parameters:
tree - ignored.
Returns:
0.

getRowForPath

public int getRowForPath(JTree tree,
                         TreePath path)
Not implemented, because rows don't make sense in this TreeUI.
Overrides:
getRowForPath in class TreeUI
Parameters:
tree - ignored.
Returns:
0.

isEditing

public boolean isEditing(JTree tree)
Returns tree.isEditing() whatever that means. Editing is not supported by this component.
Overrides:
isEditing in class TreeUI
Parameters:
tree - the JTree beeing displayed.
Returns:
tree.isEditing()

startEditingAtPath

public void startEditingAtPath(JTree tree,
                               TreePath path)
Not implemented, because this TreeUI doesn't support editing.
Overrides:
startEditingAtPath in class TreeUI

stopEditing

public boolean stopEditing(JTree tree)
Not implemented, because this TreeUI doesn't support editing.
Overrides:
stopEditing in class TreeUI
Parameters:
tree - ignored.
Returns:
true.

paint

public void paint(Graphics g,
                  JComponent c)
This method is invoked by Swing to draw components. Painting sequence: On the root - NodeWrapperObject some methods are called to perform this operation. If the tree is dirty the calcPrefSize(), calcTree(), resetline(), calcLineCache() methods are called, paintTree() is called every time. If the tree's view was dirty then treeDidChange() is called on the JTree.
Overrides:
paint in class ComponentUI
Parameters:
g - graphics object used for painting.
c - must be the JTree.

installUI

public void installUI(JComponent c)
This method ist called by the JTree, it is an undocumented call and therefore is is possible that other implementations of Swing dont call this method. Make sure, that a Treeselectionmodel is set for the JTree before you call JTree.SetUI ! It does the necessary initializations e.g. sets size to (0,0), calls the installListeners() method and sets the selection to the root node.
Overrides:
installUI in class ComponentUI
Parameters:
c - must be the JTree for beeing displayed.

uninstallUI

public void uninstallUI(JComponent c)
This method only calls the super.uninstallUI(c).
Overrides:
uninstallUI in class ComponentUI
Parameters:
c - must be the JTree beeing displayed. Was never tested.

updateRenderer

protected void updateRenderer()
Messaged from the tree we're in when the renderer has changed. Set the TreeCellRenderer used by this component to tree.getCellRenderer(). If MyTreeUI has not been initialized yet, the currentCellrenderer is set to null.

installListeners

protected void installListeners()
Installs the MouseHandler, TreeExpansionHandler and the TreeModelhandler. Its called by installUI().