com.javadocking.dock
Class FloatDock

java.lang.Object
  extended by com.javadocking.dock.FloatDock
All Implemented Interfaces:
CompositeDock, Dock
Direct Known Subclasses:
HidableFloatDock

public class FloatDock
extends java.lang.Object
implements CompositeDock

This special dock contains all the floating dockables. It is a composite dock. The child docks are put in a dialog (javaw.swing.JDialog) and are floating on the screen.

Information on using float docks is in How to Use Composite Docks in The Sanaware Developer Guide.

A dockable can be added to this dock if

When a dockable is added, a child dock is created with the 'childDockFactory'. The dockable is added to the child dock. The child dock is put in a floating window.

There is an order for the floating child docks. Children with a lower index are on top of children with a higher index.

The parent dock of the float dock is always null. The float dock has a owner window. This is the window that that will be the owner of the dialogs that contain the child docks.

Author:
Heidi Rakels.

Field Summary
 
Fields inherited from interface com.javadocking.dock.CompositeDock
CHILD_DOCK_PREFIX
 
Constructor Summary
FloatDock()
          Constructs a float dock with no owner and a SplitDockFactory as factory for the child docks.
FloatDock(java.awt.Window owner)
          Constructs a float dock with the given window as owner for the child dock windows and a SplitDockFactory as factory for creating child docks.
FloatDock(java.awt.Window owner, DockFactory childDockFactory)
          Constructs a float dock with the given window as owner for the child dock windows and the given factory for the child docks.
 
Method Summary
 void addChildDock(Dock dock, java.awt.Point location, java.awt.Dimension size)
           Adds the given dock as child dock to this dock.
 void addChildDock(Dock dock, Position position)
          Adds the child dock to the given position.
 boolean addDockable(Dockable dockableToAdd, java.awt.Point relativeLocation, java.awt.Point dockableOffset)
           Adds a dockable to this dock.
 void addDockingListener(DockingListener listener)
          Adds a listener for DockingEvents of this dock.
 void addWindowFocusListener(java.awt.event.WindowFocusListener windowFocusListener)
          Adds the listener that will listen to the window focus events of all the floating windows created by this class.
 void clearGhosts()
          Clears the ghost child docks from this dock.
 void emptyChild(Dock childDock)
          Is called when the specified child dock is empty.
 Dock getChildDock(int index)
          Gets the child dock with the specified index.
 int getChildDockCount()
          Gets the number of child docks of this dock.
 DockFactory getChildDockFactory()
          Gets the factory that creates the child docks for this composite dock.
 Position getChildDockPosition(Dock childDock)
          Gets the position, where the child dock is docked in this dock.
protected  java.util.Map getChildDockWindows()
           
protected  void getDefaultFloatingWindowLocation(java.awt.Point location)
          Moves the location inside the screen where the floating window has to be placed.
 int getDockPriority()
          Gets the dock priority for a floatable dockable that will be added to this float dock.
 int getDockPriority(Dockable dockableToAdd, java.awt.Point relativeLocation)
           Determines if the dockable can be added.
 java.awt.Window getOwner()
          Gets the window that owns the floating windows created by this dock.
 CompositeDock getParentDock()
          Always returns null, because this dock can't have a parent dock.
 void ghostChild(Dock childDock)
          Makes the given empty child dock invisible.
 boolean isEmpty()
          Determines if this dock doesn't have any dockables docked in it, or doesn't have any child docks docked in it.
 boolean isFull()
          Always returns false, because it is never full.
 void loadProperties(java.lang.String prefix, java.util.Properties properties, java.util.Map newChildDocks, java.util.Map dockablesMap, java.awt.Window owner)
           Loads the properties for this dock.
 void moveDock(Dock childDock, java.awt.Point relativeLocation, java.awt.Point dockableOffset)
          Moves the given child dock to the new location.
 void removeDockingListener(DockingListener listener)
          Removes a listener for docking events of this dock.
 void removeWindowFocusListener(java.awt.event.WindowFocusListener windowFocusListener)
          Removes the given listener.
 int retrieveDockingRectangle(Dockable dockable, java.awt.Point relativeLocation, java.awt.Point dockableOffset, java.awt.Rectangle rectangle)
           Sets the given rectangle to the position and size of the graphical content component of the dockable, when it will be docked in this dock.
 void saveProperties(java.lang.String prefix, java.util.Properties properties, java.util.Map childDockIds)
           Saves the properties of this dock in the given properties object.
 void setChildDockFactory(DockFactory childDockFactory)
          Sets the factory that creates the child docks for this composite dock.
 void setDockPriority(int dockPriority)
          Sets the dock priority for a floatable dockable that will be added to the float dock.
 void setOwner(java.awt.Window owner)
          Sets the window that owns the floating windows created by this dock.
 void setParentDock(CompositeDock parentDock)
          Does nothing, because this dock can't have a parent dock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FloatDock

public FloatDock()
Constructs a float dock with no owner and a SplitDockFactory as factory for the child docks.


FloatDock

public FloatDock(java.awt.Window owner)
Constructs a float dock with the given window as owner for the child dock windows and a SplitDockFactory as factory for creating child docks.

Parameters:
owner - The window that owns the floating windows created by this dock.

FloatDock

public FloatDock(java.awt.Window owner,
                 DockFactory childDockFactory)
Constructs a float dock with the given window as owner for the child dock windows and the given factory for the child docks.

Parameters:
owner - The window that owns the floating windows created by this dock.
childDockFactory - The factory for creating child docks.
Method Detail

getDockPriority

public int getDockPriority(Dockable dockableToAdd,
                           java.awt.Point relativeLocation)

Determines if the dockable can be added.

It can be added if

When the dockable can be added the value of the property dockPriority is returned.

Specified by:
getDockPriority in interface Dock
Parameters:
dockableToAdd - The dockable that will be added.
relativeLocation - The location where the dockable will be added.
Returns:
When the dockable can be added the value of the property dockPriority is returned, otherwise Priority.CANNOT_DOCK.

retrieveDockingRectangle

public int retrieveDockingRectangle(Dockable dockable,
                                    java.awt.Point relativeLocation,
                                    java.awt.Point dockableOffset,
                                    java.awt.Rectangle rectangle)
Description copied from interface: Dock

Sets the given rectangle to the position and size of the graphical content component of the dockable, when it will be docked in this dock.

Determines if the dockable can be added to this dock. If the dockable cannot be added, it returns Priority.CANNOT_DOCK and the given rectangle is not changed.

Specified by:
retrieveDockingRectangle in interface Dock
Parameters:
dockable - The dockable that will be added.
relativeLocation - The location where the dockable will be added.
dockableOffset - The mouse location where the dragging started, relatively to the previous dock of the dockable.
rectangle - This rectangle will be set to the location and size of the graphical component of the dockable when it will be docked in this dock. The rectangle is relative to this dock.
Returns:
If the dockable cannot be added, Priority.CANNOT_DOCK is returned, otherwise a positive integer.

addDockable

public boolean addDockable(Dockable dockableToAdd,
                           java.awt.Point relativeLocation,
                           java.awt.Point dockableOffset)
Description copied from interface: Dock

Adds a dockable to this dock.

First it determines if the dockable can be added with Dock.getDockPriority(Dockable, Point). If this method returns CANNOT_DOCK, the dockable is not added.

Specified by:
addDockable in interface Dock
Parameters:
dockableToAdd - The dockable that will be added.
relativeLocation - The location where the dockable will be added.
dockableOffset - The mouse location where the dragging started, relatively to the previous dock of the dockable.
Returns:
True if the dockable was added to this dock, false otherwise.

isEmpty

public boolean isEmpty()
Description copied from interface: Dock
Determines if this dock doesn't have any dockables docked in it, or doesn't have any child docks docked in it.

Specified by:
isEmpty in interface Dock
Returns:
True if this dock doesn't have any dockables docked in it, or doesn't have any child docks docked in it, false otherwise.

isFull

public boolean isFull()
Always returns false, because it is never full.

Specified by:
isFull in interface Dock
Returns:
True if any more dockables can be added to this dock, false otherwise.

getParentDock

public CompositeDock getParentDock()
Always returns null, because this dock can't have a parent dock.

Specified by:
getParentDock in interface Dock
Returns:
The parent dock of this dock.

setParentDock

public void setParentDock(CompositeDock parentDock)
Does nothing, because this dock can't have a parent dock.

Specified by:
setParentDock in interface Dock
Parameters:
parentDock - The parent dock of this dock.

saveProperties

public void saveProperties(java.lang.String prefix,
                           java.util.Properties properties,
                           java.util.Map childDockIds)
Description copied from interface: Dock

Saves the properties of this dock in the given properties object.

The property names for this dock should start with the given prefix.

Specified by:
saveProperties in interface Dock
Parameters:
prefix - The prefix for the property names.
properties - The properties object to which the properties should be added.
childDockIds - A mapping between the child docks that are already saved and the keys that are used for the save.
  • map key: a child dock that is already saved (Dock).
  • map value: the key that is used for saving the dock (java.lang.String).

loadProperties

public void loadProperties(java.lang.String prefix,
                           java.util.Properties properties,
                           java.util.Map newChildDocks,
                           java.util.Map dockablesMap,
                           java.awt.Window owner)
                    throws java.io.IOException
Description copied from interface: Dock

Loads the properties for this dock. The properties can be found in the given properties object. The property names for this dock start with the given prefix.

The dockables that should be docked in this dock are added to this dock. They can be found in the given dockables mapping. The docks that should be docked inside this dock are added to this dock. They can be found in the given childDocks mapping.

This method should be called after the empty constructor to create the content of the dock. Don't call this method for a dock that already has a content.

Specified by:
loadProperties in interface Dock
Parameters:
prefix - The prefix of the names of the properties that have been intended for this dock.
properties - The properties object that contains the properties for this dock. It can contain also properties for other objects, but they will have another prefix.
newChildDocks - A mapping between the dock keys of the child docks that are already loaded and the docks.
  • map key: the key that is used for saving the dock (java.lang.String).
  • map value: a child dock that is already loaded (Dock).
dockablesMap - A mapping that contains the available dockables.
  • map key: the ID of the dockable (java.lang.String).
  • map value: the dockable (Dockable).
owner - The owner window of the dock in the dock model (DockModel).
Throws:
java.io.IOException - If an error occures while decoding the properties.

addDockingListener

public void addDockingListener(DockingListener listener)
Description copied from interface: Dock
Adds a listener for DockingEvents of this dock. The listener will be informed before and after adding, moving or removing dockables or child docks from this dock.

Specified by:
addDockingListener in interface Dock
Parameters:
listener - A docking listener that will be notified when a dockable or child dock is added, moved, or removed.

removeDockingListener

public void removeDockingListener(DockingListener listener)
Description copied from interface: Dock
Removes a listener for docking events of this dock.

Specified by:
removeDockingListener in interface Dock
Parameters:
listener - The docking listener to remove.

emptyChild

public void emptyChild(Dock childDock)
Description copied from interface: CompositeDock
Is called when the specified child dock is empty. Normally this child dock will be removed.

Specified by:
emptyChild in interface CompositeDock
Parameters:
childDock - The child dock that is empty.

ghostChild

public void ghostChild(Dock childDock)
Description copied from interface: CompositeDock
Makes the given empty child dock invisible. It may not be removed, because there are still listeners attached to the child dock, that are currently dragging the dockable. The dock is becoming a ghost. It is still there, but it is invisible.

Specified by:
ghostChild in interface CompositeDock
Parameters:
childDock - The child dock that is empty, but not may be removed.

clearGhosts

public void clearGhosts()
Description copied from interface: CompositeDock
Clears the ghost child docks from this dock. The ghost child docks are removed.

Specified by:
clearGhosts in interface CompositeDock

getChildDockCount

public int getChildDockCount()
Description copied from interface: CompositeDock
Gets the number of child docks of this dock.

Specified by:
getChildDockCount in interface CompositeDock
Returns:
The number of child docks of this dock.

getChildDock

public Dock getChildDock(int index)
                  throws java.lang.IndexOutOfBoundsException
Description copied from interface: CompositeDock
Gets the child dock with the specified index.

Specified by:
getChildDock in interface CompositeDock
Parameters:
index - The index of the child dock.
Returns:
The child dock with the specified index.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of range (index < 0 || index >= getChildDockCount()).

getChildDockPosition

public Position getChildDockPosition(Dock childDock)
                              throws java.lang.IllegalArgumentException
Description copied from interface: CompositeDock
Gets the position, where the child dock is docked in this dock.

Specified by:
getChildDockPosition in interface CompositeDock
Parameters:
childDock - The dockable that is docked in this dock.
Returns:
The position where the child dock is docked in this dock. Not null.
Throws:
java.lang.IllegalArgumentException - If the given dock is not docked in this dock.

addChildDock

public void addChildDock(Dock dock,
                         Position position)
                  throws java.lang.IllegalStateException
Adds the child dock to the given position. The position has normally 3 dimensions.

Specified by:
addChildDock in interface CompositeDock
Parameters:
dock - The child dock that is added to this float dock in a dialog.
position - The position for the child dock with 3 dimensions:
  • The first dimension value will be the x-position of the dialog
  • The second dimension value will be the y-position of the dialog
  • The third dimension value will be the z-order of the dialog
Throws:
java.lang.IllegalStateException - If the dock is full.

getChildDockFactory

public DockFactory getChildDockFactory()
Description copied from interface: CompositeDock
Gets the factory that creates the child docks for this composite dock.

Specified by:
getChildDockFactory in interface CompositeDock
Returns:
The factory that creates the child docks for this composite dock.

setChildDockFactory

public void setChildDockFactory(DockFactory childDockFactory)
Description copied from interface: CompositeDock
Sets the factory that creates the child docks for this composite dock.

Specified by:
setChildDockFactory in interface CompositeDock
Parameters:
childDockFactory - The factory that creates the child docks for this composite dock.

getOwner

public java.awt.Window getOwner()
Gets the window that owns the floating windows created by this dock.

Returns:
The window that owns the floating windows created by this dock.

setOwner

public void setOwner(java.awt.Window owner)
Sets the window that owns the floating windows created by this dock.

Parameters:
owner - The window that owns the floating windows created by this dock.

getChildDockWindows

protected java.util.Map getChildDockWindows()

getDockPriority

public int getDockPriority()
Gets the dock priority for a floatable dockable that will be added to this float dock.

Returns:
The dock priority for a floatable dockable that will be added to the float dock.

setDockPriority

public void setDockPriority(int dockPriority)
Sets the dock priority for a floatable dockable that will be added to the float dock.

Parameters:
dockPriority - The dock priority for a floatable dockable that will be added to the float dock.

addWindowFocusListener

public void addWindowFocusListener(java.awt.event.WindowFocusListener windowFocusListener)
Adds the listener that will listen to the window focus events of all the floating windows created by this class.

Parameters:
windowFocusListener - The listener that will listen to the window focus events of all the floating windows created by this class.

removeWindowFocusListener

public void removeWindowFocusListener(java.awt.event.WindowFocusListener windowFocusListener)
Removes the given listener.

Parameters:
windowFocusListener - The listener that listens to the window focus events of all the floating windows created by this class.

moveDock

public void moveDock(Dock childDock,
                     java.awt.Point relativeLocation,
                     java.awt.Point dockableOffset)
Moves the given child dock to the new location.

Parameters:
childDock - The child dock that has to be moved to the new location.
relativeLocation - The new location for the child dock.
dockableOffset - The mouse location where the dragging started, relatively to the child dock.

addChildDock

public void addChildDock(Dock dock,
                         java.awt.Point location,
                         java.awt.Dimension size)

Adds the given dock as child dock to this dock.

The dock is put in a dialog. This dialog is created with the method SwComponentFactory.createJDialog(Window) of the component factory of the DockingManager.

There is a border set around the dock. This border is created with the method SwComponentFactory.createFloatingBorder() of the component factory of the docking manager.

The floating window is put at the given location. The window will have the given size. If this size is null, then the preferred size is taken.

Parameters:
dock - The child dock that is added to this float dock in a floating dialog.
location - The location for the dialog.
size - The size for the dialog. This may be null. In that case the preferred size is taken.

getDefaultFloatingWindowLocation

protected void getDefaultFloatingWindowLocation(java.awt.Point location)
Moves the location inside the screen where the floating window has to be placed.

Parameters:
location - The location where the floating window will be put, if the requested location is outside the screen.