bibliothek.gui.dock.station.split
Class Node

java.lang.Object
  extended by bibliothek.gui.dock.station.split.SplitNode
      extended by bibliothek.gui.dock.station.split.Node

public class Node
extends SplitNode

A Node represents an element in the tree of a SplitDockStation. Every node has two children. The areas of the children are separated by a "divider", whose position can be changed.

Author:
Benjamin Sigg

Field Summary
private  double divider
          The location of the divider.
private  java.awt.Rectangle dividerBounds
          The area of the divider between the two children
private  SplitNode left
          The area of the left child is either at the left or at the top of the area of this node.
private  SplitDockStation.Orientation orientation
          The order in which the children are aligned.
private  SplitNode right
          The area of the right child is either at the right or at the bottom of the area of this node.
 
Fields inherited from class bibliothek.gui.dock.station.split.SplitNode
height, width, x, y
 
Constructor Summary
Node(SplitDockAccess access)
          Constructs a new node.
Node(SplitDockAccess access, SplitNode left, SplitNode right)
          Constructs a new node.
Node(SplitDockAccess access, SplitNode left, SplitNode right, SplitDockStation.Orientation orientation)
          Constructs a new node.
 
Method Summary
 void evolve(SplitDockTree.Key key)
          Creates or replaces children according to the values found in key.
 double getDivider()
          Gets the location of the divider.
 double getDividerAt(int x, int y)
          Calculates the value which the divider must have on condition that the point x/y lies inside the divider bounds.
 java.awt.Rectangle getDividerBounds(double divider, java.awt.Rectangle bounds)
          Calculates the location and the size of the area which represents the divider.
 Node getDividerNode(int x, int y)
          Gets the Node whose divider area contains the point x/y.
 Leaf getLeaf(Dockable dockable)
          Gets the leaf which represents dockable.
 SplitNode getLeft()
          Gets the left child of this node.
 java.awt.Dimension getMinimumSize()
          Gets the minimal size of this node.
 SplitDockStation.Orientation getOrientation()
          Gets the orientation of this node.
 PutInfo getPut(int x, int y, double factorW, double factorH, Dockable drop)
          Determines where to drop the Dockable drop if the mouse is at location x/y.
 SplitNode getRight()
          Gets the right child of this node.
 SplitNode read(java.util.Map<java.lang.Integer,Dockable> children, java.io.DataInputStream in)
          Reads an earlier written node from the stream in.
 void setDivider(double divider)
          Sets the location of the divider.
 void setLeft(SplitNode left)
          Sets the left child of this node.
 void setRight(SplitNode right)
          Sets the right child of this node.
 SplitDockTree.Key submit(SplitDockTree tree)
          Writes the contents of this node into tree.
 void updateBounds(double x, double y, double width, double height, double factorW, double factorH)
          Updates the bounds of this node.
 void visit(SplitNodeVisitor visitor)
          Invokes one of the methods of the visitor for every child in the subtree with this as root.
 void write(java.util.Map<Dockable,java.lang.Integer> children, java.io.DataOutputStream out)
          Writes the structure of the subtree with this as root into out.
 
Methods inherited from class bibliothek.gui.dock.station.split.SplitNode
above, create, getAccess, getBounds, getHeight, getParent, getRoot, getSize, getWidth, getX, getY, intersection, readChild, relativeSidePut, setParent, writeChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

left

private SplitNode left
The area of the left child is either at the left or at the top of the area of this node.


right

private SplitNode right
The area of the right child is either at the right or at the bottom of the area of this node.


divider

private double divider
The location of the divider. It's the fraction of the area of the node which is given to the left child.


orientation

private SplitDockStation.Orientation orientation
The order in which the children are aligned.


dividerBounds

private java.awt.Rectangle dividerBounds
The area of the divider between the two children

Constructor Detail

Node

public Node(SplitDockAccess access,
            SplitNode left,
            SplitNode right,
            SplitDockStation.Orientation orientation)
Constructs a new node.

Parameters:
access - the access to the owner-station of this node.
left - the left child
right - the right child
orientation - how the children are aligned

Node

public Node(SplitDockAccess access,
            SplitNode left,
            SplitNode right)
Constructs a new node.

Parameters:
access - the access to the owner-station of this node
left - the left child
right - the right child

Node

public Node(SplitDockAccess access)
Constructs a new node.

Parameters:
access - the access to the owner-station of this node
Method Detail

setLeft

public void setLeft(SplitNode left)
Sets the left child of this node. The area of this child will be in the left or the upper half of the area of this node.

Parameters:
left - the left child or null

getLeft

public SplitNode getLeft()
Gets the left child of this node.

Returns:
the child
See Also:
setLeft(SplitNode)

setRight

public void setRight(SplitNode right)
Sets the right child of this node. The area of this child will be in the right or the bottom half of the area of this node.

Parameters:
right - the right child

getRight

public SplitNode getRight()
Gets the right child of this node.

Returns:
the child
See Also:
setRight(SplitNode)

getOrientation

public SplitDockStation.Orientation getOrientation()
Gets the orientation of this node. The orientation tells how to layout the children. If the orientation is SplitDockStation.Orientation.VERTICAL, one child will be at the top and the other at the bottom.

Returns:
the orientation

getMinimumSize

public java.awt.Dimension getMinimumSize()
Description copied from class: SplitNode
Gets the minimal size of this node.

Specified by:
getMinimumSize in class SplitNode
Returns:
the minimal size in pixel

setDivider

public void setDivider(double divider)
Sets the location of the divider. The area of the left child is the area of the whole node multiplied with divider.

Parameters:
divider - the divider

getDivider

public double getDivider()
Gets the location of the divider.

Returns:
the divider
See Also:
setDivider(double)

updateBounds

public void updateBounds(double x,
                         double y,
                         double width,
                         double height,
                         double factorW,
                         double factorH)
Description copied from class: SplitNode
Updates the bounds of this node. If the node represents a Component, then the bounds of the component have to be updated as well.

Overrides:
updateBounds in class SplitNode
Parameters:
x - the relative x-coordinate
y - the relative y-coordinate
width - the relative width of the node
height - the relative height of the node
factorW - a factor to be multiplied with x and width to get the size of the node in pixel
factorH - a factor to be multiplied with y and height to get the size of the node in pixel

getDividerBounds

public java.awt.Rectangle getDividerBounds(double divider,
                                           java.awt.Rectangle bounds)
Calculates the location and the size of the area which represents the divider. The user can grab this area with the mouse and drag it around.

Parameters:
divider - The location of the divider, should be between 0 and 1.
bounds - A rectangle in which the result will be stored. It can be null
Returns:
Either bounds or a new Rectangle if bounds was null

getDividerAt

public double getDividerAt(int x,
                           int y)
Calculates the value which the divider must have on condition that the point x/y lies inside the divider bounds.

Parameters:
x - x-coordinate of the point in pixel
y - y-coordinate of the point in pixel
Returns:
The value that the divider should have. This value might not be valid if the coordinates of the point are too extreme.

getPut

public PutInfo getPut(int x,
                      int y,
                      double factorW,
                      double factorH,
                      Dockable drop)
Description copied from class: SplitNode
Determines where to drop the Dockable drop if the mouse is at location x/y.

Specified by:
getPut in class SplitNode
Parameters:
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
factorW - a factor to be multiplied with the relative x and width to get the size in pixel.
factorH - a factor to be multiplied with the relative y and height to get the size in pixel.
drop - the Dockable which will be dropped
Returns:
where to drop the dockable or null if the dockable can't be dropped

evolve

public void evolve(SplitDockTree.Key key)
Description copied from class: SplitNode
Creates or replaces children according to the values found in key.

Specified by:
evolve in class SplitNode
Parameters:
key - the key to read

submit

public SplitDockTree.Key submit(SplitDockTree tree)
Description copied from class: SplitNode
Writes the contents of this node into tree.

Specified by:
submit in class SplitNode
Parameters:
tree - the tree to write into
Returns:
the key of this node

getLeaf

public Leaf getLeaf(Dockable dockable)
Description copied from class: SplitNode
Gets the leaf which represents dockable.

Specified by:
getLeaf in class SplitNode
Parameters:
dockable - the Dockable whose leaf is searched
Returns:
the leaf or null if no leaf was found

getDividerNode

public Node getDividerNode(int x,
                           int y)
Description copied from class: SplitNode
Gets the Node whose divider area contains the point x/y. Only searches in the subtree with this node as root.

Specified by:
getDividerNode in class SplitNode
Parameters:
x - the x-coordinate
y - the y-coordinate
Returns:
the Node containing the point, if no Node was found, null is returned

visit

public void visit(SplitNodeVisitor visitor)
Description copied from class: SplitNode
Invokes one of the methods of the visitor for every child in the subtree with this as root.

Specified by:
visit in class SplitNode
Parameters:
visitor - the visitor

write

public void write(java.util.Map<Dockable,java.lang.Integer> children,
                  java.io.DataOutputStream out)
           throws java.io.IOException
Description copied from class: SplitNode
Writes the structure of the subtree with this as root into out.

Specified by:
write in class SplitNode
Parameters:
children - a map that contains for every Dockable an id. This id will be written into out to represent the Dockable.
out - the stream to fill
Throws:
java.io.IOException - if the stream throws an exception

read

public SplitNode read(java.util.Map<java.lang.Integer,Dockable> children,
                      java.io.DataInputStream in)
               throws java.io.IOException
Description copied from class: SplitNode
Reads an earlier written node from the stream in.

Specified by:
read in class SplitNode
Parameters:
children - a map of substitutions for ids that are found in the stream.
in - the source
Returns:
the newly created node
Throws:
java.io.IOException - if the stream throws an exception
See Also:
SplitNode.write(Map, DataOutputStream)