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

📄 basicsplitpaneui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     * Sets the divider to use when the splitPane is configured to     * not continuously layout. This divider will only be used during a     * dragging session. It is recommended that the passed in component     * be a heavy weight.     */    protected void setNonContinuousLayoutDivider(Component newDivider) {        setNonContinuousLayoutDivider(newDivider, true);    }    /**     * Sets the divider to use.     */    protected void setNonContinuousLayoutDivider(Component newDivider,        boolean rememberSizes) {        rememberPaneSizes = rememberSizes;        if(nonContinuousLayoutDivider != null && splitPane != null) {            splitPane.remove(nonContinuousLayoutDivider);        }        nonContinuousLayoutDivider = newDivider;    }    private void addHeavyweightDivider() {        if(nonContinuousLayoutDivider != null && splitPane != null) {            /* Needs to remove all the components and re-add them! YECK! */	    // This is all done so that the nonContinuousLayoutDivider will	    // be drawn on top of the other components, without this, one	    // of the heavyweights will draw over the divider!            Component             leftC = splitPane.getLeftComponent();            Component             rightC = splitPane.getRightComponent();	    int                   lastLocation = splitPane.		                              getDividerLocation();            if(leftC != null)                splitPane.setLeftComponent(null);            if(rightC != null)                splitPane.setRightComponent(null);            splitPane.remove(divider);            splitPane.add(nonContinuousLayoutDivider, BasicSplitPaneUI.                          NON_CONTINUOUS_DIVIDER,                          splitPane.getComponentCount());            splitPane.setLeftComponent(leftC);            splitPane.setRightComponent(rightC);            splitPane.add(divider, JSplitPane.DIVIDER);            if(rememberPaneSizes) {		splitPane.setDividerLocation(lastLocation);	    }         }     }    /**     * Returns the divider to use when the splitPane is configured to     * not continuously layout. This divider will only be used during a     * dragging session.     */    public Component getNonContinuousLayoutDivider() {        return nonContinuousLayoutDivider;    }    /**     * Returns the splitpane this instance is currently contained     * in.     */    public JSplitPane getSplitPane() {        return splitPane;    }    /**     * Creates the default divider.     */    public BasicSplitPaneDivider createDefaultDivider() {        return new BasicSplitPaneDivider(this);    }    /**     * Messaged to reset the preferred sizes.     */    public void resetToPreferredSizes(JSplitPane jc) {        if(splitPane != null) {            layoutManager.resetToPreferredSizes();            splitPane.revalidate();	    splitPane.repaint();        }    }    /**     * Sets the location of the divider to location.     */    public void setDividerLocation(JSplitPane jc, int location) {	if (!ignoreDividerLocationChange) {	    dividerLocationIsSet = true;	    splitPane.revalidate();	    splitPane.repaint();            if (keepHidden) {				Insets insets = splitPane.getInsets();		int orientation = splitPane.getOrientation(); 		if ((orientation == JSplitPane.VERTICAL_SPLIT &&		     location != insets.top &&		     location != splitPane.getHeight()-divider.getHeight()-insets.top) ||		    (orientation == JSplitPane.HORIZONTAL_SPLIT &&		     location != insets.left &&		     location != splitPane.getWidth()-divider.getWidth()-insets.left)) {  		    setKeepHidden(false);		}	    }	}	else {	    ignoreDividerLocationChange = false;	}    }    /**     * Returns the location of the divider, which may differ from what     * the splitpane thinks the location of the divider is.     */    public int getDividerLocation(JSplitPane jc) {        if(orientation == JSplitPane.HORIZONTAL_SPLIT)            return divider.getLocation().x;        return divider.getLocation().y;    }    /**     * Gets the minimum location of the divider.     */    public int getMinimumDividerLocation(JSplitPane jc) {        int       minLoc = 0;        Component leftC = splitPane.getLeftComponent();        if ((leftC != null) && (leftC.isVisible())) {            Insets    insets = splitPane.getInsets();            Dimension minSize = leftC.getMinimumSize();            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                minLoc = minSize.width;            } else {                minLoc = minSize.height;            }            if(insets != null) {                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                    minLoc += insets.left;                } else {                    minLoc += insets.top;                }            }        }        return minLoc;    }    /**     * Gets the maximum location of the divider.     */    public int getMaximumDividerLocation(JSplitPane jc) {        Dimension splitPaneSize = splitPane.getSize();        int       maxLoc = 0;        Component rightC = splitPane.getRightComponent();        if (rightC != null) {            Insets    insets = splitPane.getInsets();            Dimension minSize = new Dimension(0, 0);            if (rightC.isVisible()) {                minSize = rightC.getMinimumSize();            }            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                maxLoc = splitPaneSize.width - minSize.width;            } else {                maxLoc = splitPaneSize.height - minSize.height;             }            maxLoc -= dividerSize;            if(insets != null) {                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                    maxLoc -= insets.right;                } else {                    maxLoc -= insets.top;                }            }        }        return Math.max(getMinimumDividerLocation(splitPane), maxLoc);    }    /**     * Messaged after the JSplitPane the receiver is providing the look     * and feel for paints its children.     */    public void finishedPaintingChildren(JSplitPane jc, Graphics g) {        if(jc == splitPane && getLastDragLocation() != -1 &&           !isContinuousLayout() && !draggingHW) {            Dimension      size = splitPane.getSize();            g.setColor(dividerDraggingColor);            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                g.fillRect(getLastDragLocation(), 0, dividerSize - 1,                           size.height - 1);            } else {                g.fillRect(0, lastDragLocation, size.width - 1,                           dividerSize - 1);            }        }    }    /**     * Messaged to paint the look and feel.     */    public void paint(Graphics g, JComponent jc) {	if (!painted && splitPane.getDividerLocation()<0) {	    ignoreDividerLocationChange = true;	    splitPane.setDividerLocation(getDividerLocation(splitPane));	}	painted = true;    }    /**     * Returns the preferred size for the passed in component,     * This is passed off to the current layoutmanager.     */    public Dimension getPreferredSize(JComponent jc) {        if(splitPane != null)            return layoutManager.preferredLayoutSize(splitPane);        return new Dimension(0, 0);    }    /**     * Returns the minimum size for the passed in component,     * This is passed off to the current layoutmanager.     */    public Dimension getMinimumSize(JComponent jc) {        if(splitPane != null)            return layoutManager.minimumLayoutSize(splitPane);        return new Dimension(0, 0);    }    /**     * Returns the maximum size for the passed in component,     * This is passed off to the current layoutmanager.     */    public Dimension getMaximumSize(JComponent jc) {        if(splitPane != null)            return layoutManager.maximumLayoutSize(splitPane);        return new Dimension(0, 0);    }    /**     * Returns the insets. The insets are returned from the border insets     * of the current border.     */    public Insets getInsets(JComponent jc) {        return null;    }    /**     * Resets the layout manager based on orientation and messages it     * with invalidateLayout to pull in appropriate Components.     */    protected void resetLayoutManager() {        if(orientation == JSplitPane.HORIZONTAL_SPLIT) {            layoutManager = new BasicHorizontalLayoutManager(0);        } else {            layoutManager = new BasicHorizontalLayoutManager(1);        }        splitPane.setLayout(layoutManager);        layoutManager.updateComponents();        splitPane.revalidate();        splitPane.repaint();    }    /**     * Set the value to indicate if one of the splitpane sides is expanded.     */    void setKeepHidden(boolean keepHidden) {	this.keepHidden = keepHidden;    }    /**     * The value returned indicates if one of the splitpane sides is expanded.     * @return true if one of the splitpane sides is expanded, false otherwise.     */    private boolean getKeepHidden() {	return keepHidden;    }    /**     * Should be messaged before the dragging session starts, resets     * lastDragLocation and dividerSize.     */    protected void startDragging() {        Component       leftC = splitPane.getLeftComponent();        Component       rightC = splitPane.getRightComponent();        ComponentPeer   cPeer;        beginDragDividerLocation = getDividerLocation(splitPane);        draggingHW = false;        if(leftC != null && (cPeer = leftC.getPeer()) != null &&           !(cPeer instanceof LightweightPeer)) {            draggingHW = true;        } else if(rightC != null && (cPeer = rightC.getPeer()) != null                  && !(cPeer instanceof LightweightPeer)) {            draggingHW = true;        }        if(orientation == JSplitPane.HORIZONTAL_SPLIT) {            setLastDragLocation(divider.getBounds().x);            dividerSize = divider.getSize().width;            if(!isContinuousLayout() && draggingHW) {                nonContinuousLayoutDivider.setBounds                        (getLastDragLocation(), 0, dividerSize,                         splitPane.getHeight());		      addHeavyweightDivider();            }        } else {            setLastDragLocation(divider.getBounds().y);            dividerSize = divider.getSize().height;            if(!isContinuousLayout() && draggingHW) {                nonContinuousLayoutDivider.setBounds                        (0, getLastDragLocation(), splitPane.getWidth(),                         dividerSize);		      addHeavyweightDivider();            }        }    }    /**     * Messaged during a dragging session to move the divider to the     * passed in location. If continuousLayout is true the location is     * reset and the splitPane validated.     */    protected void dragDividerTo(int location) {        if(getLastDragLocation() != location) {            if(isContinuousLayout()) {		splitPane.setDividerLocation(location);                setLastDragLocation(location);            } else {                int lastLoc = getLastDragLocation();                setLastDragLocation(location);                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                    if(draggingHW) {                        nonContinuousLayoutDivider.setLocation(                            getLastDragLocation(), 0);                    } else {			int   splitHeight = splitPane.getHeight();                        splitPane.repaint(lastLoc, 0, dividerSize,                                          splitHeight);                        splitPane.repaint(location, 0, dividerSize,                                          splitHeight);                    }                } else {                    if(draggingHW) {                        nonContinuousLayoutDivider.setLocation(0,                            getLastDragLocation());                    } else {			int    splitWidth = splitPane.getWidth();                        splitPane.repaint(0, lastLoc, splitWidth,                                          dividerSize);                        splitPane.repaint(0, location, splitWidth,                                          dividerSize);                    }                }            }        }    }    /**     * Messaged to finish the dragging session. If not continuous display     * the dividers location will be reset.     */    protected void finishDraggingTo(int location) {        dragDividerTo(location);        setLastDragLocation(-1);        if(!isContinuousLayout()) {            Component   leftC = splitPane.getLeftComponent();            Rectangle   leftBounds = leftC.getBounds();	    if (draggingHW) {		if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                    nonContinuousLayoutDivider.setLocation(-dividerSize, 0);		}		else {                    nonContinuousLayoutDivider.setLocation(0, -dividerSize);		}		splitPane.remove(nonContinuousLayoutDivider);	    }	    splitPane.setDividerLocation(location);        }    }    /**     * As of Java 2 platform v1.3 this method is no longer used. Instead     * you should set the border on the divider.     * <p>     * Returns the width of one side of the divider border.     *     * @deprecated As of Java 2 platform v1.3, instead set the border on the     * divider.

⌨️ 快捷键说明

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