Class DefaultDockingStrategy
- java.lang.Object
-
- org.flexdock.docking.defaults.DefaultDockingStrategy
-
- All Implemented Interfaces:
DockingConstants
,DockingStrategy
public class DefaultDockingStrategy extends java.lang.Object implements DockingStrategy, DockingConstants
- Author:
- Christopher Butler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultDockingStrategy.DockingResults
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PREFERRED_PROPORTION
-
Fields inherited from interface org.flexdock.docking.DockingConstants
ACTIVE_WINDOW, BOTTOM, CENTER, CENTER_REGION, CLOSE_ACTION, DEFAULT_PERSISTENCE_KEY, DOCKING_ID, EAST_REGION, HEAVYWEIGHT_DOCKABLES, HORIZONTAL, LEFT, MOUSE_PRESSED, NORTH_REGION, PERMANENT_FOCUS_OWNER, PIN_ACTION, REGION, RIGHT, SOUTH_REGION, TOP, UNINITIALIZED, UNINITIALIZED_RATIO, UNKNOWN_REGION, UNSPECIFIED_SIBLING_PREF, VERTICAL, WEST_REGION
-
-
Constructor Summary
Constructors Constructor Description DefaultDockingStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DockingPort
createDockingPort(DockingPort base)
Returns a newDefaultDockingPort
with characteristics similar to the specified baseDockingPort
.protected DockingPort
createDockingPortImpl(DockingPort base)
javax.swing.JSplitPane
createSplitPane(DockingPort base, java.lang.String region)
Returns a newDockingSplitPane
based on the specifiedDockingPort
.javax.swing.JSplitPane
createSplitPane(DockingPort base, java.lang.String region, float percent)
Returns a newDockingSplitPane
based on the specifiedDockingPort
.protected javax.swing.JSplitPane
createSplitPaneImpl(DockingPort base, java.lang.String region)
boolean
dock(Dockable dockable, DockingPort port, java.lang.String region)
Docks the specifiedDockable
into the suppliedregion
of the specifiedDockingPort
.boolean
dock(Dockable dockable, DockingPort port, java.lang.String region, DragOperation operation)
Docks the specifiedDockable
into the suppliedregion
of the specifiedDockingPort
.protected boolean
dragThresholdElapsed(DragOperation token)
protected DefaultDockingStrategy.DockingResults
dropComponent(Dockable dockable, DockingPort target, java.lang.String region, DragOperation token)
static java.lang.String
findRegion(java.awt.Component comp)
Returns the docking region within the current split docking layout containing the specifiedComponent
.protected DefaultDockingStrategy.DockingResults
floatComponent(Dockable dockable, DockingPort target, DragOperation token)
protected java.lang.String
getCreationRegion(javax.swing.JSplitPane splitPane)
double
getDividerProportion(DockingPort port, javax.swing.JSplitPane splitPane)
Returns the desired divider proportion of the specifiedJSplitPane
after rendering.protected java.awt.Component
getElderComponent(javax.swing.JSplitPane splitPane)
int
getInitialDividerLocation(DockingPort port, javax.swing.JSplitPane splitPane)
Returns the initial divider location to be used by the specifiedJSplitPane
when it is embedded within the specifiedDockingPort
.protected static java.lang.Float
getPreferredProportion(java.awt.Component c)
protected java.lang.Float
getPreferredProportion(javax.swing.JSplitPane splitPane, java.awt.Component controller)
static Dockable
getSibling(Dockable dockable)
Returns the specifiedDockable's
siblingDockable
within the current docking layout.static Dockable
getSibling(Dockable dockable, java.lang.String region)
Returns the siblingDockable
relative to the specifiedDockable's
supplied region in the current docking layout.protected boolean
isDockingPossible(Dockable dockable, DockingPort port, java.lang.String region, DragOperation token)
protected boolean
isElderTopLeft(javax.swing.JSplitPane splitPane)
protected boolean
isFloatable(Dockable dockable, DragOperation token)
static void
keepConstantPercentage(boolean cstPercent)
static void
setDefaultResizeWeight(double rw)
boolean
undock(Dockable dockable)
Undocks the specifiedDockable
from it's parentDockingPort
.
-
-
-
Field Detail
-
PREFERRED_PROPORTION
public static final java.lang.String PREFERRED_PROPORTION
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSibling
public static Dockable getSibling(Dockable dockable)
Returns the specifiedDockable's
siblingDockable
within the current docking layout. This method checks the parentDockingPort
of a givenDockable
to see if it is split equally with anotherDockable
. If so, the immediate siblingDockable
is returned. If there are more than twoDockables
within the split layout, then the closest sibling region is determined and this method dispatches togetSibling(Dockable dockable, String region)
.If the specified
Dockable
isnull
, or there are no siblings available in the docking layout, then this methdo returns anull
reference. If the specifiedDockable
is not currently docked within aDockingPort
, then this method returns anull
reference.- Parameters:
dockable
- theDockable
whose sibling is to be returned- Returns:
- the sibling of the specified
Dockable
within the current docking layout. - See Also:
Dockable.getDockingPort()
,getSibling(Dockable, String)
-
getSibling
public static Dockable getSibling(Dockable dockable, java.lang.String region)
Returns the siblingDockable
relative to the specifiedDockable's
supplied region in the current docking layout. Ifdockable
isnull
orregion
is either invalid or equal toCENTER_REGION
, then this method returns anull
reference.If the specified
Dockable
is in aDockingPort
that equally splits the layout between twoDockables
in a fashion that matches up with the specified region, then the immediate siblingDockable
is returned. Otherwise, a fuzzy search is performed throughout the docking layout for aDockable
that "looks like" it is docked to the supplied region of the specifiedDockable
from a visual standpoint.For instance, a docking layout may consist of four quadrants Dockable1 (top-left), Dockable2 (top-right), Dockable3 (bottom-left) and Dockable4 (bottom-right). The layout is built by docking Dockable2>/i> to the
EAST_REGION
of Dockable1, Dockable3 to theSOUTH_REGION
of Dockable1, and Dockable4 to theSOUTH_REGION
of Dockable2. Within this layout, Dockable1 and Dockable3 are immediate siblings, as are Dockable2 and Dockable4. Thus, requesting sibling NORTH_REGION of Dockable3 will easily yield Dockable1. However, Dockable3 has no immediateEAST_REGION
sibling. In this case, a fuzzy search through the layout is performed to determine the visual sibling, and this method returns Dockable4. Likewise, this method will return anull
reference for theWEST_REGION
sibling of Dockable3}, since there are noDockables
in the visual layout to the west of thisDockable
.- Parameters:
dockable
- theDockable
whose sibling is to be returnedregion
- the region of the specifiedDockable
whose visual sibling is to be returned- Returns:
- the
Dockable
in the supplied region relative to the specifiedDockable
-
findRegion
public static java.lang.String findRegion(java.awt.Component comp)
Returns the docking region within the current split docking layout containing the specifiedComponent
. Ifcomp
isnull
, then anull
reference is returned. Ifcomp
is not in a split layout, thenCENTER_REGION
is returned.This method resolves the associated
Dockable
andDockingPort
for the specifiedComponent
and backtracks through the docking layout to find a split layout. If a split layout is found, then the region retured by this method is calculated relative to its sibling in the layout.- Parameters:
comp
- theComponent
whose region is to be returned- Returns:
- the region of the current split layout containing the specified
Dockable
-
dock
public boolean dock(Dockable dockable, DockingPort port, java.lang.String region)
Docks the specifiedDockable
into the suppliedregion
of the specifiedDockingPort
. This method is meant for programmatic docking, as opposed to realtime, event-based docking operations. As such, it defers processing todock(Dockable dockable, DockingPort port, String region, DragOperation token)
, passing anull
argument for theDragOperation
parameter. This implies that there is no event-based drag operation currently in progress to control the semantics of the docking operation, only that an attempt should be made to dock the specifiedDockable
into the specifiedDockingPort
.This method will return
false
ifdockable
orport
arenull
, or ifregion
is not a valid region according to the specifiedDockingPort
. If aDockable
is currently docked within the specifiedDockingPort
, then thatDockable's
territorial properties are also checked and this method may returnfalse
if the territory is blocked. Finally, this method will returnfalse
if the specifiedDockable
is already docked within the supplied region of the specified- Specified by:
dock
in interfaceDockingStrategy
- Parameters:
dockable
- theDockable
we wish to dockport
- theDockingPort
into which we wish to dockregion
- the region of the specifiedDockingPort
into which we wish to dock.- Returns:
true
if the docking operation was successful,false
. otherwise.- See Also:
dock(Dockable, DockingPort, String, DragOperation)
,Dockable.getDockingProperties()
,DockablePropertySet.isTerritoryBlocked(String)
-
dock
public boolean dock(Dockable dockable, DockingPort port, java.lang.String region, DragOperation operation)
Docks the specifiedDockable
into the suppliedregion
of the specifiedDockingPort
. This method is meant for realtime, event-based docking based on an in-progress drag operation. It is not recommended for developers to call this method programmatically, except to pass in anull
DragOperation
argument. *The
DragOperation
parameter, if present, will control the semantics of the docking operation based upon current mouse position, drag threshold, and a customizable drag contextMap
. For instance, theDragOperation
may contain information regarding theDockable
over which the mouse is currently hovered, whether the user is attempting to drag aDockable
outside the bounds of any existing windows (perhaps in an attempt to float theDockable
), or whether the current distance offset from the original drag point sufficiently warrants a valid docking operation.If the
DragOperation
isnull
, then this method will attempt to programmatically dock the specifiedDockable
into the suppliedregion
of the specifiedDockingPort
without regard to external event-based criteria. This is in accordance with the behavior specified bydock(Dockable dockable, DockingPort port, String region)
. This method will returnfalse
ifdockable
orport
arenull
, or ifregion
is not a valid region according to the specifiedDockingPort
. If aDockable
is currently docked within the specifiedDockingPort
, then thatDockable's
territorial properties are also checked and this method may returnfalse
if the territory is blocked. If aDragOperation
is present, then this method will returnfalse
if the required drag threshold has not been exceeded. Finally, this method will returnfalse
if the specifiedDockable
is already docked within the supplied region of the specified- Specified by:
dock
in interfaceDockingStrategy
- Parameters:
dockable
- theDockable
we wish to dockport
- theDockingPort
into which we wish to dockregion
- the region of the specifiedDockingPort
into which we wish to dock.operation
- theDragOperation
describing the state of the application/mouse at the point in time in which we're attempting to dock.- Returns:
true
if the docking operation was successful,false
. otherwise.- See Also:
dock(Dockable, DockingPort, String, DragOperation)
,Dockable.getDockingProperties()
,DockablePropertySet.isTerritoryBlocked(String)
-
dragThresholdElapsed
protected boolean dragThresholdElapsed(DragOperation token)
-
isDockingPossible
protected boolean isDockingPossible(Dockable dockable, DockingPort port, java.lang.String region, DragOperation token)
-
isFloatable
protected boolean isFloatable(Dockable dockable, DragOperation token)
-
dropComponent
protected DefaultDockingStrategy.DockingResults dropComponent(Dockable dockable, DockingPort target, java.lang.String region, DragOperation token)
-
undock
public boolean undock(Dockable dockable)
Undocks the specifiedDockable
from it's parentDockingPort
. Ifdockable
isnull
or is not currently docked within aDockingPort
, then this method returnsfalse
.- Specified by:
undock
in interfaceDockingStrategy
- Parameters:
dockable
- theDockable
to be undocked.- Returns:
true
if the undocking operation was successful,false
otherwise.- See Also:
dock(Dockable, DockingPort, String)
-
floatComponent
protected DefaultDockingStrategy.DockingResults floatComponent(Dockable dockable, DockingPort target, DragOperation token)
-
createDockingPort
public DockingPort createDockingPort(DockingPort base)
Returns a newDefaultDockingPort
with characteristics similar to the specified baseDockingPort
. If the baseDockingPort
is aDefaultDockingPort
, then the returnedDockingPort
will share the baseDockingPort's
border manager and tabbed drag-source flag. The returnedDockingPort's
isRoot()
method will returnfalse
.- Specified by:
createDockingPort
in interfaceDockingStrategy
- Parameters:
base
- theDockingPort
off of which to base the returnedDockingPort
- Returns:
- a new
DefaultDockingPort
with characteristics similar to the specified baseDockingPort
. - See Also:
DefaultDockingPort.getBorderManager()
,DefaultDockingPort.setBorderManager(BorderManager)
,DefaultDockingPort.isTabsAsDragSource()
,DefaultDockingPort.setTabsAsDragSource(boolean)
,DefaultDockingPort.setRoot(boolean)
-
createDockingPortImpl
protected DockingPort createDockingPortImpl(DockingPort base)
-
createSplitPane
public javax.swing.JSplitPane createSplitPane(DockingPort base, java.lang.String region, float percent)
Returns a newDockingSplitPane
based on the specifiedDockingPort
. and region. Creation of theDockingSplitPane
is deferred to an internal protected method to allow for overriding by subclasses. A client property is set on the returned split pane with the key DockingConstants.REGION to indicate the creation region of the split pane for non-DockingSplitPanes
returned by overriding subclasses.This method determines the "elder" component of the split pane by checking whether the new creation region is in the TOP or LEFT (NORTH_REGION or WEST_REGION). If the creation region, representing where the new
Dockable
will be docked, is not in the top or left, then the elderComponent
in the split pane must be. This information is used to initialize the resize weight of the split pane, setting resize weight to1
if the elder is in the top or left of the split pane and0
if not. This gives the elderComponent
in the resulting split pane priority in the layout with resizing the split pane.If the creation region is
NORTH_REGION
orSOUTH_REGION
, the returned split pane is initialized with aVERTICAL_SPLIT
orientation; otherwise aHORIZONTAL_SPLIT
orientation is used.Before returning, the border is removed from the split pane, its divider size is set to 3, and if possible the border is removed from the split pane divider. This is to avoid an excessive compound border effect for embedded
Components
within the split pane that may have their own borders.- Specified by:
createSplitPane
in interfaceDockingStrategy
- Parameters:
base
- theDockingPort
off of which the returnedJSplitPane
will be based.region
- the region within the baseDockingPort
used to determine the orientation of the returnedJSplitPane
.percent
- the percentage used in the split.- Returns:
- a new
DockingSplitPane
based on the specifiedDockingPort
. and region. - See Also:
DockingSplitPane(DockingPort, String)
,createSplitPaneImpl(DockingPort, String)
,JSplitPane.setResizeWeight(double)
-
createSplitPane
public javax.swing.JSplitPane createSplitPane(DockingPort base, java.lang.String region)
Returns a newDockingSplitPane
based on the specifiedDockingPort
. and region. Creation of theDockingSplitPane
is deferred to an internal protected method to allow for overriding by subclasses. A client property is set on the returned split pane with the key DockingConstants.REGION to indicate the creation region of the split pane for non-DockingSplitPanes
returned by overriding subclasses.This method determines the "elder" component of the split pane by checking whether the new creation region is in the TOP or LEFT (NORTH_REGION or WEST_REGION). If the creation region, representing where the new
Dockable
will be docked, is not in the top or left, then the elderComponent
in the split pane must be. This information is used to initialize the resize weight of the split pane, setting resize weight to1
if the elder is in the top or left of the split pane and0
if not. This gives the elderComponent
in the resulting split pane priority in the layout with resizing the split pane.If the creation region is
NORTH_REGION
orSOUTH_REGION
, the returned split pane is initialized with aVERTICAL_SPLIT
orientation; otherwise aHORIZONTAL_SPLIT
orientation is used.Before returning, the border is removed from the split pane, its divider size is set to 3, and if possible the border is removed from the split pane divider. This is to avoid an excessive compound border effect for embedded
Components
within the split pane that may have their own borders.- Specified by:
createSplitPane
in interfaceDockingStrategy
- Parameters:
base
- theDockingPort
off of which the returnedJSplitPane
will be based.region
- the region within the baseDockingPort
used to determine the orientation of the returnedJSplitPane
.- Returns:
- a new
DockingSplitPane
based on the specifiedDockingPort
. and region. - See Also:
DockingSplitPane(DockingPort, String)
,createSplitPaneImpl(DockingPort, String)
,JSplitPane.setResizeWeight(double)
-
createSplitPaneImpl
protected javax.swing.JSplitPane createSplitPaneImpl(DockingPort base, java.lang.String region)
-
getInitialDividerLocation
public int getInitialDividerLocation(DockingPort port, javax.swing.JSplitPane splitPane)
Returns the initial divider location to be used by the specifiedJSplitPane
when it is embedded within the specifiedDockingPort
. It is assumed that theJSplitPane
parameter is embedded within the specifiedDockingPort
, is validated, visible, and its dimensions are non-zero.This method gets the "size" of the specified
DockingPort
based on the orientation of the split pane (width for horizontal split, height for vertical split) minus theDockingPort's
insets. It then dispatches togetDividerProportion(DockingPort port, JSplitPane splitPane)
to determine the preferred proportion of the split pane divider. The returned value for this method is the product of theDockingPort
size and the split proportion.If either
port
orsplitPane
parameters arenull
, then this method returns0
.- Specified by:
getInitialDividerLocation
in interfaceDockingStrategy
- Parameters:
port
- theDockingPort
that contains the specifiedJSplitPane
.splitPane
- theJSplitPane
whose initial divider location is to be determined.- Returns:
- the desired divider location of the supplied
JSplitPane
. - See Also:
DockingStrategy.getInitialDividerLocation(DockingPort, JSplitPane)
,getDividerProportion(DockingPort, JSplitPane)
-
getDividerProportion
public double getDividerProportion(DockingPort port, javax.swing.JSplitPane splitPane)
Returns the desired divider proportion of the specifiedJSplitPane
after rendering. This method assumes that theJSplitPane
parameter is, or will be embedded within the specifiedDockingPort
. This method does not assume that theJSplitPane
has been validated and that it's current dimensions are non-zero.If either
port
orsplitPane
parameters arenull
, then this method returns the default value ofRegionChecker.DEFAULT_SIBLING_SIZE
. Otherwise the "elder" component within theJSplitPane
is determined to see if it is contained within a sub-DockingPort
. If the "elder"Component
cannot be determined, or it is not contained within a sub-DockingPort
, then the default value ofRegionChecker.DEFAULT_SIBLING_SIZE
is returned.If the "elder"
Component
is successfully resolved inside a sub-DockingPort
, then a check is done on the sub-port for the client propertyDefaultDockingStrategy.PREFERRED_PROPORTION
. If this value is found, then the primitive float version of it is returned.Failing these checks, the
Dockable
is resolved for the "elder"Component
in the specifiedJSplitPane
viaDockingManager.getDockable(Component comp)
. If noDockable
can be found, thenRegionChecker.DEFAULT_SIBLING_SIZE
is returned.Otherwise, the
DockingPortPropertySet
is retrieved from the specifiedDockingPort
and itsgetRegionChecker()
method is called.getSiblingSize(Component c, String region)
is invoked on the returnedRegionChecker
passing the "elder"Component
in the split pane and the creation region resolved for the specifiedJSplitPane
. This resolves the preferred sibling size for the elderDockable
component. If the elderComponent
is in the top/left of the split pane, then1F-prefSize
is returned. Otherwise, the preferred sibling size is returned.- Specified by:
getDividerProportion
in interfaceDockingStrategy
- Parameters:
port
- theDockingPort
that contains, or will contain the specifiedJSplitPane
.splitPane
- theJSplitPane
whose initial divider location is to be determined.- Returns:
- the desired divider proportion of the supplied
JSplitPane
. - See Also:
RegionChecker.DEFAULT_SIBLING_SIZE
,PREFERRED_PROPORTION
,DockingManager.getDockable(Component)
,RegionChecker.getSiblingSize(Component, String)
-
getCreationRegion
protected java.lang.String getCreationRegion(javax.swing.JSplitPane splitPane)
-
isElderTopLeft
protected boolean isElderTopLeft(javax.swing.JSplitPane splitPane)
-
getPreferredProportion
protected java.lang.Float getPreferredProportion(javax.swing.JSplitPane splitPane, java.awt.Component controller)
-
getElderComponent
protected java.awt.Component getElderComponent(javax.swing.JSplitPane splitPane)
-
getPreferredProportion
protected static java.lang.Float getPreferredProportion(java.awt.Component c)
-
setDefaultResizeWeight
public static void setDefaultResizeWeight(double rw)
-
keepConstantPercentage
public static void keepConstantPercentage(boolean cstPercent)
-
-