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

📄 basicsplitpaneui.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    splitPane.setDividerLocation(splitPane.getWidth() -						 rightI);                }            }        }    }    static class KeyboardEndAction extends AbstractAction {        public void actionPerformed(ActionEvent ev) {	    JSplitPane splitPane = (JSplitPane)ev.getSource();	    BasicSplitPaneUI ui = (BasicSplitPaneUI)splitPane.getUI();            if (ui.dividerKeyboardResize) {		Insets   insets = splitPane.getInsets();		int      bottomI = (insets != null) ? insets.bottom : 0;		int      rightI = (insets != null) ? insets.right : 0;                if (ui.orientation == JSplitPane.VERTICAL_SPLIT) {                    splitPane.setDividerLocation(splitPane.getHeight() -                                       bottomI);                }                else {                    splitPane.setDividerLocation(splitPane.getWidth() -						 rightI);                }            }        }    }    /**     * Implementation of an ActionListener that the JSplitPane UI uses for     * handling specific key presses.     * <p>     * This inner class is marked &quot;public&quot; due to a compiler bug.     * This class should be treated as a &quot;protected&quot; inner class.     * Instantiate it only within subclasses of BasicSplitPaneUI.     */    public class KeyboardResizeToggleHandler implements ActionListener    {        public void actionPerformed(ActionEvent ev) {            if (!dividerKeyboardResize) {                splitPane.requestFocus();            }        }    }    static class KeyboardResizeToggleAction extends AbstractAction {        public void actionPerformed(ActionEvent ev) {	    JSplitPane splitPane = (JSplitPane)ev.getSource();	    BasicSplitPaneUI ui = (BasicSplitPaneUI)splitPane.getUI();            if (!ui.dividerKeyboardResize) {                splitPane.requestFocus();	    } else {		JSplitPane parentSplitPane =		    (JSplitPane)SwingUtilities.getAncestorOfClass(JSplitPane.class, splitPane);		if (parentSplitPane!=null) {		    parentSplitPane.requestFocus();		}            }        }    }    /**     * ActionListener that will focus on the opposite component that     * has focus. EG if the left side has focus, this will transfer focus     * to the right component.     */    static class ToggleSideFocusAction extends AbstractAction {	public void actionPerformed(ActionEvent ae) {	    JSplitPane splitPane = (JSplitPane)ae.getSource();	    Component left = splitPane.getLeftComponent();	    Component right = splitPane.getRightComponent();	    KeyboardFocusManager manager =		KeyboardFocusManager.getCurrentKeyboardFocusManager();	    Component focus = manager.getFocusOwner();	    Component focusOn = getNextSide(splitPane, focus);	    if (focusOn != null) {		// don't change the focus if the new focused component belongs		// to the same splitpane and the same side		if ( focus!=null &&		     ( (SwingUtilities.isDescendingFrom(focus, left) &&			SwingUtilities.isDescendingFrom(focusOn, left)) ||		       (SwingUtilities.isDescendingFrom(focus, right) &&			SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {		    return;		} 		BasicLookAndFeel.compositeRequestFocus(focusOn);	    }	}	private Component getNextSide(JSplitPane splitPane, Component focus) {	    Component left = splitPane.getLeftComponent();	    Component right = splitPane.getRightComponent();	    Component next = null;	    if (focus!=null && SwingUtilities.isDescendingFrom(focus, left) &&		right!=null) {		next = getFirstAvailableComponent(right);		if (next != null) {		    return next;		}	    }	    JSplitPane parentSplitPane = (JSplitPane)SwingUtilities.getAncestorOfClass(JSplitPane.class, splitPane);	    if (parentSplitPane!=null) {		// focus next side of the parent split pane		next = getNextSide(parentSplitPane, focus);	    } else {		next = getFirstAvailableComponent(left);		if (next == null) {		    next = getFirstAvailableComponent(right);		}	    }	    return next;	}	private Component getFirstAvailableComponent(Component c) {	    if (c!=null && c instanceof JSplitPane) {		JSplitPane sp = (JSplitPane)c;		Component left = getFirstAvailableComponent(sp.getLeftComponent());		if (left != null) {		    c = left;		} else {		    c = getFirstAvailableComponent(sp.getRightComponent());		}	    }	    return c;	}    }    /**     * Action that will move focus out of the splitpane to the next     * component (if present) if direction > 0 or to the previous     * component (if present) if direction < 0     */    static class MoveFocusOutAction extends AbstractAction {	private int direction;	public MoveFocusOutAction(int newDirection) {	    direction = newDirection;	}	public void actionPerformed(ActionEvent ae) {	    JSplitPane splitPane = (JSplitPane)ae.getSource();	    Container rootAncestor = splitPane.getFocusCycleRootAncestor();	    FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();	    Component focusOn = (direction > 0) ?		policy.getComponentAfter(rootAncestor, splitPane) :		policy.getComponentBefore(rootAncestor, splitPane);	    HashSet focusFrom = new HashSet();	    if (splitPane.isAncestorOf(focusOn)) {		do {		    focusFrom.add(focusOn);		    rootAncestor = focusOn.getFocusCycleRootAncestor();		    policy = rootAncestor.getFocusTraversalPolicy();		    focusOn = (direction > 0) ?			policy.getComponentAfter(rootAncestor, focusOn) :			policy.getComponentBefore(rootAncestor, focusOn);		} while (splitPane.isAncestorOf(focusOn) &&			 !focusFrom.contains(focusOn));	    }	    if ( focusOn!=null && !splitPane.isAncestorOf(focusOn) ) {		focusOn.requestFocus();	    }	}    }        /**     * Returns the divider between the top Components.     */    public BasicSplitPaneDivider getDivider() {        return divider;    }    /**     * Returns the default non continuous layout divider, which is an     * instanceof Canvas that fills the background in dark gray.     */    protected Component createDefaultNonContinuousLayoutDivider() {        return new Canvas() {            public void paint(Graphics g) {                if(!isContinuousLayout() && getLastDragLocation() != -1) {                    Dimension      size = splitPane.getSize();                    g.setColor(Color.darkGray);                    if(orientation == JSplitPane.HORIZONTAL_SPLIT) {                        g.fillRect(0, 0, dividerSize - 1, size.height - 1);                    } else {                        g.fillRect(0, 0, size.width - 1, dividerSize - 1);                    }                }            }        };    }    /**     * 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();            layoutManager.layoutContainer(splitPane);	    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();	}	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(Color.darkGray);            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;

⌨️ 快捷键说明

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