⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dockingmanager.java

📁 定要上载质量高而定要上载质量高而定要上载质量高而定要上载质量高而定要上载质量高而
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

    private static DockingStrategy findDockingStrategy(Dockable dockable) {
        DockingPort port = dockable.getDockingPort();
        DockingStrategy strategy = port == null ? null : port
                .getDockingStrategy();
        if (strategy == null) {
            DockingManager mgr = getDockingManager();
            strategy = mgr == null ? null : mgr.defaultDocker;
        }
        return strategy;
    }

    /**
     * Indicates whether the specified {@code Component} is currently docked.
     * This method looks up a parent {@code DockingPort} for the specified
     * {@code Component} via a call to
     * {@code getDockingPort(Component dockable)}. This method returns
     * {@code true} if a parent {@code DockingPort} is found and {@code false}
     * if no parent {@code DockingPort} is present. This method returns
     * {@code false} if the {@code Component} parameter is {@code null}.
     * 
     * @param component
     *            the {@code Component} whose docking status is to be examined
     * @return {@code true} if the {@code Component} is currently docked;
     *         otherwise {@code false}.
     */
    public static boolean isDocked(Component component) {
        return getDockingPort(component) != null;
    }

    /**
     * Indicates whether the specified {@code Dockable} is currently docked.
     * This method looks up a parent {@code DockingPort} for the specified
     * {@code Dockable} via a call to {@code getDockingPort(Dockable dockable)}.
     * This method returns {@code true} if a parent {@code DockingPort} is found
     * and {@code false} if no parent {@code DockingPort} is present. This
     * method returns {@code false} if the {@code Dockable} parameter is
     * {@code null}.
     * 
     * @param dockable
     *            the {@code Dockable} whose docking status is to be examined
     * @return {@code true} if the {@code Dockable} is currently docked;
     *         otherwise {@code false}.
     */
    public static boolean isDocked(Dockable dockable) {
        return getDockingPort(dockable) != null;
    }

    /**
     * Checks whether a supplied {@code Dockable} is docked within a supplied
     * {@code DockingPort} instance. Returns {@code true} if the
     * {@code DockingPort} contains the specified {@code Dockable};
     * {@code false} otherwise. This method returns {@code false} if either of
     * the input parameters are {@code null}.
     * 
     * @param dockingPort
     *            the {@code DockingPort} to be tested
     * @param dockable
     *            the {@code Dockable} instance to be examined
     * @return {@code true} if the supplied {@code DockingPort} contains the
     *         specified {@code Dockable}; {@code false} otherwise.
     */
    public static boolean isDocked(DockingPort dockingPort, Dockable dockable) {
        return dockingPort == null || dockable == null ? false : dockingPort
                .isParentDockingPort(dockable.getComponent());
    }

    /**
     * Indicates whether global floating support is currently enabled. Defers
     * processing to {@code FloatPolicyManager.isGlobalFloatingEnabled()}.
     * 
     * @return {@code true} if global floating support is enabled, {@code false}
     *         otherwise.
     * @see FloatPolicyManager#isGlobalFloatingEnabled()
     */
    public static boolean isFloatingEnabled() {
        return FloatPolicyManager.isGlobalFloatingEnabled();
    }

    /**
     * Indicates whether tabbed layouts are supported by default for
     * {@code DockingPorts} with a single {@code Dockable} in the CENTER region.
     * This is a global default setting and applies to any <cod>DockingPort}
     * that does not have a specific contradictory local setting.
     * <p>
     * This method defers processing to
     * {@code org.flexdock.docking.props.PropertyManager.getDockingPortRoot()}.
     * As such, there are multiple "scopes" at which this property may be
     * overridden.
     * 
     * @return {@code true} if the default setting for {@code DockingPorts}
     *         allows a tabbed layout for a single {@code Dockable} in the
     *         CENTER region; {@code false} otherwise.
     * @see PropertyManager#getDockingPortRoot()
     * @see org.flexdock.docking.props.DockingPortPropertySet#isSingleTabsAllowed()
     */
    public static boolean isSingleTabsAllowed() {
        return PropertyManager.getDockingPortRoot().isSingleTabsAllowed()
                .booleanValue();
    }

    /**
     * Indicates whether the supplied parameter is considered a valid docking
     * region. Valid values are those defined in {@code DockingConstants} and
     * include {@code NORTH_REGION}, {@code SOUTH_REGION}, {@code EAST_REGION},
     * {@code WEST_REGION}, and {@code CENTER_REGION}. This method returns
     * {@code true} if the supplied parameter is equal to one of these values.
     * 
     * @param region
     *            the region value to be tested
     * @return {@code true} if the supplied parameter is a valid docking region;
     *         {@code false} otherwise.
     */
    public static boolean isValidDockingRegion(String region) {
        return CENTER_REGION.equals(region) || NORTH_REGION.equals(region)
                || SOUTH_REGION.equals(region) || EAST_REGION.equals(region)
                || WEST_REGION.equals(region);
    }

    private static void updateDragListeners(Component dragSrc,
            DragManager listener) {
        MouseMotionListener motionListener = null;
        EventListener[] listeners = dragSrc.getMouseMotionListeners();
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof DragManager) {
                motionListener = (MouseMotionListener) listeners[i];
                break;
            }
        }
        if (motionListener != listener) {
            if (motionListener != null)
                dragSrc.removeMouseMotionListener(motionListener);
            dragSrc.addMouseMotionListener(listener);
        }

        MouseListener mouseListener = null;
        listeners = dragSrc.getMouseListeners();
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof DragManager) {
                mouseListener = (MouseListener) listeners[i];
                break;
            }
        }
        if (mouseListener != listener) {
            if (mouseListener != null)
                dragSrc.removeMouseListener(mouseListener);
            dragSrc.addMouseListener(listener);
        }
    }

    /**
     * Creates, registers, and returns a {@code Dockable} for the specified
     * {@code Component}. If the specified {@code Component} implements the
     * {@code Dockable} interface, then this method dispatches to
     * {@code registerDockable(Dockable dockable)}. Otherwise, this method
     * dispatches to {@code registerDockable(Component comp, String tabText)}.
     * <p>
     * This method attempts to resolve an appropriate value for {@code tabText}
     * by calling {@code getName()} on the specified {@code Component}. If the
     * resolved value is {@code null} or empty, then the value {@code "null"} is
     * used.
     * <p>
     * If {@code comp} is {@code null}, no exception is thrown and no action is
     * performed.
     * 
     * @param comp
     *            the target component for the {@code Dockable}.
     * @return the {@code Dockable} that has been registered for the supplied
     *         {@code Component}
     * @see #registerDockable(Dockable)
     * @see #registerDockable(Component, String)
     */
    public static Dockable registerDockable(Component comp) {
        if (comp == null)
            return null;

        if (comp instanceof Dockable)
            return registerDockable((Dockable) comp);

        return registerDockable(comp, null, null);
    }

    private static String determineTabText(Component comp, String persistId) {
        String tabText = null;
        // if 'comp' is a DockingStub, then we may be able to
        // pull the tab text from it
        if (comp instanceof DockingStub) {
            tabText = ((DockingStub) comp).getTabText();
        } else {
            // if we can find an adapter mapping, then try to pull
            // the tab text from there
            DockingAdapter adapter = AdapterFactory.getAdapter(comp);
            if (adapter != null)
                tabText = adapter.getTabText();
        }

        // if 'comp' wasn't a DockingStub, or the stub returned a null tabText,
        // then try the component name
        if (tabText == null)
            tabText = comp.getName();

        // if tabText is still null, then use the persistentId
        if (tabText == null)
            tabText = persistId;

        // get rid of null and empty cases. use the string "null" if nothing
        // else can be found
        tabText = tabText == null ? "null" : tabText.trim();
        if (tabText.length() == 0)
            tabText = "null";

        return tabText;
    }

    /**
     * Creates a {@code Dockable} for the specified {@code Component} and
     * dispatches to {@code registerDockable(Dockable init)}. If {@code comp}
     * is {@code null}, no exception is thrown and no action is performed.
     * 
     * @param comp
     *            the target component for the Dockable, both drag-starter and
     *            docking source
     * @param tabText
     *            the description of the docking source. Used as the tab-title
     *            of docked in a tabbed pane
     * @return the {@code Dockable} that has been registered for the supplied
     *         {@code Component}
     * @see #registerDockable(Dockable)
     */
    public static Dockable registerDockable(Component comp, String tabText) {
        return registerDockable(comp, tabText, null);
    }

    private static Dockable registerDockable(Component comp, String tabText,
            String dockingId) {
        if (comp == null)
            return null;

        if (tabText == null)
            tabText = determineTabText(comp, dockingId);

        Dockable dockable = getDockableForComponent(comp, tabText, dockingId);
        return registerDockable(dockable);
    }

    /**
     * Registers and initializes the specified {@code Dockable}. All
     * {@code Dockables} managed by the framework must, at some point, be
     * registered via this method. This method adds the {@code Dockable} to the
     * internal registry, allowing querying by ID and {@code Component}. Drag
     * listeners are added to the {@code Dockable} to enable drag-n-drop docking
     * support. Docking properties are also initialized for the {@code Dockable}.
     * This method fires a {@code RegistrationEvent} once the {@code Dockable}
     * has been registered. If the {@code Dockable} is {@code null}, no
     * {@code Exception} is thrown and no action is taken. The {@code Dockable}
     * returned by this method will be the same object passed in as an argument.
     * 
     * @param dockable
     *            the Dockable that is being registered.
     * @return the {@code Dockable} that has been registered.
     * @see org.flexdock.event.RegistrationEvent
     */
    public static Dockable registerDockable(Dockable dockable) {
        if (dockable == null || dockable.getComponent() == null
                || dockable.getDragSources() == null)
            return null;

        if (dockable.getPersistentId() == null)
            throw new IllegalArgumentException(
                    "Dockable must have a non-null persistent ID.");

        DOCKABLES_BY_COMPONENT.put(dockable.getComponent(), dockable);

        // flag the component as dockable, in case it doesn't
        // implement the interface directly
        Component c = dockable.getComponent();
        SwingUtility.putClientProperty(c, Dockable.DOCKABLE_INDICATOR,
                Boolean.TRUE);

        // add drag listeners
        updateDragListeners(dockable);

        // add the dockable as its own listener
        dockable.addDockingListener(dockable);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -