bibliothek.gui.dock.station.split
Class SplitNode

java.lang.Object
  extended by bibliothek.gui.dock.station.split.SplitNode
Direct Known Subclasses:
Leaf, Node, Root

public abstract class SplitNode
extends Object

The internal representation of a SplitDockStation is a tree. The subclasses of SplitNode build this tree.

Author:
Benjamin Sigg

Field Summary
protected  double height
          Bounds of this node on the station
protected  double width
          Bounds of this node on the station
protected  double x
          Bounds of this node on the station
protected  double y
          Bounds of this node on the station
 
Constructor Summary
protected SplitNode(SplitDockAccess access)
          Creates a new SplitNode.
 
Method Summary
static boolean above(double x1, double y1, double x2, double y2, double x, double y)
          Calculates whether the point x/y lies above the line going through x1/y1 and x2/y2.
protected  SplitNode create(SplitDockTree.Key key)
          Creates a new node using the contents of key.
abstract  void evolve(SplitDockTree.Key key)
          Creates or replaces children according to the values found in key.
protected  SplitDockAccess getAccess()
          Gets access to the owner-station
 Rectangle getBounds()
          Gets the size and location of this node in pixel where the point 0/0 is equal to the point 0/0 on the owner-station.
abstract  Node getDividerNode(int x, int y)
          Gets the Node whose divider area contains the point x/y.
 double getHeight()
          Gets the relative height of this node in relation to the owner-station.
abstract  Leaf getLeaf(Dockable dockable)
          Gets the leaf which represents dockable.
abstract  Dimension getMinimumSize()
          Gets the minimal size of this node.
 SplitNode getParent()
          Gets the parent of this node.
abstract  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.
protected  Root getRoot()
          Gets the root of the tree in which this node is
 Dimension getSize()
          Gets the size of this node in pixel.
 double getWidth()
          Gets the relative width of this node in relation to the owner-station.
 double getX()
          Gets the relative x-coordinate of this node on the owner-station.
 double getY()
          Gets the relative y-coordinate of this node on the owner-station.
 double intersection(SplitDockProperty property)
          Calculates how much of the rectangle given by the property lies inside this node and how much of this node lies in the rectangle.
abstract  SplitNode read(Map<Integer,Dockable> children, DataInputStream in)
          Reads an earlier written node from the stream in.
protected  SplitNode readChild(Map<Integer,Dockable> children, DataInputStream in)
          Reads a single node which was earlier written.
 PutInfo.Put relativeSidePut(double kx, double ky)
          Calculates on which side of the node the point kx/ky lies.
 void setParent(SplitNode parent)
          Sets the parent of this node.
abstract  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.
abstract  void visit(SplitNodeVisitor visitor)
          Invokes one of the methods of the visitor for every child in the subtree with this as root.
abstract  void write(Map<Dockable,Integer> children, DataOutputStream out)
          Writes the structure of the subtree with this as root into out.
protected  void writeChild(SplitNode element, Map<Dockable,Integer> children, DataOutputStream out)
          Writes the contents of a single child into out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

protected double x
Bounds of this node on the station


y

protected double y
Bounds of this node on the station


width

protected double width
Bounds of this node on the station


height

protected double height
Bounds of this node on the station

Constructor Detail

SplitNode

protected SplitNode(SplitDockAccess access)
Creates a new SplitNode.

Parameters:
access - the access to the owner of this node. Must not be null
Method Detail

getX

public double getX()
Gets the relative x-coordinate of this node on the owner-station. The coordinates are measured as fraction of the size of the owner-station.

Returns:
A value between 0 and 1

getY

public double getY()
Gets the relative y-coordinate of this node on the owner-station. The coordinates are measured as fraction of the size of the owner-station.

Returns:
A value between 0 and 1

getWidth

public double getWidth()
Gets the relative width of this node in relation to the owner-station.

Returns:
a value between 0 and 1

getHeight

public double getHeight()
Gets the relative height of this node in relation to the owner-station.

Returns:
a value between 0 and 1

setParent

public void setParent(SplitNode parent)
Sets the parent of this node.

Parameters:
parent - the new parent, can be null

getParent

public SplitNode getParent()
Gets the parent of this node.

Returns:
the parent, can be null

getAccess

protected SplitDockAccess getAccess()
Gets access to the owner-station

Returns:
the access

getMinimumSize

public abstract Dimension getMinimumSize()
Gets the minimal size of this node.

Returns:
the minimal size in pixel

updateBounds

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

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

getBounds

public Rectangle getBounds()
Gets the size and location of this node in pixel where the point 0/0 is equal to the point 0/0 on the owner-station.

Returns:
the size and location

getSize

public Dimension getSize()
Gets the size of this node in pixel.

Returns:
the size of the node

getRoot

protected Root getRoot()
Gets the root of the tree in which this node is

Returns:
the root

getPut

public abstract 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.

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

getLeaf

public abstract Leaf getLeaf(Dockable dockable)
Gets the leaf which represents dockable.

Parameters:
dockable - the Dockable whose leaf is searched
Returns:
the leaf or null if no leaf was found

getDividerNode

public abstract Node getDividerNode(int x,
                                    int y)
Gets the Node whose divider area contains the point x/y. Only searches in the subtree with this node as root.

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 abstract void visit(SplitNodeVisitor visitor)
Invokes one of the methods of the visitor for every child in the subtree with this as root.

Parameters:
visitor - the visitor

write

public abstract void write(Map<Dockable,Integer> children,
                           DataOutputStream out)
                    throws IOException
Writes the structure of the subtree with this as root into out.

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:
IOException - if the stream throws an exception

writeChild

protected void writeChild(SplitNode element,
                          Map<Dockable,Integer> children,
                          DataOutputStream out)
                   throws IOException
Writes the contents of a single child into out.

Parameters:
element - the element to store
children - the unique ids of all Dockables which may occur.
out - the stream to fill
Throws:
IOException - if the stream throws an exception
See Also:
readChild(Map, DataInputStream)

read

public abstract SplitNode read(Map<Integer,Dockable> children,
                               DataInputStream in)
                        throws IOException
Reads an earlier written node from the stream in.

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

readChild

protected SplitNode readChild(Map<Integer,Dockable> children,
                              DataInputStream in)
                       throws IOException
Reads a single node which was earlier written.

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

evolve

public abstract void evolve(SplitDockTree.Key key)
Creates or replaces children according to the values found in key.

Parameters:
key - the key to read

submit

public abstract SplitDockTree.Key submit(SplitDockTree tree)
Writes the contents of this node into tree.

Parameters:
tree - the tree to write into
Returns:
the key of this node

create

protected SplitNode create(SplitDockTree.Key key)
Creates a new node using the contents of key.

Parameters:
key - the key to read
Returns:
the new node

intersection

public double intersection(SplitDockProperty property)
Calculates how much of the rectangle given by the property lies inside this node and how much of this node lies in the rectangle. The result is a value between 0 and 1 which is 1 only if this node and the rectangle are identical. The result is 0 if they do not have a shared area.

Parameters:
property - the property that gives a rectangle
Returns:
Area of intersection divided by the maxima of the area of the rectangle and of this node.

relativeSidePut

public PutInfo.Put relativeSidePut(double kx,
                                   double ky)
Calculates on which side of the node the point kx/ky lies.

Parameters:
kx - the relative x-coordinate of the point
ky - the relative y-coordinate of the point
Returns:
One side of the node

above

public static boolean above(double x1,
                            double y1,
                            double x2,
                            double y2,
                            double x,
                            double y)
Calculates whether the point x/y lies above the line going through x1/y1 and x2/y2.

Parameters:
x1 - the x-coordinate of the first point on the line
y1 - the y-coordinate of the first point on the line
x2 - the x-coordinate of the second point on the line
y2 - the y-coordinate of the second point on the line
x - the x-coordinate of the point which may be above the line
y - the y-coordinate of the point which may be above the line
Returns:
true if the point lies above the line, false otherwise