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

📄 basicsplitpanedivider.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                    (getSize().width + right));                }                if (maxX < minX) minX = maxX = 0;            }        }        /**         * Returns true if the dragging session is valid.         */        protected boolean isValid() {            return (maxX > 0);        }        /**         * Returns the new position to put the divider at based on         * the passed in MouseEvent.         */        protected int positionForMouseEvent(MouseEvent e) {	    int newX = (e.getSource() == BasicSplitPaneDivider.this) ?		        (e.getX() + getLocation().x) : e.getX();            newX = Math.min(maxX, Math.max(minX, newX - offset));            return newX;        }        /**         * Returns the x argument, since this is used for horizontal         * splits.         */        protected int getNeededLocation(int x, int y) {            int newX;            newX = Math.min(maxX, Math.max(minX, x - offset));            return newX;        }        protected void continueDrag(int newX, int newY) {            dragDividerTo(getNeededLocation(newX, newY));        }        /**         * Messages dragDividerTo with the new location for the mouse         * event.         */        protected void continueDrag(MouseEvent e) {            dragDividerTo(positionForMouseEvent(e));        }        protected void completeDrag(int x, int y) {            finishDraggingTo(getNeededLocation(x, y));        }        /**         * Messages finishDraggingTo with the new location for the mouse         * event.         */        protected void completeDrag(MouseEvent e) {            finishDraggingTo(positionForMouseEvent(e));        }    } // End of BasicSplitPaneDivider.DragController    /**     * Handles the events during a dragging session for a     * VERTICAL_SPLIT oriented split pane. This continually     * messages <code>dragDividerTo</code> and then when done messages     * <code>finishDraggingTo</code>. When an instance is created it should be     * messaged with <code>isValid</code> to insure that dragging can happen     * (dragging won't be allowed if the two views can not be resized).     */    protected class VerticalDragController extends DragController    {        /* DragControllers ivars are now in terms of y, not x. */        protected VerticalDragController(MouseEvent e) {            super(e);            JSplitPane splitPane = splitPaneUI.getSplitPane();            Component  leftC = splitPane.getLeftComponent();	    Component  rightC = splitPane.getRightComponent();            initialX = getLocation().y;	    if (e.getSource() == BasicSplitPaneDivider.this) {		offset = e.getY();	    }	    else {		offset = e.getY() - initialX;	    }	    if (leftC == null || rightC == null || offset < -1 ||		offset > getSize().height) {		// Don't allow dragging.		maxX = -1;	    }	    else {		Insets     insets = splitPane.getInsets();                if (leftC.isVisible()) {                    minX = leftC.getMinimumSize().height;		    if (insets != null) {			minX += insets.top;		    }                }                else {                    minX = 0;                }                if (rightC.isVisible()) {		    int    bottom = (insets != null) ? insets.bottom : 0;                    maxX = Math.max(0, splitPane.getSize().height -                                    (getSize().height + bottom) -                                    rightC.getMinimumSize().height);                }                else {		    int    bottom = (insets != null) ? insets.bottom : 0;                    maxX = Math.max(0, splitPane.getSize().height -                                    (getSize().height + bottom));                }                if (maxX < minX) minX = maxX = 0;            }        }        /**         * Returns the y argument, since this is used for vertical         * splits.         */        protected int getNeededLocation(int x, int y) {            int newY;            newY = Math.min(maxX, Math.max(minX, y - offset));            return newY;        }        /**         * Returns the new position to put the divider at based on         * the passed in MouseEvent.         */        protected int positionForMouseEvent(MouseEvent e) {	    int newY = (e.getSource() == BasicSplitPaneDivider.this) ?		        (e.getY() + getLocation().y) : e.getY();            newY = Math.min(maxX, Math.max(minX, newY - offset));            return newY;        }    } // End of BasicSplitPaneDividier.VerticalDragController    /**     * Used to layout a <code>BasicSplitPaneDivider</code>.     * Layout for the divider     * involves appropriately moving the left/right buttons around.     * <p>     */    protected class DividerLayout implements LayoutManager    {        public void layoutContainer(Container c) {            if (leftButton != null && rightButton != null &&                c == BasicSplitPaneDivider.this) {                if (splitPane.isOneTouchExpandable()) {		    Insets insets = getInsets();                    if (orientation == JSplitPane.VERTICAL_SPLIT) {			int extraX = (insets != null) ? insets.left : 0;			int blockSize = getHeight();			if (insets != null) {			    blockSize -= (insets.top + insets.bottom);                            blockSize = Math.max(blockSize, 0);			}                        blockSize = Math.min(blockSize, oneTouchSize);                        int y = (c.getSize().height - blockSize) / 2;                        if (!centerOneTouchButtons) {                            y = (insets != null) ? insets.top : 0;                            extraX = 0;                        }                        leftButton.setBounds(extraX + oneTouchOffset, y,                                             blockSize * 2, blockSize);                        rightButton.setBounds(extraX + oneTouchOffset +                                              oneTouchSize * 2, y,                                              blockSize * 2, blockSize);                    }                    else {			int extraY = (insets != null) ? insets.top : 0;			int blockSize = getWidth();			if (insets != null) {			    blockSize -= (insets.left + insets.right);                            blockSize = Math.max(blockSize, 0);			}                        blockSize = Math.min(blockSize, oneTouchSize);                        int x = (c.getSize().width - blockSize) / 2;                        if (!centerOneTouchButtons) {                            x = (insets != null) ? insets.left : 0;                            extraY = 0;                        }                        leftButton.setBounds(x, extraY + oneTouchOffset,                                             blockSize, blockSize * 2);                        rightButton.setBounds(x, extraY + oneTouchOffset +                                              oneTouchSize * 2, blockSize,                                              blockSize * 2);                    }                }                else {                    leftButton.setBounds(-5, -5, 1, 1);                    rightButton.setBounds(-5, -5, 1, 1);                }            }        }        public Dimension minimumLayoutSize(Container c) {            // NOTE: This isn't really used, refer to            // BasicSplitPaneDivider.getPreferredSize for the reason.            // I leave it in hopes of having this used at some point.            if (c != BasicSplitPaneDivider.this || splitPane == null) {                return new Dimension(0,0);            }            Dimension buttonMinSize = null;            if (splitPane.isOneTouchExpandable() && leftButton != null) {                buttonMinSize = leftButton.getMinimumSize();            }            Insets insets = getInsets();            int width = getDividerSize();            int height = width;            if (orientation == JSplitPane.VERTICAL_SPLIT) {                if (buttonMinSize != null) {                    int size = buttonMinSize.height;                    if (insets != null) {                        size += insets.top + insets.bottom;                    }                    height = Math.max(height, size);                }                width = 1;            }            else {                if (buttonMinSize != null) {                    int size = buttonMinSize.width;                    if (insets != null) {                        size += insets.left + insets.right;                    }                    width = Math.max(width, size);                }                height = 1;            }            return new Dimension(width, height);        }        public Dimension preferredLayoutSize(Container c) {            return minimumLayoutSize(c);        }        public void removeLayoutComponent(Component c) {}        public void addLayoutComponent(String string, Component c) {}    } // End of class BasicSplitPaneDivider.DividerLayout    /**     * Listeners installed on the one touch expandable buttons.     */    private class OneTouchActionHandler implements ActionListener {	/** True indicates the resize should go the minimum (top or left)	 * vs false which indicates the resize should go to the maximum.	 */	private boolean toMinimum;	OneTouchActionHandler(boolean toMinimum) {	    this.toMinimum = toMinimum;	}        public void actionPerformed(ActionEvent e) {            Insets  insets = splitPane.getInsets();	    int     lastLoc = splitPane.getLastDividerLocation();            int     currentLoc = splitPaneUI.getDividerLocation(splitPane);	    int     newLoc;	    // We use the location from the UI directly, as the location the	    // JSplitPane itself maintains is not necessarly correct.	    if (toMinimum) {		if (orientation == JSplitPane.VERTICAL_SPLIT) {		    if (currentLoc >= (splitPane.getHeight() -				       insets.bottom - getHeight())) {			int maxLoc = splitPane.getMaximumDividerLocation();			newLoc = Math.min(lastLoc, maxLoc);			splitPaneUI.setKeepHidden(false);                    }		    else {			newLoc = insets.top;			splitPaneUI.setKeepHidden(true);                    }		}		else {		    if (currentLoc >= (splitPane.getWidth() -				       insets.right - getWidth())) {			int maxLoc = splitPane.getMaximumDividerLocation();			newLoc = Math.min(lastLoc, maxLoc);			splitPaneUI.setKeepHidden(false);                    }		    else {			newLoc = insets.left;			splitPaneUI.setKeepHidden(true);                    }		}	    }	    else {		if (orientation == JSplitPane.VERTICAL_SPLIT) {		    if (currentLoc == insets.top) {			int maxLoc = splitPane.getMaximumDividerLocation();			newLoc = Math.min(lastLoc, maxLoc);			splitPaneUI.setKeepHidden(false);                    }		    else {			newLoc = splitPane.getHeight() - getHeight() -			         insets.top;			splitPaneUI.setKeepHidden(true);                    }		}		else {		    if (currentLoc == insets.left) {			int maxLoc = splitPane.getMaximumDividerLocation();			newLoc = Math.min(lastLoc, maxLoc);			splitPaneUI.setKeepHidden(false);                    }		    else {			newLoc = splitPane.getWidth() - getWidth() - 			         insets.left;			splitPaneUI.setKeepHidden(true);		    }		}	    }	    if (currentLoc != newLoc) {		splitPane.setDividerLocation(newLoc);		// We do this in case the dividers notion of the location		// differs from the real location.		splitPane.setLastDividerLocation(currentLoc);	    }        }    } // End of class BasicSplitPaneDivider.LeftActionListener}

⌨️ 快捷键说明

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