📄 defaultdockingport.java
字号:
DockingPortPropertySet props = getDockingProperties();
props.setRegionChecker(new DefaultRegionChecker());
// check container hierarchy to track root dockingports
addHierarchyListener(DockingPortTracker.getInstance());
// start out as a root dockingport
rootPort = true;
// configure layout
setLayout(createLayout());
//configure the default border manager
setBorderManager(createBorderManager());
}
protected LayoutManager createLayout() {
return new PortLayout();
}
/**
* Creates a standard border manager for this docking port.
* <p>
* This method is called from the constructor.
*
* @return the border manager for this docking port.
*/
protected BorderManager createBorderManager() {
return new StandardBorderManager(new EmptyBorder(0, 0, 0, 0));
}
/**
* Overridden to set the currently docked component. Should not be called by
* application code.
*
* @param comp
* the component to be added
*/
public Component add(Component comp) {
return setComponent(comp);
}
/**
* Overridden to set the currently docked component. Should not be called by
* application code.
*
* @param comp
* the component to be added
* @param index
* the position at which to insert the component, or {@code -1}
* to append the component to the end
*/
public Component add(Component comp, int index) {
return setComponent(comp);
}
/**
* Overridden to set the currently docked component. Should not be called by
* application code.
*
* @param comp
* the component to be added
* @param constraints
* an object expressing layout contraints for this component
*/
public void add(Component comp, Object constraints) {
setComponent(comp);
}
/**
* Overridden to set the currently docked component. Should not be called by
* application code.
*
* @param comp
* the component to be added
* @param constraints
* an object expressing layout contraints for this
* @param index
* the position in the container's list at which to insert the
* component; {@code -1} means insert at the end
*/
public void add(Component comp, Object constraints, int index) {
setComponent(comp);
}
/**
* Overridden to set the currently docked component. Should not be called by
* application code.
*
* @param name
* the name of the {@code Component} to be added.
* @param comp
* the {@code Component} to add.
*/
public Component add(String name, Component comp) {
return setComponent(comp);
}
private void addCmp(DockingPort port, Component c) {
if (port instanceof Container)
((Container) port).add(c);
}
private void dockCmp(DockingPort port, Component c) {
port.dock(c, CENTER_REGION);
}
/**
* Returns {@code true} if docking is allowed for the specified
* {@code Component} within the supplied {@code region}, {@code false}
* otherwise. It is important to note that success of a docking operation
* relies on many factors and a return value of {@code true} from this
* method does not necessarily guarantee that a call to {@code dock()} will
* succeed. This method merely indicates that the current
* {@code DockingPort} does not have any outstanding reason to block a
* docking operation with respect to the specified {@code Component} and
* {@code region}.
* <p>
* If {@code comp} is {@code null} or {@code region} is invalid according to
* {@code DockingManager.isValidDockingRegion(String region)}, then this
* method returns {@code false}.
* <p>
* If this {@code DockingPort} is not already the parent {@code DockingPort}
* for the specified {@code Component}, then this method returns
* {@code true}.
* <p>
* If this {@code DockingPort} is already the parent {@code DockingPort} for
* the specified {@code Component}, then a check is performed to see if
* there is a tabbed layout. Tabbed layouts may contain multiple
* {@code Dockables}, and thus the tab ordering may be rearranged, or
* shifted into a split layout. If {@code comp} is the only docked
* {@code Component} within this {@code DockingPort}, then this method
* returns {@code false} since the layout cannot be rearranged. Otherwise,
* this method returns {@code true}.
*
* @param comp
* the {@code Component} whose docking availability is to be
* checked
* @param region
* the region to be checked for docking availability for the
* specified {@code Component}.
* @return {@code true} if docking is allowed for the specified
* {@code Component} within the supplied {@code region},
* {@code false} otherwise.
* @see DockingPort#isDockingAllowed(Component, String)
* @see DockingManager#isValidDockingRegion(String)
* @see #isParentDockingPort(Component)
*/
public boolean isDockingAllowed(Component comp, String region) {
if (comp == null || !isValidDockingRegion(region))
return false;
// allow any valid region if we're not already the parent
// of the component we're checking
if (!isParentDockingPort(comp))
return true;
// we already contain 'comp', so we're either a tabbed-layout, or
// we contain 'comp' directly. If we contain 'comp' directly, then we
// cannot logically move 'comp' to some other region within us, as it
// already fills up our entire space.
Component docked = getDockedComponent();
if (!(docked instanceof JTabbedPane))
// not a tabbed-layout, so we contain 'c' directly
return false;
JTabbedPane tabs = (JTabbedPane) docked;
// if there is only 1 tab, then we already fill up the entire
// dockingport space and cannot be moved elsewhere
if (tabs.getTabCount() < 2)
return false;
// there is more than 1 tab present, so re-ordering is possible,
// as well as changing regions
return true;
}
/**
* Checks the current state of the {@code DockingPort} and, if present,
* issues the appropriate call to the assigned {@code BorderManager}
* instance describing the container state. This method will issue a call to
* 1 of the 4 following methods on the assigned {@code BorderManager}
* instance, passing {@code this} as the method argument:
* <p>
* {@code managePortNullChild(DockingPort port)}
* {@code managePortSimpleChild(DockingPort port)}
* {@code managePortSplitChild(DockingPort port)}
* {@code managePortTabbedChild(DockingPort port)}
*/
final void evaluateDockingBorderStatus() {
if (borderManager == null)
return;
Component docked = getDockedComponent();
// check for the null-case
if (docked == null)
borderManager.managePortNullChild(this);
// check for a split layout
else if (docked instanceof JSplitPane)
borderManager.managePortSplitChild(this);
// check for a tabbed layout
else if (docked instanceof JTabbedPane)
borderManager.managePortTabbedChild(this);
// otherwise, we have a simple case of a regular component docked within
// us
else
borderManager.managePortSimpleChild(this);
}
/**
* Returns the docking region within this {@code DockingPort} that contains
* the specified {@code Point}. Valid return values are those regions
* defined in {@code DockingConstants} and include {@code NORTH_REGION},
* {@code SOUTH_REGION}, {@code EAST_REGION}, {@code WEST_REGION},
* {@code CENTER_REGION}, and {@code UNKNOWN_REGION}.
* <p>
* If {@code location} is {@code null}, then {@code UNKNOWN_REGION} is
* returned.
* <p>
* This method gets the {@code RegionChecker} for this {@code DockingPort}
* by calling {@code getRegionChecker()}. It then attempts to locate the
* {@code Dockable} at the specified {@code location} by calling
* {@code getDockableAt(Point location)}.
* <p>
* This method defers processing to {@code getRegion(Component c, Point p)}
* for the current {@code RegionChecker}. If a {@code Dockable} was found
* at the specified {@code Point}, then the location of the {@code Point}
* is translated to the coordinate system of the {@code Component} for the
* embedded {@code Dockable} and that {@code Component} and modified
* {@code Point} are passed into {@code getRegion(Component c, Point p)}}
* for the current {@code RegionChecker}. If no {@code Dockable} was found,
* then the specified {@code Point} is left unmodified and this
* {@code DockingPort} and the supplied {@code Point} are passed to
* {@code getRegion(Component c, Point p)}} for the current
* {@code RegionChecker}.
*
* @param location
* the location within this {@code DockingPort} to examine for a
* docking region.
* @return the docking region within this {@code DockingPort} that contains
* the specified {@code Point}
* @see #getRegionChecker()
* @see #getDockableAt(Point)
* @see Dockable#getComponent()
* @see RegionChecker#getRegion(Component, Point)
*/
public String getRegion(Point location) {
if (location == null)
return UNKNOWN_REGION;
RegionChecker regionChecker = getRegionChecker();
Dockable d = getDockableAt(location);
Component regionTest = this;
if (d != null) {
regionTest = d.getComponent();
location = SwingUtilities.convertPoint(this, location, regionTest);
}
return regionChecker.getRegion(regionTest, location);
}
/**
* Returns the {@code RegionChecker} currently used by this
* {@code DockingPort}. This method retrieves the
* {@code DockingPortPropertySet} instance for this {@code DockingPort} by
* calling {@code getDockingProperties()}. It then returns by invoking
* {@code getRegionChecker()} on the resolved {@code DockingPortPropertySet}.
*
* @return the {@code RegionChecker} currently used by this
* {@code DockingPort}.
* @see #getDockingProperties()
* @see DockingPortPropertySet#getRegionChecker()
*/
public RegionChecker getRegionChecker() {
return getDockingProperties().getRegionChecker();
}
/**
* Returns the direct child {@code Dockable} located at the specified
* {@code Point}. If {@code location} is {@code null}, or this
* {@code DockingPort} is empty, then a {@code null} reference is returned.
* <p>
* If this {@code DockingPort} contains a split layout, then any nested
* {@code Dockables} will be within a sub-{@code DockingPort} and not a
* direct child of this {@code DockingPort}. Therefore, if
* {@code getDockedComponent()} returns a {@code JSplitPane}, then this
* method will return a {@code null} reference.
* <p>
* If this {@code DockingPort} contains a tabbed layout, then the
* {@code JTabbedPane} returned by {@code getDockedComponent()} will be
* checked for a {@code Dockable} at the specified {@code Point}.
*
* @param location
* the location within the {@code DockingPort} to test for a
* {@code Dockable}.
* @return the direct child {@code Dockable} located at the specified
* {@code Point}.
* @see #getDockedComponent()
* @see DockingManager#getDockable(Component)
* @see JTabbedPane#getComponentAt(int x, int y)
*/
public Dockable getDockableAt(Point location) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -