bibliothek.gui.dock.station.split
Class Leaf

java.lang.Object
  extended by bibliothek.gui.dock.station.split.SplitNode
      extended by bibliothek.gui.dock.station.split.VisibleSplitNode
          extended by bibliothek.gui.dock.station.split.SpanSplitNode
              extended by bibliothek.gui.dock.station.split.Leaf

public class Leaf
extends SpanSplitNode

Represents a leaf in the tree that is the structure of a SplitDockStation. A leaf also represents a single Dockable which is shown on the owner-station.

Author:
Benjamin Sigg

Field Summary
 
Fields inherited from class bibliothek.gui.dock.station.split.SplitNode
height, width, x, y
 
Constructor Summary
Leaf(SplitDockAccess access)
          Creates a new leaf.
Leaf(SplitDockAccess access, long id)
          Creates a new leaf.
 
Method Summary
 boolean aside(AsideRequest request)
          Inserts a new placeholder at this node.
 boolean aside(SplitDockPathProperty property, int index, AsideRequest request)
          Inserts a new placeholder at location property.
protected  PutInfo createSidePut(Rectangle bounds, int x, int y, Dockable drop, boolean centered)
          Assuming the mouse at x/y is within bounds, this method calculates which one of the non-combining PutInfo.Puts describe the situation best.
 void evolve(SplitDockTree.Key key, boolean checkValidity, Map<Leaf,Dockable> linksToSet)
          Creates or replaces children according to the values found in key.
 SplitNode getChild(int location)
          Gets the child at location.
 int getChildLocation(SplitNode child)
          Gets the location of a child.
 DockableDisplayer getDisplayer()
          Gets the displayer of this leaf.
 Node getDividerNode(int x, int y)
          Gets the Node whose divider area contains the point x/y.
 Dockable getDockable()
          Gets the Dockable which is shown on the displayer of this leaf.
 StationChildHandle getDockableHandle()
          Gets the handle which is responsible for the current Dockable.
 Leaf getLeaf(Dockable dockable)
          Gets the leaf which represents dockable.
 int getMaxChildrenCount()
          Gets the maximal number of children this node can have.
 Dimension getMinimumSize()
          Gets the minimal size of this node.
 Dimension getPreferredSize()
          Gets the preferred size 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 getVisible()
          Gets the root of a subtree such that the root is visible and such that the is the uppermost visible node.
 boolean insert(SplitDockPathProperty property, int depth, Dockable dockable)
          If there are elements left in property, then the next node is to be read and the insert-method of the matching child to be called.
If there are no children, then dockable has to be inserted as new child.
Otherwise this element is to be replaced by a node containing this and the a leaf with dockable.
Subclasses may wary this scheme in order to optimize or to find a better place for the dockable.
 boolean insert(SplitDockPlaceholderProperty property, Dockable dockable)
          Recursively searches for a node or leaf that uses the placeholder specified by property and inserts the dockable there.
protected  boolean isCenterPut(Rectangle bounds, int x, int y)
          Tells whether the position of the mouse x/y would result in a drag and drop operation where PutInfo.Put.CENTER is apropriate.
 boolean isInOverrideZone(int x, int y, double factorW, double factorH)
          Tells whether the coordinates x/y lie inside the override-zone of the SplitDockStation or not.
 boolean isOfUse()
          Tells whether this node still has any use or can safely be removed from the tree
protected  boolean isTitlePut(Rectangle bounds, int x, int y)
          Tells whether the position of the mouse x/y would result in a drag and drop operation where PutInfo.Put.TITLE is apropriate.
 boolean isVisible()
          Tells whether this node (or one of this children) contains element that are visible to the user.
 void onSpanResize()
          Called if a Span of this node changed its size
 void placehold(boolean keepCurrent)
          Disconnects this leaf from its Dockable.
protected  Rectangle removeTitle(Rectangle bounds)
          Asks the DockableDisplayer for its current DockTitle and removes the size of the title from bounds.
 void resetDisplayerBounds()
          Resets the boundaries of the DockableDisplayer of this Leaf, using the current Spans as well.
 void setBounds(double x, double y, double width, double height, double factorW, double factorH, boolean updateComponentBounds)
          Updates the bounds of this node.
 void setChild(SplitNode child, int location)
          Adds a child to this node at a given location.
 void setDockable(Dockable dockable, DockHierarchyLock.Token token)
          Sets the element of this leaf.
 void setDockable(Dockable dockable, DockHierarchyLock.Token token, boolean updatePlaceholders, boolean storePlaceholderMap)
          Sets the element of this leaf.
 void setHandle(StationChildHandle handle)
          Sets the element of this leaf.
<N> N
submit(SplitTreeFactory<N> factory)
          Writes the contents of this node into a new tree create by factory.
 void toString(int tabs, StringBuilder out)
          Writes some contents of this node into out.
 void updateBounds(double x, double y, double width, double height, double factorW, double factorH, boolean components)
          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.
 
Methods inherited from class bibliothek.gui.dock.station.split.SpanSplitNode
createSpans, getSpans
 
Methods inherited from class bibliothek.gui.dock.station.split.VisibleSplitNode
getCurrentBounds
 
Methods inherited from class bibliothek.gui.dock.station.split.SplitNode
above, addPlaceholder, create, create, createLeaf, createNode, createPlaceholder, delete, ensureIdUnique, ensureIdUniqueAsync, getAccess, getBounds, getHeight, getId, getParent, getPlaceholderMap, getPlaceholderNode, getPlaceholders, getRoot, getSize, getStation, getTotalChildrenCount, getWidth, getX, getY, hasPlaceholder, hasPlaceholders, intersection, movePlaceholderMap, relativeSidePut, removePlaceholder, removePlaceholders, replace, setParent, setPlaceholderMap, setPlaceholders, split, split, toString, treeChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Leaf

public Leaf(SplitDockAccess access)
Creates a new leaf.

Parameters:
access - the access to the private functions of the owning SplitDockStation

Leaf

public Leaf(SplitDockAccess access,
            long id)
Creates a new leaf.

Parameters:
access - the access to the private functions of the owning SplitDockStation
id - the unique id of this leaf
Method Detail

setHandle

public void setHandle(StationChildHandle handle)
Sets the element of this leaf.

Parameters:
handle - the element

getMinimumSize

public 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

getPreferredSize

public Dimension getPreferredSize()
Description copied from class: SplitNode
Gets the preferred size of this node.

Specified by:
getPreferredSize in class SplitNode
Returns:
the preferred size in pixel

getChildLocation

public int getChildLocation(SplitNode child)
Description copied from class: SplitNode
Gets the location of a child.

Specified by:
getChildLocation in class SplitNode
Parameters:
child - a child of this node
Returns:
the location of child or -1 if the child is unknown

setChild

public void setChild(SplitNode child,
                     int location)
Description copied from class: SplitNode
Adds a child to this node at a given location.

Specified by:
setChild in class SplitNode
Parameters:
child - the new child
location - the location of the child

getMaxChildrenCount

public int getMaxChildrenCount()
Description copied from class: SplitNode
Gets the maximal number of children this node can have.

Specified by:
getMaxChildrenCount in class SplitNode
Returns:
the maximal number of children

getChild

public SplitNode getChild(int location)
Description copied from class: SplitNode
Gets the child at location.

Specified by:
getChild in class SplitNode
Parameters:
location - the location of the child
Returns:
the child or null if the location is invalid or if there is no child at the location

setDockable

public void setDockable(Dockable dockable,
                        DockHierarchyLock.Token token)
Sets the element of this leaf. This method ensures that dockable is registered in the DockStation

Parameters:
dockable - the new element or null to remove the old Dockable
token - if null, then a token will be acquired by this method and this method will fire events, otherwise this methods is executed silently. Clients should use null.

setDockable

public void setDockable(Dockable dockable,
                        DockHierarchyLock.Token token,
                        boolean updatePlaceholders,
                        boolean storePlaceholderMap)
Sets the element of this leaf. This method ensures that dockable is registered in the DockStation

Parameters:
dockable - the new element or null to remove the old Dockable
token - if null, then a token will be acquired by this method and this method will fire events, otherwise this methods is executed silently
updatePlaceholders - if true, the placeholder list of this leaf is automatically updated
storePlaceholderMap - if true, the current PlaceholderMap is replaced by the map provided by the current Dockable which is a DockStation

getDockable

public Dockable getDockable()
Gets the Dockable which is shown on the displayer of this leaf.

Returns:
the Dockable

getDisplayer

public DockableDisplayer getDisplayer()
Gets the displayer of this leaf.

Returns:
the displayer

getDockableHandle

public StationChildHandle getDockableHandle()
Gets the handle which is responsible for the current Dockable.

Returns:
the handle, might be null

isVisible

public boolean isVisible()
Description copied from class: SplitNode
Tells whether this node (or one of this children) contains element that are visible to the user.

Specified by:
isVisible in class SplitNode
Returns:
true if this node or one of its children contains a graphical element

getVisible

public SplitNode getVisible()
Description copied from class: SplitNode
Gets the root of a subtree such that the root is visible and such that the is the uppermost visible node.

Specified by:
getVisible in class SplitNode
Returns:
the visible root, can be null, this or any child of this node

isOfUse

public boolean isOfUse()
Description copied from class: SplitNode
Tells whether this node still has any use or can safely be removed from the tree

Specified by:
isOfUse in class SplitNode
Returns:
true if this node has to remain in the tree, false otherwise

placehold

public void placehold(boolean keepCurrent)
Disconnects this leaf from its Dockable. This leaf either deletes itself or replaces itself with a Placeholder.

Parameters:
keepCurrent - if true, the placeholder of the current Dockable is added to the set of the placeholders, otherwise the placeholder is removed.

updateBounds

public void updateBounds(double x,
                         double y,
                         double width,
                         double height,
                         double factorW,
                         double factorH,
                         boolean components)
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.
This method is recursive, it will call updateBounds on the children of this node.

Overrides:
updateBounds in class VisibleSplitNode
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
components - whether to update the bounds of Components that are in the tree. If set to false, then all updates stay within the tree and the graphical user interface is not changed. That can be useful if more than one round of updates is necessary. If in doubt, set this parameter to true.
See Also:
SplitNode.setBounds(double, double, double, double, double, double, boolean)

setBounds

public void setBounds(double x,
                      double y,
                      double width,
                      double height,
                      double factorW,
                      double factorH,
                      boolean updateComponentBounds)
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. This method is not recursive, it does not call getBounds on the children of this node.

Overrides:
setBounds 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
updateComponentBounds - whether to update the bounds of Components that are in the tree. If set to false, then all updates stay within the tree and the graphical user interface is not changed. That can be useful if more than one round of updates is necessary. If in doubt, set this parameter to true.
See Also:
SplitNode.updateBounds(double, double, double, double, double, double, boolean)

onSpanResize

public void onSpanResize()
Description copied from class: SpanSplitNode
Called if a Span of this node changed its size

Specified by:
onSpanResize in class SpanSplitNode

resetDisplayerBounds

public void resetDisplayerBounds()
Resets the boundaries of the DockableDisplayer of this Leaf, using the current Spans as well.


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

removeTitle

protected Rectangle removeTitle(Rectangle bounds)
Asks the DockableDisplayer for its current DockTitle and removes the size of the title from bounds. Depending on the position of the title bounds is moved, shrunk only horizontally or vertically.

Parameters:
bounds - some boundaries, usually describing the boundaries of this Leaf but any Rectangle can be modified by this method
Returns:
a copy of bounds where the size of the title (if there is any) has been removed

isCenterPut

protected boolean isCenterPut(Rectangle bounds,
                              int x,
                              int y)
Tells whether the position of the mouse x/y would result in a drag and drop operation where PutInfo.Put.CENTER is apropriate.

Parameters:
bounds - the boundaries of the Dockable, this Leaf or any other representation of the Dockable
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
Returns:
whether the location of the mouse would allow a combination of the Dockables

isTitlePut

protected boolean isTitlePut(Rectangle bounds,
                             int x,
                             int y)
Tells whether the position of the mouse x/y would result in a drag and drop operation where PutInfo.Put.TITLE is apropriate.

Parameters:
bounds - the boundaries of the Dockable, this Leaf or any other representation of the Dockable
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
Returns:
whether the location of the mouse would allow a combination of the Dockables

createSidePut

protected PutInfo createSidePut(Rectangle bounds,
                                int x,
                                int y,
                                Dockable drop,
                                boolean centered)
Assuming the mouse at x/y is within bounds, this method calculates which one of the non-combining PutInfo.Puts describe the situation best. The method creates and validates a new PutInfo.

Parameters:
bounds - the boundaries of the Dockable, the Leaf or any other representation of the Dockable.
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
drop - the item that is about to be dropped
centered - whether the mouse position alone would usually require one of the combining PutInfo.Puts
Returns:
the new drag and drop operation, or null if the suggested operation is not valid

isInOverrideZone

public boolean isInOverrideZone(int x,
                                int y,
                                double factorW,
                                double factorH)
Description copied from class: SplitNode
Tells whether the coordinates x/y lie inside the override-zone of the SplitDockStation or not.

Specified by:
isInOverrideZone 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.
Returns:
true if the station should not allow child-stations to make a drop when the mouse is at x/y

evolve

public void evolve(SplitDockTree.Key key,
                   boolean checkValidity,
                   Map<Leaf,Dockable> linksToSet)
Description copied from class: SplitNode
Creates or replaces children according to the values found in key. Note that this method does not remove any Dockables from the station. They must be removed explicitly using setDockable(Dockable, bibliothek.gui.dock.DockHierarchyLock.Token)

Specified by:
evolve in class SplitNode
Parameters:
key - the key to read
checkValidity - whether to ensure that all new Dockables are acceptable or not.
linksToSet - a map that is to be filled with all new Leafs and their Dockables which are not yet set.

insert

public boolean insert(SplitDockPlaceholderProperty property,
                      Dockable dockable)
Description copied from class: SplitNode
Recursively searches for a node or leaf that uses the placeholder specified by property and inserts the dockable there. Also removes the placeholder from this node.

Specified by:
insert in class SplitNode
Parameters:
property - the placeholder to search
dockable - the new element
Returns:
true if the element was inserted, false otherwise

aside

public boolean aside(AsideRequest request)
Description copied from class: SplitNode
Inserts a new placeholder at this node.

Specified by:
aside in class SplitNode
Parameters:
request - more information about the request, including the placeholder to add
Returns:
true if the placeholder was added, false if it could not be added

aside

public boolean aside(SplitDockPathProperty property,
                     int index,
                     AsideRequest request)
Description copied from class: SplitNode
Inserts a new placeholder at location property.

Specified by:
aside in class SplitNode
Parameters:
property - the path to the placeholder
index - the current segment, represents this node
request - more information about the request, including the placeholder to add
Returns:
true if the placeholder was added, false if it could not be added

insert

public boolean insert(SplitDockPathProperty property,
                      int depth,
                      Dockable dockable)
Description copied from class: SplitNode
If there are elements left in property, then the next node is to be read and the insert-method of the matching child to be called.
If there are no children, then dockable has to be inserted as new child.
Otherwise this element is to be replaced by a node containing this and the a leaf with dockable.
Subclasses may wary this scheme in order to optimize or to find a better place for the dockable.

Specified by:
insert in class SplitNode
Parameters:
property - a list of nodes
depth - the index of the node that corresponds to this
dockable - the element to insert
Returns:
true if the element was inserted, false otherwise

submit

public <N> N submit(SplitTreeFactory<N> factory)
Description copied from class: SplitNode
Writes the contents of this node into a new tree create by factory.

Specified by:
submit in class SplitNode
Type Parameters:
N - the type of element the factory will create
Parameters:
factory - the factory transforming the elements of the tree into a new form.
Returns:
the representation 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

toString

public void toString(int tabs,
                     StringBuilder out)
Description copied from class: SplitNode
Writes some contents of this node into out.

Specified by:
toString in class SplitNode
Parameters:
tabs - the number of tabs that should be added before the text if a new line is necessary.
out - the container to write into