📄 defaultregionchecker.java
字号:
* {@code Component}.
* @see RegionChecker#getRegionBounds(Component, String)
* @see #getRegionSize(Component, String)
*/
public Rectangle getRegionBounds(Component c, String region) {
if (c != null && region != null) {
float size = getRegionSize(c, region);
return calculateRegionalBounds(c, region, size);
}
return null;
}
/**
* Returns the bounding {@code Rectangle} within the specified component
* that represents the desired area to be allotted for sibling
* {@code Components} in the specified region. If {@code c} or
* {@code region} are null, then this method returns a {@code null}
* reference.
* <p>
* This method dispatches to
* {@code getSiblingSize(Component c, String region)} to determine the
* proportional size of the specified {@code Component} dedicated to
* siblings in the specified region. It then multiplies this value by the
* relevant {@code Component} dimension (<i>{@code width} for east/west,
* {@code height} for north/south</i>) and returns a {@code Rectangle} with
* the resulting dimension, spanning the {@code Component} edge for the
* specified region.
*
* @param c
* the {@code Component} whose sibling bounds are to be returned.
* @param region
* the specified region that is to be examined.
* @return the bounds representing the allotted sibling area for the
* supplied region of the specified {@code Component}.
* @see RegionChecker#getSiblingBounds(Component, String)
* @see #getSiblingSize(Component, String)
*/
public Rectangle getSiblingBounds(Component c, String region) {
if (c != null && region != null) {
float size = getSiblingSize(c, region);
return calculateRegionalBounds(c, region, size);
}
return null;
}
protected Rectangle calculateRegionalBounds(Component c, String region,
float size) {
if (c == null || region == null)
return null;
Rectangle bounds = c.getBounds();
if (NORTH_REGION.equals(region) || SOUTH_REGION.equals(region)) {
int h = (int) ((float) bounds.height * size);
int y = NORTH_REGION.equals(region) ? 0 : bounds.height - h;
return new Rectangle(0, y, bounds.width, h);
}
if (WEST_REGION.equals(region) || EAST_REGION.equals(region)) {
int w = (int) ((float) bounds.width * size);
int x = WEST_REGION.equals(region) ? 0 : bounds.width - w;
return new Rectangle(x, 0, w, bounds.height);
}
return null;
}
/**
* Returns a percentage (0.0F through 1.0F) representing the amount of space
* allotted for the specified region within the specified {@code Component}.
* <p>
* This method resolves the {@code Dockable} associated with the specified
* {@code Component} and dispatches to
* {@code getRegionPreference(Dockable d, String region)}.
* {@code getRegionPreference(Dockable d, String region)} attempts to invoke
* {@code getDockingProperties()} on the {@code Dockable} to resolve a
* {@code DockablePropertySet} instance and return from its
* {@code getRegionInset(String region)} method.
* <p>
* If the specified {@code Component} is {@code null}, no {@code Dockable}
* can be resolved, or no value is specified in the {@code Dockable's}
* associated {@code DockingProps} instance, then the default value of
* {@code RegionChecker.DEFAULT_REGION_SIZE} is returned.
*
* @param c
* the {@code Component} whose region is to be examined.
* @param region
* the specified region that is to be examined.
* @return the percentage of the specified {@code Component} allotted for
* the specified region.
* @see RegionChecker#getRegionSize(Component, String)
* @see DockingManager#getDockable(Component)
* @see #getRegionPreference(Dockable, String)
* @see Dockable#getDockingProperties()
*/
public float getRegionSize(Component c, String region) {
Dockable d = DockingManager.getDockable(c);
return getRegionPreference(d, region);
}
/**
* Returns a percentage (0.0F through 1.0F) representing the amount of space
* allotted for sibling {@code Component} docked to the specified region
* within the specified {@code Component}.
* <p>
* This method resolves the {@code Dockable} associated with the specified
* {@code Component} and dispatches to
* {@code getSiblingPreference(Dockable d, String region)}.
* {@code getSiblingPreference(Dockable d, String region)} attempts to
* invoke {@code getDockingProperties()} on the {@code Dockable} to resolve
* a {@code DockablePropertySet} instance and return from its
* {@code getSiblingSize(String region)} method.
* <p>
* If the specified {@code Component} is {@code null}, no {@code Dockable}
* can be resolved, or no value is specified in the {@code Dockable's}
* associated {@code DockingProps} instance, then the default value of
* {@code RegionChecker.DEFAULT_SIBLING_SIZE} is returned.
*
* @param c
* the {@code Component} whose sibling size is to be examined.
* @param region
* the specified region that is to be examined.
* @return the percentage of the specified {@code Component} allotted for
* the siblings within the specified region.
* @see DockingManager#getDockable(Component)
* @see #getSiblingPreference(Dockable, String)
* @see Dockable#getDockingProperties()
*/
public float getSiblingSize(Component c, String region) {
Dockable d = DockingManager.getDockable(c);
return getSiblingPreference(d, region);
}
protected static float getDockingInset(Float value, float defaultVal,
float max, float min) {
float f = value == null ? -1 : value.floatValue();
if (f == -1)
f = defaultVal;
return checkBounds(f, max, min);
}
protected static float checkBounds(float val, float max, float min) {
val = Math.min(val, max);
return Math.max(val, min);
}
/**
* Returns {@code size} if it is between the values
* {@code RegionChecker.MIN_REGION_SIZE} and
* {@code RegionChecker.MAX_REGION_SIZE}. If {@code size} is less than
* {@code RegionChecker.MIN_REGION_SIZE}, then
* {@code RegionChecker.MIN_REGION_SIZE} is returned. If {@code size} is
* greater than {@code RegionChecker.MAX_REGION_SIZE}, then
* {@code RegionChecker.MAX_REGION_SIZE} is returned.
*
* @return a valid {@code size} value between
* {@code RegionChecker.MIN_REGION_SIZE} and
* {@code RegionChecker.MAX_REGION_SIZE}, inclusive.
*/
public static float validateRegionSize(float size) {
return checkBounds(size, MAX_REGION_SIZE, MIN_REGION_SIZE);
}
/**
* Returns {@code size} if it is between the values
* {@code RegionChecker.MIN_SIBILNG_SIZE} and
* {@code RegionChecker.MAX_SIBILNG_SIZE}. If {@code size} is less than
* {@code RegionChecker.MIN_SIBILNG_SIZE}, then
* {@code RegionChecker.MIN_SIBILNG_SIZE} is returned. If {@code size} is
* greater than {@code RegionChecker.MAX_SIBILNG_SIZE}, then
* {@code RegionChecker.MAX_SIBILNG_SIZE} is returned.
*
* @return a valid {@code size} value between
* {@code RegionChecker.MIN_SIBILNG_SIZE} and
* {@code RegionChecker.MAX_SIBILNG_SIZE}, inclusive.
*/
public static float validateSiblingSize(float size) {
return checkBounds(size, MAX_SIBILNG_SIZE, MIN_SIBILNG_SIZE);
}
/**
* Returns a percentage (0.0F through 1.0F) representing the amount of space
* allotted for the specified region within the specified {@code Dockable}.
* <p>
* This method calls {@code getDockingProperties()} on the {@code Dockable}
* to resolve a {@code DockablePropertySet} instance. It then invokes
* {@code getRegionInset(String region)} on the {@code DockablePropertySet}
* to retrieve the preferred region size. If the {@code Dockable} is
* {@code null} or no region preference can be found, then the default value
* of {@code RegionChecker.DEFAULT_REGION_SIZE} is returned. Otherwise, the
* retrieved region preference is passed through
* {@code validateRegionSize(float size)} and returned.
*
* @param d
* the {@code Dockable} whose region is to be checked
* @param region
* the region of the specified {@code Dockable} to be checked
* @return a percentage (0.0F through 1.0F) representing the amount of space
* allotted for the specified region within the specified
* {@code Dockable}.
* @see Dockable#getDockingProperties()
* @see RegionChecker#DEFAULT_REGION_SIZE
* @see #validateRegionSize(float)
*/
public static float getRegionPreference(Dockable d, String region) {
Float inset = d == null ? null : d.getDockingProperties()
.getRegionInset(region);
return getDockingInset(inset, DEFAULT_REGION_SIZE, MAX_REGION_SIZE,
MIN_REGION_SIZE);
}
/**
* Returns a percentage (0.0F through 1.0F) representing the amount of space
* allotted for sibling {@code Components} docked to the specified region
* within the specified {@code Dockable}.
* <p>
* This method calls {@code getDockingProperties()} on the {@code Dockable}
* to resolve a {@code DockablePropertySet} instance. It then invokes
* {@code getSiblingSize(String region)} on the {@code DockablePropertySet}
* to retrieve the preferred sibling size. If the {@code Dockable} is
* {@code null} or no sibling preference can be found, then the default
* value of {@code RegionChecker.DEFAULT_SIBLING_SIZE} is returned.
* Otherwise, the retrieved region preference is passed through
* {@code validateSiblingSize(float size)} and returned.
*
* @param d
* the {@code Dockable} whose sibling size is to be checked
* @param region
* the region of the specified {@code Dockable} to be checked
* @return a percentage (0.0F through 1.0F) representing the amount of space
* allotted for sibling {@code Components} docked to the specified
* region within the specified {@code Dockable}.
* @see Dockable#getDockingProperties()
* @see RegionChecker#DEFAULT_SIBLING_SIZE
* @see #validateSiblingSize(float)
*/
public static float getSiblingPreference(Dockable d, String region) {
Float size = d == null ? null : d.getDockingProperties()
.getSiblingSize(region);
return getDockingInset(size, DockingManager.getDefaultSiblingSize(),
MAX_SIBILNG_SIZE, MIN_SIBILNG_SIZE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -