📄 dockingutility.java
字号:
* {@code true}. This includes {@code CENTER_REGION}, which is axis
* independent.
* <p>
* {@code CENTER_REGION} is 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 specified {@code region} or
* {@code otherRegion} is {@code CENTER_REGION} and the other is not, then
* this method returns {@code false}.
* <p>
* Equivalancy across axes follows a top-to-left and bottom-to-right
* mapping. In this fashion, {@code NORTH_REGION} and {@code WEST_REGION}
* are equivalent and {@code SOUTH_REGION} and {@code EAST_REGION} are
* equivalent. These combination will return {@code true} for this method.
* All other region combinatinos will cause this method to return
* {@code false}.
*
* @param region
* the first region to check for equivalency
* @param otherRegion
* the second region to check for equivalency
* @return {@code true} if the two specified regions are equal or cross-axis
* equivalents, {@code false} otherwise.
* @see DockingManager#isValidDockingRegion(String)
*/
public static boolean isAxisEquivalent(String region, String otherRegion) {
if (!DockingManager.isValidDockingRegion(region)
|| !DockingManager.isValidDockingRegion(otherRegion))
return false;
if (region.equals(otherRegion))
return true;
if (CENTER_REGION.equals(region))
return false;
if (NORTH_REGION.equals(region))
return WEST_REGION.equals(otherRegion);
if (SOUTH_REGION.equals(region))
return EAST_REGION.equals(otherRegion);
if (EAST_REGION.equals(region))
return SOUTH_REGION.equals(otherRegion);
if (WEST_REGION.equals(region))
return NORTH_REGION.equals(otherRegion);
return false;
}
/**
* Returns {@code true} if the specified {@code region} is equal to either
* {@code NORTH_REGION} or {@code WEST_REGION}. Returns {@code false}
* otherwise.
*
* @param region
* the {@code region} to check for top or left equivalency
* @return {@code true} if the specified {@code region} is equal to either
* {@code NORTH_REGION} or {@code WEST_REGION}; {@code false}
* otherwise.
* @see DockingConstants#NORTH_REGION
* @see DockingConstants#WEST_REGION
*/
public static boolean isRegionTopLeft(String region) {
return NORTH_REGION.equals(region) || WEST_REGION.equals(region);
}
/**
* Returns the {@code String} docking region for the specified orientation
* constant. {@code LEFT} maps to {@code WEST_REGION}, {@code RIGHT} maps
* to {@code EAST_REGION}, {@code TOP} maps to {@code NORTH_REGION},
* {@code BOTTOM} maps to {@code SOUTH_REGION}, and {@code CENTER} maps to
* {@code CENTER_REGION}. All other integer values will cause this method
* to return {@code UNKNOWN_REGION}.
* <p>
* All constants, both integer an {@code String} values, can be found on the
* {@code DockingConstants} interface.
*
* @param regionType
* the orientation constant to translate into a docking region
* @return the {@code String} docking region for the specified orientation
* constant.
* @see DockingConstants#LEFT
* @see DockingConstants#RIGHT
* @see DockingConstants#TOP
* @see DockingConstants#BOTTOM
* @see DockingConstants#CENTER
* @see DockingConstants#WEST_REGION
* @see DockingConstants#EAST_REGION
* @see DockingConstants#NORTH_REGION
* @see DockingConstants#SOUTH_REGION
* @see DockingConstants#CENTER_REGION
* @see DockingConstants#UNKNOWN_REGION
*/
public static String getRegion(int regionType) {
switch (regionType) {
case LEFT:
return WEST_REGION;
case RIGHT:
return EAST_REGION;
case TOP:
return NORTH_REGION;
case BOTTOM:
return SOUTH_REGION;
case CENTER:
return CENTER_REGION;
default:
return UNKNOWN_REGION;
}
}
/**
* Returns {@code true} if the specified {@code Dockable} is currently
* minimized; {@code false} otherwise. If the {@code Dockable} is
* {@code null}, then this method returns {@code false}.
* <p>
* This method retrieves the current {@code DockingState} instance
* associated with the {@code Dockable} and calls it's {@code isMinimized()}
* method to return. {@code DockingState} for the specified {@code Dockable}
* is queried by calling {@code getDockingState(Dockable dockable)} on the
* {@code DockingManager's} currently installed {@code LayoutManager}.
*
* @param dockable
* the {@code Dockable} whose minimized state is to be returned
* @return {@code true} if the specified {@code Dockable} is currently
* minimized; {@code false} otherwise.
* @see DockingState#isMinimized()
* @see DockingManager#getLayoutManager()
* @see org.flexdock.docking.state.LayoutManager#getDockingState(Dockable)
*/
public static boolean isMinimized(Dockable dockable) {
if (dockable == null)
return false;
DockingState info = getDockingState(dockable);
return info == null ? false : info.isMinimized();
}
/**
* Returns an {@code int} value representing the current minimization
* constraint for the specified {@code Dockable}. If the {@code Dockable}
* is {@code null}, then this method returns
* {@code MinimizationManager.UNSPECIFIED_LAYOUT_CONSTRAINT}.
* <p>
* This method retrieves the current {@code DockingState} instance
* associated with the {@code Dockable} and calls it's
* {@code getMinimizedConstraint()} method to return. {@code DockingState}
* for the specified {@code Dockable} is queried by calling
* {@code getDockingState(Dockable dockable)} on the
* {@code DockingManager's} currently installed {@code LayoutManager}.
*
* @param dockable
* the {@code Dockable} whose minimized constraint is to be
* returned
* @return an {@code int} value representing the current minimization
* constraint for the specified {@code Dockable}
* @see MinimizationManager#UNSPECIFIED_LAYOUT_CONSTRAINT
* @see DockingState#getMinimizedConstraint()()
* @see DockingManager#getLayoutManager()
* @see org.flexdock.docking.state.LayoutManager#getDockingState(Dockable)
*/
public static int getMinimizedConstraint(Dockable dockable) {
int defaultConstraint = MinimizationManager.UNSPECIFIED_LAYOUT_CONSTRAINT;
DockingState info = dockable == null ? null : getDockingState(dockable);
return info == null ? defaultConstraint : info.getMinimizedConstraint();
}
private static DockingState getDockingState(Dockable dockable) {
return DockingManager.getLayoutManager().getDockingState(dockable);
}
/**
* Docks the specified {@code Dockable} relative to another already-docked
* {@code Dockable} in the specified region. The "parent" {@code Dockable}
* must currently be docked. If not, this method will return {@code false}.
* Otherwise, its parent {@code DockingPort} will be resolved and the new
* {@code Dockable} will be docked into the {@code DockingPort} relative to
* the "parent" {@code Dockable}. This method defers processing to
* {@code dockRelative(Dockable dockable, Dockable parent, String relativeRegion, float ratio)}
* passing {@code UNSPECIFIED_SIBLING_PREF} for the {@code ratio} parameter.
* <p>
* This method returns {@code false} if any of the input parameters are
* {@code null} or if the specified {@code region} is invalid according to
* {@code DockingManager.isValidDockingRegion(String region)}. If the
* specified region is other than CENTER, then a split layout should result.
*
* @param dockable
* the {@code Dockable} to be docked
* @param parent
* the {@code Dockable} used as a reference point for docking
* @param relativeRegion
* the docking region into which {@code dockable} will be docked
* @return {@code true} if the docking operation was successful;
* {@code false} otherwise.
* @see #dockRelative(Dockable, Dockable, String, float)
* @see DockingManager#isValidDockingRegion(String)
* @see Dockable#getDockingPort()
* @see DockingManager#dock(Dockable, DockingPort, String)
*/
public static boolean dockRelative(Dockable dockable, Dockable parent,
String relativeRegion) {
return dockRelative(parent, dockable, relativeRegion,
UNSPECIFIED_SIBLING_PREF);
}
/**
* Docks the specified {@code Dockable} relative to another already-docked
* {@code Dockable} in the specified region with the specified split
* proportion. The "parent" {@code Dockable} must currently be docked. If
* not, this method will return {@code false}. Otherwise, its parent
* {@code DockingPort} will be resolved and the new {@code Dockable} will be
* docked into the {@code DockingPort} relative to the "parent"
* {@code Dockable}. If the specified region is CENTER, then the
* {@code proportion} parameter is ignored. Otherwise, a split layout should
* result with the proportional space specified in the {@code proportion}
* parameter allotted to the {@code dockable} argument.
* <p>
* This method returns {@code false} if any of the input parameters are
* {@code null} or if the specified {@code region} is invalid according to
* {@code DockingManager.isValidDockingRegion(String region)}.
*
* @param dockable
* the {@code Dockable} to be docked
* @param parent
* the {@code Dockable} used as a reference point for docking
* @param relativeRegion
* the docking region into which {@code dockable} will be docked
* @param ratio
* the proportional space to allot the {@code dockable} argument
* if the docking operation results in a split layout.
* @return {@code true} if the docking operation was successful;
* {@code false} otherwise.
* @see DockingManager#isValidDockingRegion(String)
* @see Dockable#getDockingPort()
* @see DockingManager#dock(Dockable, DockingPort, String)
*/
public static boolean dockRelative(Dockable dockable, Dockable parent,
String relativeRegion, float ratio) {
if (parent == null || dockable == null
|| !DockingManager.isValidDockingRegion(relativeRegion))
return false;
// set the sibling preference
setSiblingPreference(parent, relativeRegion, ratio);
DockingPort port = parent.getDockingPort();
if (port != null)
return DockingManager.dock(dockable, port, relativeRegion);
return false;
}
private static void setSiblingPreference(Dockable src, String region,
float size) {
if (size == UNSPECIFIED_SIBLING_PREF || CENTER_REGION.equals(region)
|| !DockingManager.isValidDockingRegion(region))
return;
size = DefaultRegionChecker.validateSiblingSize(size);
src.getDockingProperties().setSiblingSize(region, size);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -