📄 dockingmanager.java
字号:
// cache the dockable by ID
DOCKABLES_BY_ID.put(dockable.getPersistentId(), dockable);
// make sure we have docking-properties initialized (must come after
// ID-caching)
DockablePropertySet props = PropertyManager
.getDockablePropertySet(dockable);
// dispatch a registration event
EventManager.dispatch(new RegistrationEvent(dockable,
DockingManager.SINGLETON, true));
// return the dockable
return dockable;
}
public static void unregisterDockable(Component comp) {
Dockable dockable = getDockable(comp);
unregisterDockable(dockable);
}
public static void unregisterDockable(String dockingId) {
Dockable dockable = getDockableImpl(dockingId);
unregisterDockable(dockable);
}
public static void unregisterDockable(Dockable dockable) {
if (dockable == null)
return;
synchronized (DOCKABLES_BY_COMPONENT) {
DOCKABLES_BY_COMPONENT.remove(dockable.getComponent());
}
// flag the component as dockable, in case it doesn't
// implement the interface directly
Component c = dockable.getComponent();
SwingUtility.removeClientProperty(c, Dockable.DOCKABLE_INDICATOR);
// remove the drag listeners
removeDragListeners(dockable);
// remove the dockable as its own listener
dockable.removeDockingListener(dockable);
// unlink the propertySet
PropertyManager.removePropertySet(dockable);
// remove the dockable by ID
synchronized (DOCKABLES_BY_ID) {
DOCKABLES_BY_ID.remove(dockable.getPersistentId());
}
// dispatch a registration event
EventManager.dispatch(new RegistrationEvent(dockable,
DockingManager.SINGLETON, false));
}
/**
* Removes the event listeners that manage drag-n-drop docking operations
* from the specified {@code Component}. If the specific listeners are not
* present, then no action is taken. Drag listeners used by the docking
* system are of type {@code org.flexdock.docking.drag.DragManager}.
*
* @param comp
* the {@code Component} from which to remove drag listeners.
* @see DragManager
*/
public static void removeDragListeners(Component comp) {
if (comp == null)
return;
MouseMotionListener motionListener = null;
EventListener[] listeners = comp.getMouseMotionListeners();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof DragManager) {
motionListener = (MouseMotionListener) listeners[i];
break;
}
}
if (motionListener != null) {
comp.removeMouseMotionListener(motionListener);
}
MouseListener mouseListener = null;
listeners = comp.getMouseListeners();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof DragManager) {
mouseListener = (MouseListener) listeners[i];
break;
}
}
if (mouseListener != null) {
comp.removeMouseListener(mouseListener);
}
}
/**
* Displays the specified {@code Dockable} in the application's docking
* layout. If the {@code Dockable} has not previously been docked, a
* suitable location is determined within the layout and the
* {@code Dockable} is docked to that location. If the {@code Dockable} has
* previously been docked within the layout and subsequently removed, as
* with a call to {@code DockingManager.close()}, the {@code Dockable} will
* be restored to its prior state within the layout. This method defers
* processing to the {@code display(Dockable dockable)} method for the
* currently installed {@code org.flexdock.docking.state.LayoutManager}.
* The {@code LayoutManager} implementation is responsible for handling the
* semantics of determining an initial docking location or restoring a
* {@code Dockable} to its previous layout state. If the {@code Dockable}
* parameter is {@code null}, no {@code Exception} is thrown and no action
* is taken.
*
* @param dockable
* the {@code Dockable} to be displayed.
* @return {@code true} if the {@code Dockable} was successfully displayed;
* {@code false} otherwise.
* @see #getLayoutManager()
* @see LayoutManager#display(Dockable)
*/
public static boolean display(Dockable dockable) {
return getLayoutManager().display(dockable);
}
/**
* Displays the {@code Dockable} with the specified ID within the
* application's docking layout. A valid {@code Dockable} is looked up for
* the supplied ID. If none is found, this method returns {@code false}.
* Otherwise, processing is dispatched to {@code display(Dockable dockable)}.
* If the {@code Dockable} has not previously been docked, a suitable
* location is determined within the layout and the {@code Dockable} is
* docked to that location. If the {@code Dockable} has previously been
* docked within the layout and subsequently removed, as with a call to
* {@code DockingManager.close()}, the {@code Dockable} will be restored to
* its prior state within the layout. This method defers processing to the
* {@code display(Dockable dockable)} method for the currently installed
* {@code org.flexdock.docking.state.LayoutManager}. The
* {@code LayoutManager} implementation is responsible for handling the
* semantics of determining an initial docking location or restoring a
* {@code Dockable} to its previous layout state. If the {@code Dockable}
* parameter is {@code null}, no {@code Exception} is thrown and no action
* is taken.
*
* @param dockable
* the ID of the {@code Dockable} to be displayed.
* @return {@code true} if the {@code Dockable} was successfully displayed;
* {@code false} otherwise.
* @see #display(Dockable)
* @see #getLayoutManager()
* @see LayoutManager#display(Dockable)
*/
public static boolean display(String dockable) {
return getLayoutManager().display(getDockable(dockable));
}
private static String generatePersistentId(Object obj) {
return generatePersistentId(obj, null);
}
private static String generatePersistentId(Object obj, String desiredId) {
if (obj == null)
return null;
synchronized (persistentIdLock) {
String pId = desiredId == null ? obj.getClass().getName()
: desiredId;
StringBuffer baseId = new StringBuffer(pId);
for (int i = 1; hasRegisteredDockableId(pId); i++) {
baseId.append("_").append(i);
pId = baseId.toString();
}
return pId;
}
}
private static boolean hasRegisteredDockableId(String id) {
return DOCKABLES_BY_ID.containsKey(id);
}
/**
* Returns the {@code DockingStrategy} associated with the {@code Class} of
* the {@code Object} parameter. This method returns {@code null} if the
* parameter is {@code null}. Otherwise, the method retrieves the
* {@code Object's} {@code Class} and dispatches to
* {@code getDockingStrategy(Class classKey)}.
* <p>
* {@code DockingStrategy} association follows a strict inheritance chain
* using {@code org.flexdock.util.ClassMapping}. If a mapping for
* {@code obj.getClass()} is not found, then the superclass is tested, and
* so on until {@code java.lang.Object} is reached. Thus, if a
* {@code DockingStrategy} mapping of {@code Foo} exists for class
* {@code Bar}, and class {@code Baz} extends {@code Bar}, then calling
* this method for an instance of {@code Baz} will return an instance of
* {@code Foo}. The inheritance chain is <i>strict</i> in the sense that
* only superclasses are checked. Implemented interfaces are ignored.
* <p>
* If a class association is never found, then an instance of
* {@code DefaultDockingStrategy} is returned.
*
* @param obj
* the object whose {@code DockingStrategy} association we wish
* to test
* @return the {@code DockingStrategy} associated with the {@code Class}
* type of the {@code Object} parameter.
* @see #getDockingStrategy(Class)
* @see #setDockingStrategy(Class, DockingStrategy)
* @see ClassMapping#getClassInstance(Class)
*/
public static DockingStrategy getDockingStrategy(Object obj) {
Class key = obj == null ? null : obj.getClass();
return getDockingStrategy(key);
}
/**
* Returns the {@code DockingStrategy} associated with specified
* {@code Class}. This method returns {@code null} if the parameter is
* {@code null}.
* <p>
* {@code DockingStrategy} association follows a strict inheritance chain
* using {@code org.flexdock.util.ClassMapping}. If a mapping for
* {@code classKey} is not found, then the superclass is tested, and so on
* until {@code java.lang.Object} is reached. Thus, if a
* {@code DockingStrategy} mapping of {@code Foo} exists for class
* {@code Bar}, and class {@code Baz} extends {@code Bar}, then calling
* this method for class {@code Baz} will return an instance of {@code Foo}.
* The inheritance chain is <i>strict</i> in the sense that only
* superclasses are checked. Implemented interfaces are ignored.
* <p>
* If a class association is never found, then an instance of
* {@code DefaultDockingStrategy} is returned.
*
* @param classKey
* the {@code Class} whose {@code DockingStrategy} association we
* wish to test
* @return the {@code DockingStrategy} associated with the specified
* {@code Class}.
* @see #setDockingStrategy(Class, DockingStrategy)
* @see ClassMapping#getClassInstance(Class)
*/
public static DockingStrategy getDockingStrategy(Class classKey) {
DockingStrategy strategy = (DockingStrategy) DOCKING_STRATEGIES
.getClassInstance(classKey);
return strategy;
}
/**
* Returns an array of {@code RootWindows} known to the docking framework
* that contain {@code DockingPorts}. Any {@code Frame}, {@code Applet},
* {@code Dialog}, or {@code Window} that has a {@code DockingPort} added
* as a descendent {@code Component} will automatically have an
* {@code org.flexdock.util.RootWindow} wrapper instance associated with it.
* This method will return an array of all known RootWindows that contain
* {@code DockingPorts}. Ordering of the array may be based off of a
* {@code java.util.Set} and is <b>not</b> guaranteed.
*
* @return an array of all known {@code RootWindows} that contain
* {@code DockingPorts}
* @see RootWindow
* @see DockingPortTracker#getDockingWindows()
*/
public static RootWindow[] getDockingWindows() {
Set windowSet = DockingPortTracker.getDockingWindows();
return windowSet == null ? new RootWindow[0] : (RootWindow[]) windowSet
.toArray(new RootWindow[0]);
}
/**
* Returns the {@code DockingPort} with the specified ID. If the
* {@code portId} parameter is {@code null}, or a {@code DockingPort} with
* the specified ID is not found, a {@code null} reference is returned. This
* method internally dispatches to
* {@code org.flexdock.docking.event.hierarchy.DockingPortTracker.findById(String portId)}.
* {@code portId} should match the value returned by a {@code DockingPort's}
* {@code getPersistentId()} method.
*
* @param portId
* the ID of the {@code DockingPort} to be looked up
* @return the {@code DockingPort} with the specified ID
* @see DockingPort#getPersistentId()
* @see DockingPortTracker#findById(String)
*/
public static DockingPort getDockingPort(String portId) {
return DockingPortTracker.findById(portId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -