Class DockingUtility
- java.lang.Object
-
- org.flexdock.util.DockingUtility
-
- All Implemented Interfaces:
DockingConstants
public class DockingUtility extends java.lang.Object implements DockingConstants
- Author:
- Christopher Butler
-
-
Field Summary
-
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
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleandockRelative(Dockable dockable, Dockable parent, java.lang.String relativeRegion)Docks the specifiedDockablerelative to another already-dockedDockablein the specified region.static booleandockRelative(Dockable dockable, Dockable parent, java.lang.String relativeRegion, float ratio)Docks the specifiedDockablerelative to another already-dockedDockablein the specified region with the specified split proportion.static DockingPortfindDockingPort(java.awt.Container container, java.awt.Point location)Returns the deepestDockingPortwithin the specifiedContainerat the specifiedlocation.static java.lang.StringflipRegion(java.lang.String region)Returns the opposite docking region of the specifiedregion.static DockablegetAncestorDockable(java.awt.Component comp)static intgetMinimizedConstraint(Dockable dockable)Returns anintvalue representing the current minimization constraint for the specifiedDockable.static DockingPortgetParentDockingPort(java.awt.Component comp)Returns theDockingPortthat contains the specifiedComponent.static DockingPortgetParentDockingPort(Dockable d)Returns theDockingPortthat contains the specifiedDockable.static java.lang.StringgetRegion(int regionType)Returns theStringdocking region for the specified orientation constant.static java.lang.StringgetTabText(Dockable dockable)Returns the text to be used by aDockableas a tab label within a tabbed layout.static booleanisActive(Dockable dockable)static booleanisAxisEquivalent(java.lang.String region, java.lang.String otherRegion)Tests for region equivalency between the specified region parameters across horizontal and vertical axes.static booleanisDockable(java.lang.Object obj)Returnstrueif the specificObjectis aDockable.static booleanisEmbedded(Dockable dockable)Returnstrueif the specifiedDockableis currently docked within aDockingPort.static booleanisFloating(Dockable dockable)Returnstrueif the specifiedDockableis currently docked within a floating dialog.static booleanisMinimized(Dockable dockable)Returnstrueif the specifiedDockableis currently minimized;falseotherwise.static booleanisRegionTopLeft(java.lang.String region)Returnstrueif the specifiedregionis equal to eitherNORTH_REGIONorWEST_REGION.static booleanisSubport(DockingPort dockingPort)Returnstrueif the specifiedDockingPorthas an ancestorDockingPort;falseotherwise.static voidsetSplitProportion(Dockable dockable, float proportion)Sets the divider location of the split layout containing the specified dockableComponent.static voidsetSplitProportion(DockingPort port, float proportion)Sets the divider location of the split layout embedded within the specifiedDockingPort.static java.lang.StringtranslateRegionAxis(javax.swing.JSplitPane splitPane, java.lang.String region)Returns the specifiedregion'scross-axis equivalent region in accordance with the orientation used by the specifiedJSplitPane.
-
-
-
Method Detail
-
getParentDockingPort
public static DockingPort getParentDockingPort(Dockable d)
Returns theDockingPortthat contains the specifiedDockable. If theDockableisnull, then anullreference is returned.This method will only return the immediate parent
DockingPortof the specifiedDockableThis means that a check is performed for theComponentreturned by theDockable'sgetComponent()method. TheDockingPortreturned by this method will not only be an ancestorContainerof thisComponent, but invoking theDockingPort'sisParentDockingPort(Component comp)with the thisComponentwill also returntrue. If both of these conditions cannot be satisfied, then this method returns anullreference.- Parameters:
d- theDockablewhose parentDockingPortis to be returned.- Returns:
- the imediate parent
DockingPortthat contains the specifiedDockable. - See Also:
getParentDockingPort(Component)
-
getParentDockingPort
public static DockingPort getParentDockingPort(java.awt.Component comp)
Returns theDockingPortthat contains the specifiedComponent. If theComponentisnull, then anullreference is returned.This method will only return the immediate parent
DockingPortof the specifiedComponentThis means that theDockingPortreturned by this method will not only be an ancestorContainerof the specifiedComponent, but invoking itsisParentDockingPort(Component comp)with the specifiedComponentwill also returntrue. If both of these conditions cannot be satisfied, then this method returns anullreference.- Parameters:
comp- theComponentwhose parentDockingPortis to be returned.- Returns:
- the immediate parent
DockingPortthat contains the specifiedComponent.
-
isSubport
public static boolean isSubport(DockingPort dockingPort)
Returnstrueif the specifiedDockingPorthas an ancestorDockingPort;falseotherwise. If the specifiedDockingPortisnull, then this method returnsfalse.- Parameters:
dockingPort- theDockingPortto check for an ancestor port- Returns:
trueif the specifiedDockingPorthas an ancestorDockingPort;falseotherwise.- See Also:
SwingUtilities.getAncestorOfClass(java.lang.Class, java.awt.Component)
-
findDockingPort
public static DockingPort findDockingPort(java.awt.Container container, java.awt.Point location)
Returns the deepestDockingPortwithin the specifiedContainerat the specifiedlocation. If eithercontainerorlocationarenull, then this method returnsnull.This method will find the deepest
Componentwithin the specified container that the specifiedPointviaSwingUtilities.getDeepestComponentAt(Component parent, int x, int y). If noComponentis resovled, then this method returnsnull. If the resolvedComponentis aDockingPort, then it is returned. Otherwise, theComponent'sDockingPortancestor is resovled and returned fromSwingUtilities.getAncestorOfClass(Class c, Component comp), passingDockingPort.classfor the ancestor class parameter.- Parameters:
container- theContainerwithin which to find aDockingPort.location- the point within the specifiedContainerat which to search for aDockingPort.- Returns:
- the deepest
DockingPortwithin the specifiedContainerat the specifiedlocation. - See Also:
SwingUtilities.getDeepestComponentAt(java.awt.Component, int, int),SwingUtilities.getAncestorOfClass(java.lang.Class, java.awt.Component)
-
translateRegionAxis
public static java.lang.String translateRegionAxis(javax.swing.JSplitPane splitPane, java.lang.String region)Returns the specifiedregion'scross-axis equivalent region in accordance with the orientation used by the specifiedJSplitPane. If theJSplitPaneisnull, or the specifiedregionis invalid according toDockingManager.isValidDockingRegion(String region), then this method returnsnull.NORTH_REGIONandSOUTH_REGIONare considered "vertical" regions, whileWEST_REGIONandEAST_REGIONare considered horizontal regions. If theJSplitPaneorientation matches the specifiedregionorientation, then the originalregionvalue is returned. For instance, if the specifiedregionisEAST_REGION, and theJSplitPaneis of a horizontal orientation, then there is no need to translate theregionparameter across axes since its current axis is already horizontal. In this case,EAST_REGIONwould be returned by this method.If the axis of the specified
regiondoes not match the orientation of theJSplitPane, then the region is translated to its cross-axis equivalent and returns. In this case,NORTH_REGIONwill be translated toWEST_REGION,SOUTH_REGIONtoEAST_REGION,WEST_REGIONtoNORTH_REGION, andEAST_REGIONtoSOUTH_REGION.CENTER_REGIONis never altered.- Parameters:
splitPane- theJSplitPanewhose orientation is to be used as a target axisregion- the docking region to translate to the target axis- Returns:
- the specified
region'scross-axis equivalent region in accordance with the orientation used by the specifiedJSplitPane. - See Also:
DockingManager.isValidDockingRegion(String),JSplitPane.getOrientation(),isAxisEquivalent(String, String)
-
flipRegion
public static java.lang.String flipRegion(java.lang.String region)
Returns the opposite docking region of the specifiedregion. ForNORTH_REGION, this method returnsSOUTH_REGION. ForSOUTH_REGION, this method returnsNORTH_REGION. ForEAST_REGION, this method returnsWEST_REGION. ForWEST_REGION, this method returnsEAST_REGION. ForCENTER_REGIONor an invalid region, as specified byDockingManager.isValidDockingRegion(String region), this method returnCENTER_REGION.- Parameters:
region- the region whose opposite is to be returned.- Returns:
- the opposite docking region of the specified
region. - See Also:
DockingManager.isValidDockingRegion(String)
-
isAxisEquivalent
public static boolean isAxisEquivalent(java.lang.String region, java.lang.String otherRegion)Tests for region equivalency between the specified region parameters across horizontal and vertical axes. If eitherregionorotherRegionarenullor invalid according toDockingManager.isValidDockingRegion(String region), then this method returnsfalse.Equivalency within the same axis means that the two specified regions are the same value, as each region is unique within its axis. Thus, this method returns
trueifregion.equals(otherRegion)returnstrue. This includesCENTER_REGION, which is axis independent.CENTER_REGIONis not an axis equivalent to any region other than itself since it is the only docking region that does not correspond to a horizontal or vertical axis. If either the specifiedregionorotherRegionisCENTER_REGIONand the other is not, then this method returnsfalse.Equivalancy across axes follows a top-to-left and bottom-to-right mapping. In this fashion,
NORTH_REGIONandWEST_REGIONare equivalent andSOUTH_REGIONandEAST_REGIONare equivalent. These combination will returntruefor this method. All other region combinatinos will cause this method to returnfalse.- Parameters:
region- the first region to check for equivalencyotherRegion- the second region to check for equivalency- Returns:
trueif the two specified regions are equal or cross-axis equivalents,falseotherwise.- See Also:
DockingManager.isValidDockingRegion(String)
-
isRegionTopLeft
public static boolean isRegionTopLeft(java.lang.String region)
Returnstrueif the specifiedregionis equal to eitherNORTH_REGIONorWEST_REGION. Returnsfalseotherwise.- Parameters:
region- theregionto check for top or left equivalency- Returns:
trueif the specifiedregionis equal to eitherNORTH_REGIONorWEST_REGION;falseotherwise.- See Also:
DockingConstants.NORTH_REGION,DockingConstants.WEST_REGION
-
getRegion
public static java.lang.String getRegion(int regionType)
Returns theStringdocking region for the specified orientation constant.LEFTmaps toWEST_REGION,RIGHTmaps toEAST_REGION,TOPmaps toNORTH_REGION,BOTTOMmaps toSOUTH_REGION, andCENTERmaps toCENTER_REGION. All other integer values will cause this method to returnUNKNOWN_REGION.All constants, both integer an
Stringvalues, can be found on theDockingConstantsinterface.- Parameters:
regionType- the orientation constant to translate into a docking region- Returns:
- the
Stringdocking region for the specified orientation constant. - See Also:
DockingConstants.LEFT,DockingConstants.RIGHT,DockingConstants.TOP,DockingConstants.BOTTOM,DockingConstants.CENTER,DockingConstants.WEST_REGION,DockingConstants.EAST_REGION,DockingConstants.NORTH_REGION,DockingConstants.SOUTH_REGION,DockingConstants.CENTER_REGION,DockingConstants.UNKNOWN_REGION
-
isMinimized
public static boolean isMinimized(Dockable dockable)
Returnstrueif the specifiedDockableis currently minimized;falseotherwise. If theDockableisnull, then this method returnsfalse.This method retrieves the current
DockingStateinstance associated with theDockableand calls it'sisMinimized()method to return.DockingStatefor the specifiedDockableis queried by callinggetDockingState(Dockable dockable)on theDockingManager'scurrently installedLayoutManager.- Parameters:
dockable- theDockablewhose minimized state is to be returned- Returns:
trueif the specifiedDockableis currently minimized;falseotherwise.- See Also:
DockingState.isMinimized(),DockingManager.getLayoutManager(),LayoutManager.getDockingState(Dockable)
-
getMinimizedConstraint
public static int getMinimizedConstraint(Dockable dockable)
Returns anintvalue representing the current minimization constraint for the specifiedDockable. If theDockableisnull, then this method returnsMinimizationManager.UNSPECIFIED_LAYOUT_CONSTRAINT.This method retrieves the current
DockingStateinstance associated with theDockableand calls it'sgetMinimizedConstraint()method to return.DockingStatefor the specifiedDockableis queried by callinggetDockingState(Dockable dockable)on theDockingManager'scurrently installedLayoutManager.- Parameters:
dockable- theDockablewhose minimized constraint is to be returned- Returns:
- an
intvalue representing the current minimization constraint for the specifiedDockable - See Also:
MinimizationManager.UNSPECIFIED_LAYOUT_CONSTRAINT,DockingManager.getLayoutManager(),LayoutManager.getDockingState(Dockable)
-
dockRelative
public static boolean dockRelative(Dockable dockable, Dockable parent, java.lang.String relativeRegion)
Docks the specifiedDockablerelative to another already-dockedDockablein the specified region. The "parent"Dockablemust currently be docked. If not, this method will returnfalse. Otherwise, its parentDockingPortwill be resolved and the newDockablewill be docked into theDockingPortrelative to the "parent"Dockable. This method defers processing todockRelative(Dockable dockable, Dockable parent, String relativeRegion, float ratio)passingUNSPECIFIED_SIBLING_PREFfor theratioparameter.This method returns
falseif any of the input parameters arenullor if the specifiedregionis invalid according toDockingManager.isValidDockingRegion(String region). If the specified region is other than CENTER, then a split layout should result.- Parameters:
dockable- theDockableto be dockedparent- theDockableused as a reference point for dockingrelativeRegion- the docking region into whichdockablewill be docked- Returns:
trueif the docking operation was successful;falseotherwise.- See Also:
dockRelative(Dockable, Dockable, String, float),DockingManager.isValidDockingRegion(String),Dockable.getDockingPort(),DockingManager.dock(Dockable, DockingPort, String)
-
dockRelative
public static boolean dockRelative(Dockable dockable, Dockable parent, java.lang.String relativeRegion, float ratio)
Docks the specifiedDockablerelative to another already-dockedDockablein the specified region with the specified split proportion. The "parent"Dockablemust currently be docked. If not, this method will returnfalse. Otherwise, its parentDockingPortwill be resolved and the newDockablewill be docked into theDockingPortrelative to the "parent"Dockable. If the specified region is CENTER, then theproportionparameter is ignored. Otherwise, a split layout should result with the proportional space specified in theproportionparameter allotted to thedockableargument.This method returns
falseif any of the input parameters arenullor if the specifiedregionis invalid according toDockingManager.isValidDockingRegion(String region).- Parameters:
dockable- theDockableto be dockedparent- theDockableused as a reference point for dockingrelativeRegion- the docking region into whichdockablewill be dockedratio- the proportional space to allot thedockableargument if the docking operation results in a split layout.- Returns:
trueif the docking operation was successful;falseotherwise.- See Also:
DockingManager.isValidDockingRegion(String),Dockable.getDockingPort(),DockingManager.dock(Dockable, DockingPort, String)
-
isFloating
public static boolean isFloating(Dockable dockable)
Returnstrueif the specifiedDockableis currently docked within a floating dialog. This method returnsfalseif theDockableis presently, minimized, hidden, docked within the main application layout, or if theDockableparameter isnull.This method retrieves the current
DockingStateinstance associated with theDockableand calls it'sisFloating()method to return.DockingStatefor the specifiedDockableis queried by callinggetDockingState(Dockable dockable)on theDockingManager'scurrently installedLayoutManager.- Parameters:
dockable- theDockablewhose floating state is to be returned- Returns:
trueif the specifiedDockableis currently floating;falseotherwise.- See Also:
DockingState.isFloating(),DockingManager.getLayoutManager(),LayoutManager.getDockingState(Dockable)
-
isEmbedded
public static boolean isEmbedded(Dockable dockable)
Returnstrueif the specifiedDockableis currently docked within aDockingPort. This method returnsfalseif theDockableis presently floating, minimized, hidden, or if theDockableparameter isnull.- Parameters:
dockable- theDockablewhose embedded state is to be returned- Returns:
trueif the specifiedDockableis currently docked within aDockingPort;falseotherwise.- See Also:
DockingManager.isDocked(Dockable),isFloating(Dockable)
-
setSplitProportion
public static void setSplitProportion(DockingPort port, float proportion)
Sets the divider location of the split layout embedded within the specifiedDockingPort. This method differs from bothsetSplitProportion(Dockable dockable, float proportion)in that this method resolves the split layout embedded within the specifiedDockingPort, whereas the other method modifies the split layout containing its respectiveDockableparameter.The resulting divider location will be a percentage of the split layout size based upon the
proportionparameter. Valid values forproportionrange from0.0F{@code to {@code 1.0F}. For example, a {@code proportion} of {@code 0.3F} will move the divider to 30% of the "size" (<i>width</i> for horizontal split, <i>height</i> for vertical split) of the split container embedded within the specified {@code DockingPort}. If a {@code proportion} of less than {@code 0.0F} is supplied, the value }0.0Fis used. If aproportiongreater than1.0Fis supplied, the value }1.0F} is used.This method should be effective regardless of whether the split layout in question has been fully realized and is currently visible on the screen. This should alleviate common problems associated with setting percentages of unrealized
Componentdimensions, which are initially0x0before theComponenthas been rendered to the screen.If the specified
DockingPortisnull, then noExceptionis thrown and no action is taken. Identical behavior occurs if theDockingPortdoes not contain split layout.- Parameters:
port- theDockingPortcontaining the split layout is to be resized.proportion- the percentage of split layout size to which the split divider should be set.- See Also:
SwingUtility.setSplitDivider(JSplitPane, float)
-
setSplitProportion
public static void setSplitProportion(Dockable dockable, float proportion)
Sets the divider location of the split layout containing the specified dockableComponent.The resulting divider location will be a percentage of the split layout size based upon the
proportionparameter. Valid values forproportionrange from0.0F{@code to {@code 1.0F}. For example, a {@code proportion} of {@code 0.3F} will move the divider to 30% of the "size" (<i>width</i> for horizontal split, <i>height</i> for vertical split) of the split container that contains the specified {@code Dockable}. If a {@code proportion} of less than {@code 0.0F} is supplied, the value }0.0Fis used. If aproportiongreater than1.0Fis supplied, the value }1.0F} is used.It is important to note that the split divider location is only a percentage of the container size from left to right or top to bottom. A
proportionof0.3Fdoes not imply thatdockableitself will be allotted 30% of the available space. The split divider will be moved to the 30% position of the split container regardless of the region in which the specifiedDockableresides (which may possibly result indockablebeing allotted 70% of the available space).This method should be effective regardless of whether the split layout in question has been fully realized and is currently visible on the screen. This should alleviate common problems associated with setting percentages of unrealized
Componentdimensions, which are initially0x0before theComponenthas been rendered to the screen.If the specified
Dockableisnull, then noExceptionis thrown and no action is taken. Identical behavior occurs if theDockabledoes not reside within a split layout.If the
Dockableresides within a tabbed layout, a check is done to see if the tabbed layout resides within a parent split layout. If so, the resolved split layout is resized. Otherwise no action is taken.- Parameters:
dockable- theDockablewhose containing split layout is to be resized.proportion- the percentage of containing split layout size to which the split divider should be set.- See Also:
SwingUtility.setSplitDivider(JSplitPane, float)
-
getTabText
public static java.lang.String getTabText(Dockable dockable)
Returns the text to be used by aDockableas a tab label within a tabbed layout. This method retrieves the associatedDockablePropertySetby callinggetDockingProperties()on the specifiedDockable. It then returns the value retrieved from callinggetDockableDesc()on theDockablePropertySetinstance. If the specifiedDockableisnull, then this method returnsnull.- Parameters:
dockable- theDockablewhose tab-text is to be returned- Returns:
- the text to be used by a
Dockableas a tab label within a tabbed layout. - See Also:
Dockable.getDockingProperties(),DockablePropertySet.getDockableDesc()
-
isDockable
public static boolean isDockable(java.lang.Object obj)
Returnstrueif the specificObjectis aDockable. Ifobj instanceof Dockableistrue, then this method returnstrue. Anullparameter will cause this method to returnfalse.Registered
Dockablecomponents, if they areJComponents, will also have aBooleanclient property present with the keyDockable.DOCKABLE_INDICATOR, used by dockableJComponentsthat don't implement theDockableinterface directly, but acquire docking capabilities through a separate wrapperDockableimplementation. For these components, theinstanceofcheck is insufficient since the validDockableis implemented by a separate class. Therefore, if theinstanceofcheck fails, and the suppliedObjectparameter is aJComponent, a client property with the keyDockable.DOCKABLE_INDICATORis checked for a value ofBoolean.TRUE. If the client property is present, then this method returnstrue.- Parameters:
obj- theObjectto be checked to see if it represents a validDockable- Returns:
trueif the specificObjectis aDockable- See Also:
Dockable.DOCKABLE_INDICATOR,Boolean.TRUE,JComponent.getClientProperty(java.lang.Object)
-
getAncestorDockable
public static Dockable getAncestorDockable(java.awt.Component comp)
-
isActive
public static boolean isActive(Dockable dockable)
-
-