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

📄 basicdockpanel.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        dock(getWrapper(outter), getWrapper(inner), idx);    }    /**     * Dock the given child onto the given parent, which is itself a     * child of this class.     */    protected void dock(DockWrapper outter, DockWrapper inner) {        dock(outter, inner, -1);    }    /**     * Dock the given child onto the given parent, which is itself a     * child of this class.     */    protected void dock(DockWrapper outter, DockWrapper inner, int idx) {        freeWrapper(inner);        outter.dock(inner, idx);    }    /**     * Set the component to an internal frame     */    public void internalFrame(JComponent child) {        internalFrame(getWrapper(child));    }    /**     * Set the component to an internal frame     */    protected void internalFrame(DockWrapper wrapper) {        freeWrapper(wrapper);        internalFrameWrappers.add(wrapper);        wrapper.makeInternalFrame();    }    /**     * Set the component to an external frame     */    public void externalFrame(JComponent child) {        externalFrame(getWrapper(child));    }    /**     * Set the component to an internal frame     */    protected void externalFrame(DockWrapper wrapper) {        freeWrapper(wrapper);        externalFrameWrappers.add(wrapper);        wrapper.makeExternalFrame();    }    /**     * Dock the given child somewhere...     */    public void dockSomewhere(JComponent child) {        dockSomewhere(getWrapper(child));    }    /**     * Dock the given child somewhere...     */    protected void dockSomewhere(DockWrapper wrapper) {        if (wrapper == null) {            throw new RuntimeException("Can't dock null!");        }        if (wrapper.canDockNorth()) {            dockNorth(wrapper);            return;        }        if (wrapper.canDockWest()) {            dockWest(wrapper);            return;        }        if (wrapper.canDockSouth()) {            dockSouth(wrapper);            return;        }        if (wrapper.canDockEast()) {            dockEast(wrapper);            return;        }        if (wrapper.canInternalFrame()) {            internalFrame(wrapper);            return;        }        if (wrapper.canExternalFrame()) {            externalFrame(wrapper);            return;        }        Debug.error("DockPanel: Can't dock anywhere...");        externalFrame(wrapper);    }    //Overwrite from Component:    ///////////////////////////    /**     * We need to handle adding the component specially. If it is the     * background, do one thing. Otherwise wrap it up...     */    public Component add(Component comp) {        add(comp, new DockConstraint());        return comp;    }    /**     * We need to handle adding the component specially. If it is the     * background, do one thing. Otherwise wrap it up...     */    public void add(Component comp, Object constraints) {        if (comp == null) {            throw new RuntimeException("Can't add null component to DockPanel");        }        if (comp instanceof DockWrapper) {            Debug.error("DockPanel: Unexpected call to add with a DockWrapper");            super.add(comp, constraints);        } else {            if (constraints.equals(BACKGROUND)) {                background = (JComponent) comp;                super.add(comp, constraints);                setLayer(comp, BACKGROUND_LAYER.intValue());            } else if (constraints instanceof DockConstraint) {                if (comp instanceof JToolBar) {                    JToolBar t = (JToolBar) comp;                    t.setFloatable(false);                }                setConstraint((JComponent) comp, (DockConstraint) constraints);                if (!alreadyAdded(comp)) {                    createDockWrapper((JComponent) comp);                }            } else {                Debug.error("DockPanel: Unexpected constraint: " + constraints);            }        }    }    public void remove(Component comp) {        if (comp == null) {            Debug.error("Trying to remove null component");        }        if (comp instanceof DockWrapper) {            freeWrapper((DockWrapper) comp);            removeWrapper((DockWrapper) comp);        } else {            DockWrapper w = getWrapper((JComponent) comp);            if (w != null) {                super.remove(w);            }            super.remove(comp);        }    }    public void removeAll() {        for (int i = 0; i < getComponentCount(); i++) {            JComponent comp = (JComponent) getComponent(i);            if (comp instanceof DockWrapper) {                freeWrapper((DockWrapper) comp);                removeWrapper((DockWrapper) comp);            }        }        super.removeAll();    }    ////    ////Package/Protected/Private Implementation Functions:    ///////////////////////////////////////////////////////    ///////////////////////////////////////////////////////    protected DockWrapper getNorth() {        return north;    }    protected DockWrapper getSouth() {        return south;    }    protected DockWrapper getEast() {        return east;    }    protected DockWrapper getWest() {        return west;    }    protected int getOverlapTolerance() {        return 5;    }    //Wrapper Functions:    /////////////////////    protected void setWrapper(JComponent child, DockWrapper w) {        childToWrapper.put(child, w);    }    protected DockWrapper getWrapper(JComponent child) {        return (DockWrapper) childToWrapper.get(child);    }    protected void removeWrapper(DockWrapper wrapper) {        for (Iterator iter = wrapper.getChildren().iterator(); iter.hasNext();) {            JComponent j = (JComponent) iter.next();            childToWrapper.remove(j);        }    }    /**     * Remove the wrapper from wherever it is currently     */    protected void freeWrapper(DockWrapper w) {        if (externalFrameWrappers.remove(w)) {            w.freeWrapper();            return;        }        if (internalFrameWrappers.remove(w)) {            w.freeWrapper();            return;        }        if (north.freeWrapper(w)) {            return;        }        if (south.freeWrapper(w)) {            return;        }        if (east.freeWrapper(w)) {            return;        }        if (west.freeWrapper(w)) {            return;        }    }    //Package Accessors for access from DockWrapper:    ////////////////////////////////////////////////    /**     * Get a list of DockConstraint objects for a list of children.     *      * @param children a List of JComponent children     * @return a List of DockConstraints     */    List getConstraints(List children) {        List ret = new ArrayList(children.size());        for (Iterator iter = children.iterator(); iter.hasNext();) {            JComponent child = (JComponent) iter.next();            ret.add(getConstraint(child));        }        return ret;    }    /** Create a DockWrapper for the given JComponent. */    DockWrapper createDockWrapper(JComponent comp) {        DockWrapper dw = new DockWrapper(this);        setWrapper(comp, dw);        dw.addChild(comp);        dockSomewhere(comp);        return dw;    }    /** Pass back to add the dockwrapper to the layer. */    void addDockWrapper(DockWrapper dw) {        super.add(dw, null);    }    /** Pass back to remove the dockwrapper from the layer. */    void removeDockWrapper(DockWrapper dw) {        super.remove(dw);    }    /**     * Returns true if the component has already been added to a     * DockWrapper that has been added to the DockPanel.     */    boolean alreadyAdded(Component comp) {        Component components[] = getComponents();        for (int i = 0; i < components.length; i++) {            Component c = components[i];            if (c instanceof DockWrapper) {                DockWrapper dw = (DockWrapper) c;                if (dw.getChildren().contains(comp)) {                    return true;                }            }        }        return false;    }}

⌨️ 快捷键说明

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