Class DefaultRegionChecker
- java.lang.Object
-
- org.flexdock.docking.defaults.DefaultRegionChecker
-
- All Implemented Interfaces:
DockingConstants
,RegionChecker
public class DefaultRegionChecker extends java.lang.Object implements RegionChecker, 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
-
Fields inherited from interface org.flexdock.docking.RegionChecker
DEFAULT_REGION_SIZE, DEFAULT_SIBLING_SIZE, DEFAULT_SIBLING_SIZE_KEY, MAX_REGION_SIZE, MAX_SIBILNG_SIZE, MIN_REGION_SIZE, MIN_SIBILNG_SIZE
-
-
Constructor Summary
Constructors Constructor Description DefaultRegionChecker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.awt.Rectangle
calculateRegionalBounds(java.awt.Component c, java.lang.String region, float size)
protected static float
checkBounds(float val, float max, float min)
protected static float
getDockingInset(java.lang.Float value, float defaultVal, float max, float min)
java.awt.Rectangle
getEastRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.EAST_REGION
.java.awt.Rectangle
getNorthRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.NORTH_REGION
.java.lang.String
getRegion(java.awt.Component comp, java.awt.Point point)
Returns the docking region of the suppliedComponent
that contains the coordinates of the specifiedPoint
.java.awt.Rectangle
getRegionBounds(java.awt.Component c, java.lang.String region)
Returns the boundingRectangle
within the specified component that represents the specified region.static float
getRegionPreference(Dockable d, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for the specified region within the specifiedDockable
.float
getRegionSize(java.awt.Component c, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for the specified region within the specifiedComponent
.java.awt.Rectangle
getSiblingBounds(java.awt.Component c, java.lang.String region)
Returns the boundingRectangle
within the specified component that represents the desired area to be allotted for siblingComponents
in the specified region.static float
getSiblingPreference(Dockable d, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for siblingComponents
docked to the specified region within the specifiedDockable
.float
getSiblingSize(java.awt.Component c, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for siblingComponent
docked to the specified region within the specifiedComponent
.java.awt.Rectangle
getSouthRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.SOUTH_REGION
.java.awt.Rectangle
getWestRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.WEST_REGION
.static float
validateRegionSize(float size)
Returnssize
if it is between the valuesRegionChecker.MIN_REGION_SIZE
andRegionChecker.MAX_REGION_SIZE
.static float
validateSiblingSize(float size)
Returnssize
if it is between the valuesRegionChecker.MIN_SIBILNG_SIZE
andRegionChecker.MAX_SIBILNG_SIZE
.
-
-
-
Method Detail
-
getRegion
public java.lang.String getRegion(java.awt.Component comp, java.awt.Point point)
Returns the docking region of the suppliedComponent
that contains the coordinates of the specifiedPoint
. If eithercomp
orpoint
isnull
, thenUNKNOWN_REGION
is returned. If the specifiedComponent
bounds do not contain the suppliedPoint
, thenUNKNOWN_REGION
is returned.This implementation assumes that
comp
is aComponent
embedded within aDockingPort
. Ifcomp
is itself aDockingPort
, thenCENTER_REGION
is returned. Otherwise, the returned region is based upon a section of the bounds of the specifiedComponent
relative to the containingDockingPort
.This method divides the specified
Component's
bounds into fourRectangles
determined bygetNorthRegion(Component c)
,getSouthRegion(Component c)
,getEastRegion(Component c)
, andgetWestRegion(Component c)
, respectively. EachRectangle
is then checked to see if it contains the specifiedPoint
. The order of precedence is NORTH, SOUTH, EAST, and then WEST. If the specifiedPoint
is contained by theComponent
bounds but none of the sub-Rectangles
, thenCENTER_REGION
is returned.For NORTH and SOUTH
Rectangles
, the distance is checked between the top/bottom and left or right edge of the regional bounds. If the horizontal distance to the regional edge is smaller than the vertical distance, then EAST or WEST takes precendence of NORTH or SOUTH. This allows for proper determination between "northeast", "northwest", "southeast", and "southwest" cases.- Specified by:
getRegion
in interfaceRegionChecker
- Parameters:
comp
- theComponent
whose region is to be examined.point
- the coordinates whose region is to be determined.- Returns:
- the docking region containing the specified
Point
. - See Also:
RegionChecker.getRegion(Component, Point)
,getNorthRegion(Component)
,getSouthRegion(Component)
,getEastRegion(Component)
,getWestRegion(Component)
-
getNorthRegion
public java.awt.Rectangle getNorthRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.NORTH_REGION
. This method dispatches togetRegionBounds(Component c, String region)
, passing an argument ofDockingConstants.NORTH_REGION
for the region parameter. If the specifiedComponent
isnull
, then anull
reference is returned.- Specified by:
getNorthRegion
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose north region is to be returned.- Returns:
- the bounds containing the north region of the specified
Component
. - See Also:
RegionChecker.getNorthRegion(Component)
,getRegionBounds(Component, String)
-
getSouthRegion
public java.awt.Rectangle getSouthRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.SOUTH_REGION
. This method dispatches togetRegionBounds(Component c, String region)
, passing an argument ofDockingConstants.SOUTH_REGION
for the region parameter. If the specifiedComponent
isnull
, then anull
reference is returned.- Specified by:
getSouthRegion
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose south region is to be returned.- Returns:
- the bounds containing the north region of the specified
Component
. - See Also:
RegionChecker.getSouthRegion(Component)
,getRegionBounds(Component, String)
-
getEastRegion
public java.awt.Rectangle getEastRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.EAST_REGION
. This method dispatches togetRegionBounds(Component c, String region)
, passing an argument ofDockingConstants.EAST_REGION
for the region parameter. If the specifiedComponent
isnull
, then anull
reference is returned.- Specified by:
getEastRegion
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose east region is to be returned.- Returns:
- the bounds containing the north region of the specified
Component
. - See Also:
RegionChecker.getEastRegion(Component)
,getRegionBounds(Component, String)
-
getWestRegion
public java.awt.Rectangle getWestRegion(java.awt.Component c)
Returns the rectangular bounds within the specified component that represent it'sDockingConstants.WEST_REGION
. This method dispatches togetRegionBounds(Component c, String region)
, passing an argument ofDockingConstants.WEST_REGION
for the region parameter. If the specifiedComponent
isnull
, then anull
reference is returned.- Specified by:
getWestRegion
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose west region is to be returned.- Returns:
- the bounds containing the north region of the specified
Component
. - See Also:
RegionChecker.getWestRegion(Component)
,getRegionBounds(Component, String)
-
getRegionBounds
public java.awt.Rectangle getRegionBounds(java.awt.Component c, java.lang.String region)
Returns the boundingRectangle
within the specified component that represents the specified region. Ifc
orregion
are null, then this method returns anull
reference.This method dispatches to
getRegionSize(Component c, String region)
to determine the proportional size of the specifiedComponent
dedicated to the specified region. It then multiplies this value by the relevantComponent
dimension (width
for east/west,height
for north/south) and returns aRectangle
with the resulting dimension, spanning theComponent
edge for the specified region.- Specified by:
getRegionBounds
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose region bounds are to be returned.region
- the specified region that is to be examined.- Returns:
- the bounds containing the supplied region of the specified
Component
. - See Also:
RegionChecker.getRegionBounds(Component, String)
,getRegionSize(Component, String)
-
getSiblingBounds
public java.awt.Rectangle getSiblingBounds(java.awt.Component c, java.lang.String region)
Returns the boundingRectangle
within the specified component that represents the desired area to be allotted for siblingComponents
in the specified region. Ifc
orregion
are null, then this method returns anull
reference.This method dispatches to
getSiblingSize(Component c, String region)
to determine the proportional size of the specifiedComponent
dedicated to siblings in the specified region. It then multiplies this value by the relevantComponent
dimension (width
for east/west,height
for north/south) and returns aRectangle
with the resulting dimension, spanning theComponent
edge for the specified region.- Specified by:
getSiblingBounds
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose sibling bounds are to be returned.region
- the specified region that is to be examined.- Returns:
- the bounds representing the allotted sibling area for the
supplied region of the specified
Component
. - See Also:
RegionChecker.getSiblingBounds(Component, String)
,getSiblingSize(Component, String)
-
calculateRegionalBounds
protected java.awt.Rectangle calculateRegionalBounds(java.awt.Component c, java.lang.String region, float size)
-
getRegionSize
public float getRegionSize(java.awt.Component c, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for the specified region within the specifiedComponent
.This method resolves the
Dockable
associated with the specifiedComponent
and dispatches togetRegionPreference(Dockable d, String region)
.getRegionPreference(Dockable d, String region)
attempts to invokegetDockingProperties()
on theDockable
to resolve aDockablePropertySet
instance and return from itsgetRegionInset(String region)
method.If the specified
Component
isnull
, noDockable
can be resolved, or no value is specified in theDockable's
associatedDockingProps
instance, then the default value ofRegionChecker.DEFAULT_REGION_SIZE
is returned.- Specified by:
getRegionSize
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose region is to be examined.region
- the specified region that is to be examined.- Returns:
- the percentage of the specified
Component
allotted for the specified region. - See Also:
RegionChecker.getRegionSize(Component, String)
,DockingManager.getDockable(Component)
,getRegionPreference(Dockable, String)
,Dockable.getDockingProperties()
-
getSiblingSize
public float getSiblingSize(java.awt.Component c, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for siblingComponent
docked to the specified region within the specifiedComponent
.This method resolves the
Dockable
associated with the specifiedComponent
and dispatches togetSiblingPreference(Dockable d, String region)
.getSiblingPreference(Dockable d, String region)
attempts to invokegetDockingProperties()
on theDockable
to resolve aDockablePropertySet
instance and return from itsgetSiblingSize(String region)
method.If the specified
Component
isnull
, noDockable
can be resolved, or no value is specified in theDockable's
associatedDockingProps
instance, then the default value ofRegionChecker.DEFAULT_SIBLING_SIZE
is returned.- Specified by:
getSiblingSize
in interfaceRegionChecker
- Parameters:
c
- theComponent
whose sibling size is to be examined.region
- the specified region that is to be examined.- Returns:
- the percentage of the specified
Component
allotted for the siblings within the specified region. - See Also:
DockingManager.getDockable(Component)
,getSiblingPreference(Dockable, String)
,Dockable.getDockingProperties()
-
getDockingInset
protected static float getDockingInset(java.lang.Float value, float defaultVal, float max, float min)
-
checkBounds
protected static float checkBounds(float val, float max, float min)
-
validateRegionSize
public static float validateRegionSize(float size)
Returnssize
if it is between the valuesRegionChecker.MIN_REGION_SIZE
andRegionChecker.MAX_REGION_SIZE
. Ifsize
is less thanRegionChecker.MIN_REGION_SIZE
, thenRegionChecker.MIN_REGION_SIZE
is returned. Ifsize
is greater thanRegionChecker.MAX_REGION_SIZE
, thenRegionChecker.MAX_REGION_SIZE
is returned.- Returns:
- a valid
size
value betweenRegionChecker.MIN_REGION_SIZE
andRegionChecker.MAX_REGION_SIZE
, inclusive.
-
validateSiblingSize
public static float validateSiblingSize(float size)
Returnssize
if it is between the valuesRegionChecker.MIN_SIBILNG_SIZE
andRegionChecker.MAX_SIBILNG_SIZE
. Ifsize
is less thanRegionChecker.MIN_SIBILNG_SIZE
, thenRegionChecker.MIN_SIBILNG_SIZE
is returned. Ifsize
is greater thanRegionChecker.MAX_SIBILNG_SIZE
, thenRegionChecker.MAX_SIBILNG_SIZE
is returned.- Returns:
- a valid
size
value betweenRegionChecker.MIN_SIBILNG_SIZE
andRegionChecker.MAX_SIBILNG_SIZE
, inclusive.
-
getRegionPreference
public static float getRegionPreference(Dockable d, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for the specified region within the specifiedDockable
.This method calls
getDockingProperties()
on theDockable
to resolve aDockablePropertySet
instance. It then invokesgetRegionInset(String region)
on theDockablePropertySet
to retrieve the preferred region size. If theDockable
isnull
or no region preference can be found, then the default value ofRegionChecker.DEFAULT_REGION_SIZE
is returned. Otherwise, the retrieved region preference is passed throughvalidateRegionSize(float size)
and returned.- Parameters:
d
- theDockable
whose region is to be checkedregion
- the region of the specifiedDockable
to be checked- Returns:
- a percentage (0.0F through 1.0F) representing the amount of space
allotted for the specified region within the specified
Dockable
. - See Also:
Dockable.getDockingProperties()
,RegionChecker.DEFAULT_REGION_SIZE
,validateRegionSize(float)
-
getSiblingPreference
public static float getSiblingPreference(Dockable d, java.lang.String region)
Returns a percentage (0.0F through 1.0F) representing the amount of space allotted for siblingComponents
docked to the specified region within the specifiedDockable
.This method calls
getDockingProperties()
on theDockable
to resolve aDockablePropertySet
instance. It then invokesgetSiblingSize(String region)
on theDockablePropertySet
to retrieve the preferred sibling size. If theDockable
isnull
or no sibling preference can be found, then the default value ofRegionChecker.DEFAULT_SIBLING_SIZE
is returned. Otherwise, the retrieved region preference is passed throughvalidateSiblingSize(float size)
and returned.- Parameters:
d
- theDockable
whose sibling size is to be checkedregion
- the region of the specifiedDockable
to be checked- Returns:
- a percentage (0.0F through 1.0F) representing the amount of space
allotted for sibling
Components
docked to the specified region within the specifiedDockable
. - See Also:
Dockable.getDockingProperties()
,RegionChecker.DEFAULT_SIBLING_SIZE
,validateSiblingSize(float)
-
-