com.javadocking.dock
Class SingleDock

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.javadocking.dock.SingleDock
All Implemented Interfaces:
Dock, DockableHider, LeafDock, ExternalizeDock, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class SingleDock
extends javax.swing.JPanel
implements LeafDock, DockableHider, ExternalizeDock

This is a dock that contains zero or one dockables.

Information on using single docks is in How to Use Laef Docks in The Sanaware Developer Guide.

It is a leaf dock. It cannot contain other docks.

When it contains one dockable, it is full. When it contains no dockable, it is empty.

A dockable can be docked in this dock if:

A composite dockable can also be docked to this dock if:

If the mouse is inside the priority rectangle, the dockable can be docked with priority (see Priority.CAN_DOCK_WITH_PRIORITY). When the mouse is inside the panel of this dock, but outside the priority rectangle, the dockable can be docked without priority (see Priority.CAN_DOCK). The priority rectangle is a rectangle in the middle of the dock and retrieved with getPriorityRectangle(Rectangle).

Author:
Heidi Rakels.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static Position SINGLE_POSITION
          The only position for a dockable docked in his dock.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SingleDock()
          Constructs a single dock.
 
Method Summary
 boolean addDockable(Dockable dockableToAdd, java.awt.Point relativeLocation, java.awt.Point dockableOffset)
           Adds a dockable to this dock.
 void addDockable(Dockable dockableToAdd, Position position)
           Adds the given dockable to this dock at the given position.
 void addDockingListener(DockingListener listener)
          Adds a listener for DockingEvents of this dock.
 boolean canRemoveDockable(Dockable dockableToRemove)
          Determines if the specified dockable can be removed from this dock.
 void clearGhosts()
          Clears the ghost child docks from this dock.
 boolean containsDockable(Dockable otherDockable)
          Determines if the given dockable is docked in this dock.
 void externalizeDockable(Dockable dockableToExternalize)
          Adds the dockable to this dock.
 Dockable getDockable(int index)
          Gets the dockable with the specified index, that is docked in this dock.
 int getDockableCount()
          Gets the number of dockables that are docked in this dock.
 Position getDockablePosition(Dockable childDockable)
          Gets the position where the dockable is docked in this dock.
 int getDockPriority(Dockable dockable, java.awt.Point relativeLocation)
          Determines if the dockable can be added.
 Externalizer getExternalizer()
          Gets the externalizer that contains this externalize dock.
 int getHeaderPosition()
           Gets the position where the header of the dock is placed.
 Dockable getHiddenDockable(int index)
          Gets the dockable that is hidden in this dock with the given index.
 int getHiddenDockableCount()
          Gets the number of hidden dockables of this dock.
 CompositeDock getParentDock()
          Gets the parent dock of this dock.
protected  void getPriorityRectangle(java.awt.Rectangle rectangle)
           Computes the relative rectangle in this dock in which docking has priority.
 void hideDockable(Dockable dockableToHide)
           Hides the content of the dockable.
 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 isExternalized()
          Determines if a dockable is externalized in this dock.
 boolean isFull()
          Determines if any more dockables can be added to this dock.
 void loadProperties(java.lang.String prefix, java.util.Properties properties, java.util.Map childDocks, java.util.Map dockablesMap, java.awt.Window owner)
           Loads the properties for this dock.
 boolean moveDockable(Dockable dockableToMove, java.awt.Point relativeLocation)
          Moves a dockable to a new position in this dock.
 boolean removeDockable(Dockable dockableToRemove)
          Removes the specified dockable from this dock.
 void removeDockingListener(DockingListener listener)
          Removes a listener for docking events of this dock.
 void restoreDockable(Dockable dockableToRestore)
          Restores the dockable that is hidden.
 int retrieveDockingRectangle(Dockable dockable, java.awt.Point relativeLocation, java.awt.Point dockableOffset, java.awt.Rectangle rectangle)
          Sets the rectangle on the whole dock, if the dockable can be docked.
 void saveProperties(java.lang.String prefix, java.util.Properties properties, java.util.Map childDocks)
           Saves the properties of this dock in the given properties object.
 void setExternalizer(Externalizer externalizer)
          Sets the externalizer that contains this externalize dock.
 void setHeaderPosition(int headerPosition)
           Sets the position where the header is placed.
 void setParentDock(CompositeDock parentDock)
          Sets the specified dock as new parent dock of this dock.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLE_POSITION

public static final Position SINGLE_POSITION
The only position for a dockable docked in his dock.

Constructor Detail

SingleDock

public SingleDock()
Constructs a single dock.

Method Detail

getDockPriority

public int getDockPriority(Dockable dockable,
                           java.awt.Point relativeLocation)
Determines if the dockable can be added. It can be added if: A composite dockable can also be docked to this dock if:

Specified by:
getDockPriority in interface Dock
Parameters:
dockable - The dockable that will be added.
relativeLocation - The location where the dockable will be added.
Returns:
The integer that determines the priority for adding the dockable. If the dockable cannot be added, CANNOT_DOCK is returned. The higher the integer, the higher the priority for docking the dockable in this dock.

retrieveDockingRectangle

public int retrieveDockingRectangle(Dockable dockable,
                                    java.awt.Point relativeLocation,
                                    java.awt.Point dockableOffset,
                                    java.awt.Rectangle rectangle)
Sets the rectangle on the whole dock, if the dockable can be docked.

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.

canRemoveDockable

public boolean canRemoveDockable(Dockable dockableToRemove)
Description copied from interface: LeafDock
Determines if the specified dockable can be removed from this dock.

Specified by:
canRemoveDockable in interface LeafDock
Parameters:
dockableToRemove - The dockable that will be removed.
Returns:
True if the specified dockable can be removed from this dock, false otherwise.

removeDockable

public boolean removeDockable(Dockable dockableToRemove)
Description copied from interface: LeafDock
Removes the specified dockable from this dock.

Specified by:
removeDockable in interface LeafDock
Parameters:
dockableToRemove - The dockable that will be removed.
Returns:
True if the specified dockable was removed from 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()
Description copied from interface: Dock
Determines if any more dockables can be added to this dock.

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

getParentDock

public CompositeDock getParentDock()
Description copied from interface: Dock
Gets the parent dock of this dock.

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

setParentDock

public void setParentDock(CompositeDock parentDock)
Description copied from interface: Dock
Sets the specified dock as new parent dock of this 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 childDocks)
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.
childDocks - 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 childDocks,
                           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.
childDocks - 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.

getDockable

public Dockable getDockable(int index)
                     throws java.lang.IndexOutOfBoundsException
Description copied from interface: LeafDock
Gets the dockable with the specified index, that is docked in this dock.

Specified by:
getDockable in interface LeafDock
Parameters:
index - The index of the dockable
Returns:
The dockable with the specified index that is docked in this dock.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of range (index < 0 || index >= getDockableCount()).

getDockableCount

public int getDockableCount()
Description copied from interface: LeafDock
Gets the number of dockables that are docked in this dock.

Specified by:
getDockableCount in interface LeafDock
Returns:
The number of dockables that are docked in this dock.

containsDockable

public boolean containsDockable(Dockable otherDockable)
Description copied from interface: LeafDock
Determines if the given dockable is docked in this dock.

Specified by:
containsDockable in interface LeafDock
Parameters:
otherDockable - The dockable.
Returns:
True if if the given dockable is docked in this dock, false otherwise.

moveDockable

public boolean moveDockable(Dockable dockableToMove,
                            java.awt.Point relativeLocation)
Description copied from interface: LeafDock
Moves a dockable to a new position in this dock.

Specified by:
moveDockable in interface LeafDock
Parameters:
dockableToMove - The dockable that will be moved.
relativeLocation - The location to which the dockable will be moved, relatively to the dock.
Returns:
True if the position of the dockable changed, false otherwise.

getDockablePosition

public Position getDockablePosition(Dockable childDockable)
                             throws java.lang.IllegalArgumentException
Description copied from interface: LeafDock
Gets the position where the dockable is docked in this dock.

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

addDockable

public void addDockable(Dockable dockableToAdd,
                        Position position)
Description copied from interface: LeafDock

Adds the given dockable to this dock at the given position.

If there is already a dockable at the given position, or if the position is invalid, then the dockable is added at another position.

Specified by:
addDockable in interface LeafDock
Parameters:
dockableToAdd - The dockable to add to this dock.
position - The position of the dockable.

hideDockable

public void hideDockable(Dockable dockableToHide)
                  throws java.lang.IllegalArgumentException
Description copied from interface: DockableHider

Hides the content of the dockable. The dockable stays docked in this dock at the same position, but it has to be removed from the components of this dock.

The dock is not empty if it has a hidden dockable.

Specified by:
hideDockable in interface DockableHider
Parameters:
dockableToHide - The dockable that is docked in this dock, that has to be hidden.
Throws:
java.lang.IllegalArgumentException - If the given dockable is not docked in this dock.

getHiddenDockableCount

public int getHiddenDockableCount()
Description copied from interface: DockableHider
Gets the number of hidden dockables of this dock.

Specified by:
getHiddenDockableCount in interface DockableHider
Returns:
The number of hidden dockables of this dock.

getHiddenDockable

public Dockable getHiddenDockable(int index)
Description copied from interface: DockableHider
Gets the dockable that is hidden in this dock with the given index.

Specified by:
getHiddenDockable in interface DockableHider
Parameters:
index - The index of the hidden dockable.
Returns:
The hidden dockable, if there is one; otherwise null.

restoreDockable

public void restoreDockable(Dockable dockableToRestore)
Description copied from interface: DockableHider
Restores the dockable that is hidden.

Specified by:
restoreDockable in interface DockableHider
Parameters:
dockableToRestore - The dockable to restore

externalizeDockable

public void externalizeDockable(Dockable dockableToExternalize)
Description copied from interface: ExternalizeDock
Adds the dockable to this dock. The dockable is externalized.

Specified by:
externalizeDockable in interface ExternalizeDock
Parameters:
dockableToExternalize - The externalized dockable that is added to this dock.

getExternalizer

public Externalizer getExternalizer()
Description copied from interface: ExternalizeDock
Gets the externalizer that contains this externalize dock.

Specified by:
getExternalizer in interface ExternalizeDock
Returns:
The externalizer of this externalize dock.

setExternalizer

public void setExternalizer(Externalizer externalizer)
Description copied from interface: ExternalizeDock
Sets the externalizer that contains this externalize dock.

Specified by:
setExternalizer in interface ExternalizeDock
Parameters:
externalizer - The externalizer of this externalize dock.

isExternalized

public boolean isExternalized()
Description copied from interface: ExternalizeDock
Determines if a dockable is externalized in this dock.

Specified by:
isExternalized in interface ExternalizeDock
Returns:
True if the dockables in this dock are externalized.

clearGhosts

public void clearGhosts()
Clears the ghost child docks from this dock. The ghost child docks are removed.


getPriorityRectangle

protected void getPriorityRectangle(java.awt.Rectangle rectangle)

Computes the relative rectangle in this dock in which docking has priority. This rectangle is in the middle of the dock.

Parameters:
rectangle - The rectangle that will get the position and size of the priority rectangle for this dock.

getHeaderPosition

public int getHeaderPosition()

Gets the position where the header of the dock is placed.

It should be one of the following values:

The default value is Position.TOP.

Returns:
The position where the header is placed.

setHeaderPosition

public void setHeaderPosition(int headerPosition)

Sets the position where the header is placed.

It should be one of the following values:

Parameters:
headerPosition - The position where the header is placed.
Throws:
java.lang.IllegalArgumentException - If the given postion is not Position.TOP, Position.BOTTOM, Position.LEFT or Position.RIGHT.