📄 dockingutility.java
字号:
/**
* Returns {@code true} if the specified {@code Dockable} is currently
* docked within a floating dialog. This method returns {@code false} if the
* {@code Dockable} is presently, minimized, hidden, docked within the main
* application layout, or if the {@code Dockable} parameter is {@code null}.
* <p>
* This method retrieves the current {@code DockingState} instance
* associated with the {@code Dockable} and calls it's {@code isFloating()}
* 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 floating state is to be returned
* @return {@code true} if the specified {@code Dockable} is currently
* floating; {@code false} otherwise.
* @see DockingState#isFloating()
* @see DockingManager#getLayoutManager()
* @see org.flexdock.docking.state.LayoutManager#getDockingState(Dockable)
*/
public static boolean isFloating(Dockable dockable) {
DockingState info = getDockingState(dockable);
return info == null ? false : info.isFloating();
}
/**
* Returns {@code true} if the specified {@code Dockable} is currently
* docked within a {@code DockingPort}. This method returns {@code false}
* if the {@code Dockable} is presently floating, minimized, hidden, or if
* the {@code Dockable} parameter is {@code null}.
*
* @param dockable
* the {@code Dockable} whose embedded state is to be returned
* @return {@code true} if the specified {@code Dockable} is currently
* docked within a {@code DockingPort}; {@code false} otherwise.
* @see DockingManager#isDocked(Dockable)
* @see #isFloating(Dockable)
*/
public static boolean isEmbedded(Dockable dockable) {
return dockable == null ? false : DockingManager.isDocked(dockable)
&& !isFloating(dockable);
}
/**
* Sets the divider location of the split layout embedded within the
* specified {@code DockingPort}. This method differs from both
* {@code setSplitProportion(Dockable dockable, float proportion)} in that
* this method resolves the split layout embedded <b>within</b> the
* specified {@code DockingPort}, whereas the other method modifies the
* split layout <b>containing</b> its respective {@code Dockable}
* parameter.
* <p>
* The resulting divider location will be a percentage of the split layout
* size based upon the {@code proportion} parameter. Valid values for
* {@code proportion} range from {@code 0.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.0F} is used. If a {@code proportion} greater
* than {@code 1.0F} is supplied, the value }1.0F} is used.
* <p>
* 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 {@code Component} dimensions, which are initially
* {@code 0x0} before the {@code Component} has been rendered to the screen.
* <p>
* If the specified {@code DockingPort} is {@code null}, then no
* {@code Exception} is thrown and no action is taken. Identical behavior
* occurs if the {@code DockingPort} does not contain split layout.
*
* @param port
* the {@code DockingPort} containing the split layout is to be
* resized.
* @param proportion
* the percentage of split layout size to which the split divider
* should be set.
* @see SwingUtility#setSplitDivider(JSplitPane, float)
*/
public static void setSplitProportion(DockingPort port, float proportion) {
if (port == null)
return;
Component comp = port.getDockedComponent();
if (comp instanceof JSplitPane)
SwingUtility.setSplitDivider((JSplitPane) comp, proportion);
}
/**
* Sets the divider location of the split layout containing the specified
* dockable {@code Component}.
* <p>
* The resulting divider location will be a percentage of the split layout
* size based upon the {@code proportion} parameter. Valid values for
* {@code proportion} range from {@code 0.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.0F} is used. If a {@code proportion} greater than
* {@code 1.0F} is supplied, the value }1.0F} is used.
* <p>
* 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
* {@code proportion} of {@code 0.3F} does not imply that {@code dockable}
* itself 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 specified {@code Dockable} resides (which may
* possibly result in {@code dockable} being allotted 70% of the available
* space).
* <p>
* 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 {@code Component} dimensions, which are initially
* {@code 0x0} before the {@code Component} has been rendered to the screen.
* <p>
* If the specified {@code Dockable} is {@code null}, then no
* {@code Exception} is thrown and no action is taken. Identical behavior
* occurs if the {@code Dockable} does not reside within a split layout.
* <p>
* If the {@code Dockable} resides 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.
*
* @param dockable
* the {@code Dockable} whose containing split layout is to be
* resized.
* @param proportion
* the percentage of containing split layout size to which the
* split divider should be set.
* @see SwingUtility#setSplitDivider(JSplitPane, float)
*/
public static void setSplitProportion(Dockable dockable, float proportion) {
if (dockable == null)
return;
Component comp = dockable.getComponent();
Container parent = comp.getParent();
if (parent instanceof JTabbedPane) {
parent = parent.getParent();
}
if (!(parent instanceof DockingPort))
return;
Container grandParent = parent.getParent();
if (grandParent instanceof JSplitPane)
SwingUtility.setSplitDivider((JSplitPane) grandParent, proportion);
}
/**
* Returns the text to be used by a {@code Dockable} as a tab label within a
* tabbed layout. This method retrieves the associated
* {@code DockablePropertySet} by calling {@code getDockingProperties()} on
* the specified {@code Dockable}. It then returns the value retrieved from
* calling {@code getDockableDesc()} on the {@code DockablePropertySet}
* instance. If the specified {@code Dockable} is {@code null}, then this
* method returns {@code null}.
*
* @param dockable
* the {@code Dockable} whose tab-text is to be returned
* @return the text to be used by a {@code Dockable} as a tab label within a
* tabbed layout.
* @see Dockable#getDockingProperties()
* @see DockablePropertySet#getDockableDesc()
*/
public static String getTabText(Dockable dockable) {
DockablePropertySet props = dockable == null ? null : dockable
.getDockingProperties();
return props == null ? null : props.getDockableDesc();
}
/**
* Returns {@code true} if the specific {@code Object} is a {@code Dockable}.
* If {@code obj instanceof Dockable} is {@code true}, then this method
* returns {@code true}. A {@code null} parameter will cause this method to
* return {@code false}.
* <p>
* Registered {@code Dockable} components, if they are {@code JComponents},
* will also have a {@code Boolean} client property present with the key
* {@code Dockable.DOCKABLE_INDICATOR}, used by dockable
* {@code JComponents} that don't implement the {@code Dockable} interface
* directly, but acquire docking capabilities through a separate wrapper
* {@code Dockable} implementation. For these components, the
* {@code instanceof} check is insufficient since the valid {@code Dockable}
* is implemented by a separate class. Therefore, if the {@code instanceof}
* check fails, and the supplied {@code Object} parameter is a
* {@code JComponent}, a client property with the key
* {@code Dockable.DOCKABLE_INDICATOR} is checked for a value of
* {@code Boolean.TRUE}. If the client property is present, then this
* method returns {@code true}.
*
* @param obj
* the {@code Object} to be checked to see if it represents a
* valid {@code Dockable}
* @return {@code true} if the specific {@code Object} is a {@code Dockable}
* @see Dockable#DOCKABLE_INDICATOR
* @see Boolean#TRUE
* @see javax.swing.JComponent#getClientProperty(java.lang.Object)
*/
public static boolean isDockable(Object obj) {
if (obj == null)
return false;
// if the object directly implements Dockable, then we can return from
// here.
if (obj instanceof Dockable)
return true;
// if the object is a JComponent, but not a Dockable implementation,
// then check its
// client property indicator
if (obj instanceof JComponent) {
Component comp = (Component) obj;
return SwingUtility.getClientProperty(comp,
Dockable.DOCKABLE_INDICATOR) == Boolean.TRUE;
}
// they may have a heavyweight Component that does not directly
// implement Dockable.
// in this case, Component does not have client properties we can check.
// we'll have to
// check directly with the DockingManager.
if (obj instanceof Component) {
Component comp = (Component) obj;
return DockingManager.getDockable(comp) != null;
}
return false;
}
public static Dockable getAncestorDockable(Component comp) {
if (comp == null)
return null;
if (isDockable(comp))
return DockingManager.getDockable(comp);
Container parent = comp.getParent();
while (parent != null && !(parent instanceof JRootPane)) {
if (isDockable(parent))
return DockingManager.getDockable(parent);
parent = parent.getParent();
}
return null;
}
public static boolean isActive(Dockable dockable) {
if (dockable == null)
return false;
return dockable.getDockingProperties().isActive().booleanValue();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -