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 classDefaultDockingStrategy.DockingResults
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPREFERRED_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 DockingPortcreateDockingPort(DockingPort base)Returns a newDefaultDockingPortwith characteristics similar to the specified baseDockingPort.protected DockingPortcreateDockingPortImpl(DockingPort base)javax.swing.JSplitPanecreateSplitPane(DockingPort base, java.lang.String region)Returns a newDockingSplitPanebased on the specifiedDockingPort.javax.swing.JSplitPanecreateSplitPane(DockingPort base, java.lang.String region, float percent)Returns a newDockingSplitPanebased on the specifiedDockingPort.protected javax.swing.JSplitPanecreateSplitPaneImpl(DockingPort base, java.lang.String region)booleandock(Dockable dockable, DockingPort port, java.lang.String region)Docks the specifiedDockableinto the suppliedregionof the specifiedDockingPort.booleandock(Dockable dockable, DockingPort port, java.lang.String region, DragOperation operation)Docks the specifiedDockableinto the suppliedregionof the specifiedDockingPort.protected booleandragThresholdElapsed(DragOperation token)protected DefaultDockingStrategy.DockingResultsdropComponent(Dockable dockable, DockingPort target, java.lang.String region, DragOperation token)static java.lang.StringfindRegion(java.awt.Component comp)Returns the docking region within the current split docking layout containing the specifiedComponent.protected DefaultDockingStrategy.DockingResultsfloatComponent(Dockable dockable, DockingPort target, DragOperation token)protected java.lang.StringgetCreationRegion(javax.swing.JSplitPane splitPane)doublegetDividerProportion(DockingPort port, javax.swing.JSplitPane splitPane)Returns the desired divider proportion of the specifiedJSplitPaneafter rendering.protected java.awt.ComponentgetElderComponent(javax.swing.JSplitPane splitPane)intgetInitialDividerLocation(DockingPort port, javax.swing.JSplitPane splitPane)Returns the initial divider location to be used by the specifiedJSplitPanewhen it is embedded within the specifiedDockingPort.protected static java.lang.FloatgetPreferredProportion(java.awt.Component c)protected java.lang.FloatgetPreferredProportion(javax.swing.JSplitPane splitPane, java.awt.Component controller)static DockablegetSibling(Dockable dockable)Returns the specifiedDockable'ssiblingDockablewithin the current docking layout.static DockablegetSibling(Dockable dockable, java.lang.String region)Returns the siblingDockablerelative to the specifiedDockable'ssupplied region in the current docking layout.protected booleanisDockingPossible(Dockable dockable, DockingPort port, java.lang.String region, DragOperation token)protected booleanisElderTopLeft(javax.swing.JSplitPane splitPane)protected booleanisFloatable(Dockable dockable, DragOperation token)static voidkeepConstantPercentage(boolean cstPercent)static voidsetDefaultResizeWeight(double rw)booleanundock(Dockable dockable)Undocks the specifiedDockablefrom 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'ssiblingDockablewithin the current docking layout. This method checks the parentDockingPortof a givenDockableto see if it is split equally with anotherDockable. If so, the immediate siblingDockableis returned. If there are more than twoDockableswithin the split layout, then the closest sibling region is determined and this method dispatches togetSibling(Dockable dockable, String region).If the specified
Dockableisnull, or there are no siblings available in the docking layout, then this methdo returns anullreference. If the specifiedDockableis not currently docked within aDockingPort, then this method returns anullreference.- Parameters:
dockable- theDockablewhose sibling is to be returned- Returns:
- the sibling of the specified
Dockablewithin the current docking layout. - See Also:
Dockable.getDockingPort(),getSibling(Dockable, String)
-
getSibling
public static Dockable getSibling(Dockable dockable, java.lang.String region)
Returns the siblingDockablerelative to the specifiedDockable'ssupplied region in the current docking layout. Ifdockableisnullorregionis either invalid or equal toCENTER_REGION, then this method returns anullreference.If the specified
Dockableis in aDockingPortthat equally splits the layout between twoDockablesin a fashion that matches up with the specified region, then the immediate siblingDockableis returned. Otherwise, a fuzzy search is performed throughout the docking layout for aDockablethat "looks like" it is docked to the supplied region of the specifiedDockablefrom 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_REGIONof Dockable1, Dockable3 to theSOUTH_REGIONof Dockable1, and Dockable4 to theSOUTH_REGIONof 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_REGIONsibling. 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 anullreference for theWEST_REGIONsibling of Dockable3}, since there are noDockablesin the visual layout to the west of thisDockable.- Parameters:
dockable- theDockablewhose sibling is to be returnedregion- the region of the specifiedDockablewhose visual sibling is to be returned- Returns:
- the
Dockablein 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. Ifcompisnull, then anullreference is returned. Ifcompis not in a split layout, thenCENTER_REGIONis returned.This method resolves the associated
DockableandDockingPortfor the specifiedComponentand 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- theComponentwhose 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 specifiedDockableinto the suppliedregionof 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 anullargument for theDragOperationparameter. 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 specifiedDockableinto the specifiedDockingPort.This method will return
falseifdockableorportarenull, or ifregionis not a valid region according to the specifiedDockingPort. If aDockableis currently docked within the specifiedDockingPort, then thatDockable'sterritorial properties are also checked and this method may returnfalseif the territory is blocked. Finally, this method will returnfalseif the specifiedDockableis already docked within the supplied region of the specified- Specified by:
dockin interfaceDockingStrategy- Parameters:
dockable- theDockablewe wish to dockport- theDockingPortinto which we wish to dockregion- the region of the specifiedDockingPortinto which we wish to dock.- Returns:
trueif 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 specifiedDockableinto the suppliedregionof 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 anullDragOperationargument. *The
DragOperationparameter, if present, will control the semantics of the docking operation based upon current mouse position, drag threshold, and a customizable drag contextMap. For instance, theDragOperationmay contain information regarding theDockableover which the mouse is currently hovered, whether the user is attempting to drag aDockableoutside 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
DragOperationisnull, then this method will attempt to programmatically dock the specifiedDockableinto the suppliedregionof the specifiedDockingPortwithout regard to external event-based criteria. This is in accordance with the behavior specified bydock(Dockable dockable, DockingPort port, String region). This method will returnfalseifdockableorportarenull, or ifregionis not a valid region according to the specifiedDockingPort. If aDockableis currently docked within the specifiedDockingPort, then thatDockable'sterritorial properties are also checked and this method may returnfalseif the territory is blocked. If aDragOperationis present, then this method will returnfalseif the required drag threshold has not been exceeded. Finally, this method will returnfalseif the specifiedDockableis already docked within the supplied region of the specified- Specified by:
dockin interfaceDockingStrategy- Parameters:
dockable- theDockablewe wish to dockport- theDockingPortinto which we wish to dockregion- the region of the specifiedDockingPortinto which we wish to dock.operation- theDragOperationdescribing the state of the application/mouse at the point in time in which we're attempting to dock.- Returns:
trueif 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 specifiedDockablefrom it's parentDockingPort. Ifdockableisnullor is not currently docked within aDockingPort, then this method returnsfalse.- Specified by:
undockin interfaceDockingStrategy- Parameters:
dockable- theDockableto be undocked.- Returns:
trueif the undocking operation was successful,falseotherwise.- 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 newDefaultDockingPortwith characteristics similar to the specified baseDockingPort. If the baseDockingPortis aDefaultDockingPort, then the returnedDockingPortwill share the baseDockingPort'sborder manager and tabbed drag-source flag. The returnedDockingPort'sisRoot()method will returnfalse.- Specified by:
createDockingPortin interfaceDockingStrategy- Parameters:
base- theDockingPortoff of which to base the returnedDockingPort- Returns:
- a new
DefaultDockingPortwith 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 newDockingSplitPanebased on the specifiedDockingPort. and region. Creation of theDockingSplitPaneis 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-DockingSplitPanesreturned 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
Dockablewill be docked, is not in the top or left, then the elderComponentin the split pane must be. This information is used to initialize the resize weight of the split pane, setting resize weight to1if the elder is in the top or left of the split pane and0if not. This gives the elderComponentin the resulting split pane priority in the layout with resizing the split pane.If the creation region is
NORTH_REGIONorSOUTH_REGION, the returned split pane is initialized with aVERTICAL_SPLITorientation; otherwise aHORIZONTAL_SPLITorientation 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
Componentswithin the split pane that may have their own borders.- Specified by:
createSplitPanein interfaceDockingStrategy- Parameters:
base- theDockingPortoff of which the returnedJSplitPanewill be based.region- the region within the baseDockingPortused to determine the orientation of the returnedJSplitPane.percent- the percentage used in the split.- Returns:
- a new
DockingSplitPanebased 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 newDockingSplitPanebased on the specifiedDockingPort. and region. Creation of theDockingSplitPaneis 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-DockingSplitPanesreturned 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
Dockablewill be docked, is not in the top or left, then the elderComponentin the split pane must be. This information is used to initialize the resize weight of the split pane, setting resize weight to1if the elder is in the top or left of the split pane and0if not. This gives the elderComponentin the resulting split pane priority in the layout with resizing the split pane.If the creation region is
NORTH_REGIONorSOUTH_REGION, the returned split pane is initialized with aVERTICAL_SPLITorientation; otherwise aHORIZONTAL_SPLITorientation 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
Componentswithin the split pane that may have their own borders.- Specified by:
createSplitPanein interfaceDockingStrategy- Parameters:
base- theDockingPortoff of which the returnedJSplitPanewill be based.region- the region within the baseDockingPortused to determine the orientation of the returnedJSplitPane.- Returns:
- a new
DockingSplitPanebased 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 specifiedJSplitPanewhen it is embedded within the specifiedDockingPort. It is assumed that theJSplitPaneparameter is embedded within the specifiedDockingPort, is validated, visible, and its dimensions are non-zero.This method gets the "size" of the specified
DockingPortbased on the orientation of the split pane (width for horizontal split, height for vertical split) minus theDockingPort'sinsets. 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 theDockingPortsize and the split proportion.If either
portorsplitPaneparameters arenull, then this method returns0.- Specified by:
getInitialDividerLocationin interfaceDockingStrategy- Parameters:
port- theDockingPortthat contains the specifiedJSplitPane.splitPane- theJSplitPanewhose 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 specifiedJSplitPaneafter rendering. This method assumes that theJSplitPaneparameter is, or will be embedded within the specifiedDockingPort. This method does not assume that theJSplitPanehas been validated and that it's current dimensions are non-zero.If either
portorsplitPaneparameters arenull, then this method returns the default value ofRegionChecker.DEFAULT_SIBLING_SIZE. Otherwise the "elder" component within theJSplitPaneis determined to see if it is contained within a sub-DockingPort. If the "elder"Componentcannot be determined, or it is not contained within a sub-DockingPort, then the default value ofRegionChecker.DEFAULT_SIBLING_SIZEis returned.If the "elder"
Componentis 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
Dockableis resolved for the "elder"Componentin the specifiedJSplitPaneviaDockingManager.getDockable(Component comp). If noDockablecan be found, thenRegionChecker.DEFAULT_SIBLING_SIZEis returned.Otherwise, the
DockingPortPropertySetis retrieved from the specifiedDockingPortand itsgetRegionChecker()method is called.getSiblingSize(Component c, String region)is invoked on the returnedRegionCheckerpassing the "elder"Componentin the split pane and the creation region resolved for the specifiedJSplitPane. This resolves the preferred sibling size for the elderDockablecomponent. If the elderComponentis in the top/left of the split pane, then1F-prefSizeis returned. Otherwise, the preferred sibling size is returned.- Specified by:
getDividerProportionin interfaceDockingStrategy- Parameters:
port- theDockingPortthat contains, or will contain the specifiedJSplitPane.splitPane- theJSplitPanewhose 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)
-
-