0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage javax.swing.plaf.basic;
0N/A
0N/A
0N/Aimport sun.swing.DefaultLookup;
0N/Aimport sun.swing.UIAction;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.Border;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.peer.ComponentPeer;
0N/Aimport java.awt.peer.LightweightPeer;
0N/Aimport java.beans.*;
0N/Aimport java.util.*;
0N/Aimport javax.swing.plaf.SplitPaneUI;
0N/Aimport javax.swing.plaf.ComponentUI;
0N/Aimport javax.swing.plaf.UIResource;
0N/Aimport sun.swing.SwingUtilities2;
0N/A
0N/A
0N/A/**
0N/A * A Basic L&F implementation of the SplitPaneUI.
0N/A *
0N/A * @author Scott Violet
0N/A * @author Steve Wilson
0N/A * @author Ralph Kar
0N/A */
0N/Apublic class BasicSplitPaneUI extends SplitPaneUI
0N/A{
0N/A /**
0N/A * The divider used for non-continuous layout is added to the split pane
0N/A * with this object.
0N/A */
0N/A protected static final String NON_CONTINUOUS_DIVIDER =
0N/A "nonContinuousDivider";
0N/A
0N/A
0N/A /**
0N/A * How far (relative) the divider does move when it is moved around by
0N/A * the cursor keys on the keyboard.
0N/A */
0N/A protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3;
0N/A
0N/A
0N/A /**
0N/A * JSplitPane instance this instance is providing
0N/A * the look and feel for.
0N/A */
0N/A protected JSplitPane splitPane;
0N/A
0N/A
0N/A /**
0N/A * LayoutManager that is created and placed into the split pane.
0N/A */
0N/A protected BasicHorizontalLayoutManager layoutManager;
0N/A
0N/A
0N/A /**
0N/A * Instance of the divider for this JSplitPane.
0N/A */
0N/A protected BasicSplitPaneDivider divider;
0N/A
0N/A
0N/A /**
0N/A * Instance of the PropertyChangeListener for this JSplitPane.
0N/A */
0N/A protected PropertyChangeListener propertyChangeListener;
0N/A
0N/A
0N/A /**
0N/A * Instance of the FocusListener for this JSplitPane.
0N/A */
0N/A protected FocusListener focusListener;
0N/A
0N/A private Handler handler;
0N/A
0N/A
0N/A /**
0N/A * Keys to use for forward focus traversal when the JComponent is
0N/A * managing focus.
0N/A */
1833N/A private Set<KeyStroke> managingFocusForwardTraversalKeys;
0N/A
0N/A /**
0N/A * Keys to use for backward focus traversal when the JComponent is
0N/A * managing focus.
0N/A */
1833N/A private Set<KeyStroke> managingFocusBackwardTraversalKeys;
0N/A
0N/A
0N/A /**
0N/A * The size of the divider while the dragging session is valid.
0N/A */
0N/A protected int dividerSize;
0N/A
0N/A
0N/A /**
0N/A * Instance for the shadow of the divider when non continuous layout
0N/A * is being used.
0N/A */
0N/A protected Component nonContinuousLayoutDivider;
0N/A
0N/A
0N/A /**
0N/A * Set to true in startDragging if any of the children
0N/A * (not including the nonContinuousLayoutDivider) are heavy weights.
0N/A */
0N/A protected boolean draggingHW;
0N/A
0N/A
0N/A /**
0N/A * Location of the divider when the dragging session began.
0N/A */
0N/A protected int beginDragDividerLocation;
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke upKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke downKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke leftKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke rightKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke homeKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke endKey;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected KeyStroke dividerResizeToggleKey;
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener keyboardUpLeftListener;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener keyboardDownRightListener;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener keyboardHomeListener;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener keyboardEndListener;
0N/A /**
0N/A * As of Java 2 platform v1.3 this previously undocumented field is no
0N/A * longer used.
0N/A * Key bindings are now defined by the LookAndFeel, please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener keyboardResizeToggleListener;
0N/A
0N/A
0N/A // Private data of the instance
0N/A private int orientation;
0N/A private int lastDragLocation;
0N/A private boolean continuousLayout;
0N/A private boolean dividerKeyboardResize;
0N/A private boolean dividerLocationIsSet; // needed for tracking
0N/A // the first occurrence of
0N/A // setDividerLocation()
0N/A private Color dividerDraggingColor;
0N/A private boolean rememberPaneSizes;
0N/A
0N/A // Indicates wether the one of splitpane sides is expanded
0N/A private boolean keepHidden = false;
0N/A
0N/A /** Indicates that we have painted once. */
0N/A // This is used by the LayoutManager to determine when it should use
0N/A // the divider location provided by the JSplitPane. This is used as there
0N/A // is no way to determine when the layout process has completed.
0N/A boolean painted;
0N/A /** If true, setDividerLocation does nothing. */
0N/A boolean ignoreDividerLocationChange;
0N/A
0N/A
0N/A /**
0N/A * Creates a new BasicSplitPaneUI instance
0N/A */
0N/A public static ComponentUI createUI(JComponent x) {
0N/A return new BasicSplitPaneUI();
0N/A }
0N/A
0N/A static void loadActionMap(LazyActionMap map) {
0N/A map.put(new Actions(Actions.NEGATIVE_INCREMENT));
0N/A map.put(new Actions(Actions.POSITIVE_INCREMENT));
0N/A map.put(new Actions(Actions.SELECT_MIN));
0N/A map.put(new Actions(Actions.SELECT_MAX));
0N/A map.put(new Actions(Actions.START_RESIZE));
0N/A map.put(new Actions(Actions.TOGGLE_FOCUS));
0N/A map.put(new Actions(Actions.FOCUS_OUT_FORWARD));
0N/A map.put(new Actions(Actions.FOCUS_OUT_BACKWARD));
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Installs the UI.
0N/A */
0N/A public void installUI(JComponent c) {
0N/A splitPane = (JSplitPane) c;
0N/A dividerLocationIsSet = false;
0N/A dividerKeyboardResize = false;
0N/A keepHidden = false;
0N/A installDefaults();
0N/A installListeners();
0N/A installKeyboardActions();
0N/A setLastDragLocation(-1);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Installs the UI defaults.
0N/A */
0N/A protected void installDefaults(){
0N/A LookAndFeel.installBorder(splitPane, "SplitPane.border");
0N/A LookAndFeel.installColors(splitPane, "SplitPane.background",
0N/A "SplitPane.foreground");
0N/A LookAndFeel.installProperty(splitPane, "opaque", Boolean.TRUE);
0N/A
0N/A if (divider == null) divider = createDefaultDivider();
0N/A divider.setBasicSplitPaneUI(this);
0N/A
0N/A Border b = divider.getBorder();
0N/A
0N/A if (b == null || !(b instanceof UIResource)) {
0N/A divider.setBorder(UIManager.getBorder("SplitPaneDivider.border"));
0N/A }
0N/A
0N/A dividerDraggingColor = UIManager.getColor("SplitPaneDivider.draggingColor");
0N/A
0N/A setOrientation(splitPane.getOrientation());
0N/A
3461N/A // note: don't rename this temp variable to dividerSize
3461N/A // since it will conflict with "this.dividerSize" field
3461N/A Integer temp = (Integer)UIManager.get("SplitPane.dividerSize");
3461N/A LookAndFeel.installProperty(splitPane, "dividerSize", temp == null? 10: temp);
0N/A
0N/A divider.setDividerSize(splitPane.getDividerSize());
0N/A dividerSize = divider.getDividerSize();
0N/A splitPane.add(divider, JSplitPane.DIVIDER);
0N/A
0N/A setContinuousLayout(splitPane.isContinuousLayout());
0N/A
0N/A resetLayoutManager();
0N/A
0N/A /* Install the nonContinuousLayoutDivider here to avoid having to
0N/A add/remove everything later. */
0N/A if(nonContinuousLayoutDivider == null) {
0N/A setNonContinuousLayoutDivider(
0N/A createDefaultNonContinuousLayoutDivider(),
0N/A true);
0N/A } else {
0N/A setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true);
0N/A }
0N/A
0N/A // focus forward traversal key
0N/A if (managingFocusForwardTraversalKeys==null) {
614N/A managingFocusForwardTraversalKeys = new HashSet<KeyStroke>();
0N/A managingFocusForwardTraversalKeys.add(
0N/A KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
0N/A }
0N/A splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0N/A managingFocusForwardTraversalKeys);
0N/A // focus backward traversal key
0N/A if (managingFocusBackwardTraversalKeys==null) {
614N/A managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>();
0N/A managingFocusBackwardTraversalKeys.add(
0N/A KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
0N/A }
0N/A splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
0N/A managingFocusBackwardTraversalKeys);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Installs the event listeners for the UI.
0N/A */
0N/A protected void installListeners() {
0N/A if ((propertyChangeListener = createPropertyChangeListener()) !=
0N/A null) {
0N/A splitPane.addPropertyChangeListener(propertyChangeListener);
0N/A }
0N/A
0N/A if ((focusListener = createFocusListener()) != null) {
0N/A splitPane.addFocusListener(focusListener);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Installs the keyboard actions for the UI.
0N/A */
0N/A protected void installKeyboardActions() {
0N/A InputMap km = getInputMap(JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0N/A
0N/A SwingUtilities.replaceUIInputMap(splitPane, JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
0N/A km);
0N/A LazyActionMap.installLazyActionMap(splitPane, BasicSplitPaneUI.class,
0N/A "SplitPane.actionMap");
0N/A }
0N/A
0N/A InputMap getInputMap(int condition) {
0N/A if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
0N/A return (InputMap)DefaultLookup.get(splitPane, this,
0N/A "SplitPane.ancestorInputMap");
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Uninstalls the UI.
0N/A */
0N/A public void uninstallUI(JComponent c) {
0N/A uninstallKeyboardActions();
0N/A uninstallListeners();
0N/A uninstallDefaults();
0N/A dividerLocationIsSet = false;
0N/A dividerKeyboardResize = false;
0N/A splitPane = null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Uninstalls the UI defaults.
0N/A */
0N/A protected void uninstallDefaults() {
0N/A if(splitPane.getLayout() == layoutManager) {
0N/A splitPane.setLayout(null);
0N/A }
0N/A
0N/A if(nonContinuousLayoutDivider != null) {
0N/A splitPane.remove(nonContinuousLayoutDivider);
0N/A }
0N/A
0N/A LookAndFeel.uninstallBorder(splitPane);
0N/A
0N/A Border b = divider.getBorder();
0N/A
0N/A if (b instanceof UIResource) {
0N/A divider.setBorder(null);
0N/A }
0N/A
0N/A splitPane.remove(divider);
0N/A divider.setBasicSplitPaneUI(null);
0N/A layoutManager = null;
0N/A divider = null;
0N/A nonContinuousLayoutDivider = null;
0N/A
0N/A setNonContinuousLayoutDivider(null);
0N/A
0N/A // sets the focus forward and backward traversal keys to null
0N/A // to restore the defaults
0N/A splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
0N/A splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Uninstalls the event listeners for the UI.
0N/A */
0N/A protected void uninstallListeners() {
0N/A if (propertyChangeListener != null) {
0N/A splitPane.removePropertyChangeListener(propertyChangeListener);
0N/A propertyChangeListener = null;
0N/A }
0N/A if (focusListener != null) {
0N/A splitPane.removeFocusListener(focusListener);
0N/A focusListener = null;
0N/A }
0N/A
0N/A keyboardUpLeftListener = null;
0N/A keyboardDownRightListener = null;
0N/A keyboardHomeListener = null;
0N/A keyboardEndListener = null;
0N/A keyboardResizeToggleListener = null;
0N/A handler = null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Uninstalls the keyboard actions for the UI.
0N/A */
0N/A protected void uninstallKeyboardActions() {
0N/A SwingUtilities.replaceUIActionMap(splitPane, null);
0N/A SwingUtilities.replaceUIInputMap(splitPane, JComponent.
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
0N/A null);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a PropertyChangeListener for the JSplitPane UI.
0N/A */
0N/A protected PropertyChangeListener createPropertyChangeListener() {
0N/A return getHandler();
0N/A }
0N/A
0N/A private Handler getHandler() {
0N/A if (handler == null) {
0N/A handler = new Handler();
0N/A }
0N/A return handler;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a FocusListener for the JSplitPane UI.
0N/A */
0N/A protected FocusListener createFocusListener() {
0N/A return getHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no
0N/A * longer used. Subclassers previously using this method should
0N/A * instead create an Action wrapping the ActionListener, and register
0N/A * that Action by overriding <code>installKeyboardActions</code> and
0N/A * placing the Action in the SplitPane's ActionMap. Please refer to
0N/A * the key bindings specification for further details.
0N/A * <p>
0N/A * Creates a ActionListener for the JSplitPane UI that listens for
0N/A * specific key presses.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener createKeyboardUpLeftListener() {
0N/A return new KeyboardUpLeftHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no
0N/A * longer used. Subclassers previously using this method should
0N/A * instead create an Action wrapping the ActionListener, and register
0N/A * that Action by overriding <code>installKeyboardActions</code> and
0N/A * placing the Action in the SplitPane's ActionMap. Please refer to
0N/A * the key bindings specification for further details.
0N/A * <p>
0N/A * Creates a ActionListener for the JSplitPane UI that listens for
0N/A * specific key presses.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener createKeyboardDownRightListener() {
0N/A return new KeyboardDownRightHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no
0N/A * longer used. Subclassers previously using this method should
0N/A * instead create an Action wrapping the ActionListener, and register
0N/A * that Action by overriding <code>installKeyboardActions</code> and
0N/A * placing the Action in the SplitPane's ActionMap. Please refer to
0N/A * the key bindings specification for further details.
0N/A * <p>
0N/A * Creates a ActionListener for the JSplitPane UI that listens for
0N/A * specific key presses.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener createKeyboardHomeListener() {
0N/A return new KeyboardHomeHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no
0N/A * longer used. Subclassers previously using this method should
0N/A * instead create an Action wrapping the ActionListener, and register
0N/A * that Action by overriding <code>installKeyboardActions</code> and
0N/A * placing the Action in the SplitPane's ActionMap. Please refer to
0N/A * the key bindings specification for further details.
0N/A * <p>
0N/A * Creates a ActionListener for the JSplitPane UI that listens for
0N/A * specific key presses.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener createKeyboardEndListener() {
0N/A return new KeyboardEndHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no
0N/A * longer used. Subclassers previously using this method should
0N/A * instead create an Action wrapping the ActionListener, and register
0N/A * that Action by overriding <code>installKeyboardActions</code> and
0N/A * placing the Action in the SplitPane's ActionMap. Please refer to
0N/A * the key bindings specification for further details.
0N/A * <p>
0N/A * Creates a ActionListener for the JSplitPane UI that listens for
0N/A * specific key presses.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A */
0N/A @Deprecated
0N/A protected ActionListener createKeyboardResizeToggleListener() {
0N/A return new KeyboardResizeToggleHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the orientation for the JSplitPane.
0N/A */
0N/A public int getOrientation() {
0N/A return orientation;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Set the orientation for the JSplitPane.
0N/A */
0N/A public void setOrientation(int orientation) {
0N/A this.orientation = orientation;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines wether the JSplitPane is set to use a continuous layout.
0N/A */
0N/A public boolean isContinuousLayout() {
0N/A return continuousLayout;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Turn continuous layout on/off.
0N/A */
0N/A public void setContinuousLayout(boolean b) {
0N/A continuousLayout = b;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the last drag location of the JSplitPane.
0N/A */
0N/A public int getLastDragLocation() {
0N/A return lastDragLocation;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Set the last drag location of the JSplitPane.
0N/A */
0N/A public void setLastDragLocation(int l) {
0N/A lastDragLocation = l;
0N/A }
0N/A
0N/A /**
0N/A * @return increment via keyboard methods.
0N/A */
0N/A int getKeyboardMoveIncrement() {
1833N/A return 3;
0N/A }
0N/A
0N/A /**
0N/A * Implementation of the PropertyChangeListener
0N/A * that the JSplitPane UI uses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class PropertyHandler implements PropertyChangeListener
0N/A {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A
0N/A /**
0N/A * Messaged from the <code>JSplitPane</code> the receiver is
0N/A * contained in. May potentially reset the layout manager and cause a
0N/A * <code>validate</code> to be sent.
0N/A */
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A getHandler().propertyChange(e);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Implementation of the FocusListener that the JSplitPane UI uses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class FocusHandler extends FocusAdapter
0N/A {
0N/A // NOTE: This class exists only for backward compatability. All
0N/A // its functionality has been moved into Handler. If you need to add
0N/A // new functionality add it to the Handler, but make sure this
0N/A // class calls into the Handler.
0N/A public void focusGained(FocusEvent ev) {
0N/A getHandler().focusGained(ev);
0N/A }
0N/A
0N/A public void focusLost(FocusEvent ev) {
0N/A getHandler().focusLost(ev);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Implementation of an ActionListener that the JSplitPane UI uses for
0N/A * handling specific key presses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class KeyboardUpLeftHandler implements ActionListener
0N/A {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(Math.max(0,getDividerLocation
0N/A (splitPane) - getKeyboardMoveIncrement()));
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Implementation of an ActionListener that the JSplitPane UI uses for
0N/A * handling specific key presses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class KeyboardDownRightHandler implements ActionListener
0N/A {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(getDividerLocation(splitPane) +
0N/A getKeyboardMoveIncrement());
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Implementation of an ActionListener that the JSplitPane UI uses for
0N/A * handling specific key presses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class KeyboardHomeHandler implements ActionListener
0N/A {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(0);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Implementation of an ActionListener that the JSplitPane UI uses for
0N/A * handling specific key presses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class KeyboardEndHandler implements ActionListener
0N/A {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (dividerKeyboardResize) {
0N/A Insets insets = splitPane.getInsets();
0N/A int bottomI = (insets != null) ? insets.bottom : 0;
0N/A int rightI = (insets != null) ? insets.right : 0;
0N/A
0N/A if (orientation == JSplitPane.VERTICAL_SPLIT) {
0N/A splitPane.setDividerLocation(splitPane.getHeight() -
0N/A bottomI);
0N/A }
0N/A else {
0N/A splitPane.setDividerLocation(splitPane.getWidth() -
0N/A rightI);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Implementation of an ActionListener that the JSplitPane UI uses for
0N/A * handling specific key presses.
0N/A * <p>
0N/A * This class should be treated as a &quot;protected&quot; inner class.
0N/A * Instantiate it only within subclasses of BasicSplitPaneUI.
0N/A */
0N/A public class KeyboardResizeToggleHandler implements ActionListener
0N/A {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (!dividerKeyboardResize) {
0N/A splitPane.requestFocus();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the divider between the top Components.
0N/A */
0N/A public BasicSplitPaneDivider getDivider() {
0N/A return divider;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the default non continuous layout divider, which is an
1999N/A * instance of {@code Canvas} that fills in the background with dark gray.
0N/A */
0N/A protected Component createDefaultNonContinuousLayoutDivider() {
0N/A return new Canvas() {
0N/A public void paint(Graphics g) {
0N/A if(!isContinuousLayout() && getLastDragLocation() != -1) {
0N/A Dimension size = splitPane.getSize();
0N/A
0N/A g.setColor(dividerDraggingColor);
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A g.fillRect(0, 0, dividerSize - 1, size.height - 1);
0N/A } else {
0N/A g.fillRect(0, 0, size.width - 1, dividerSize - 1);
0N/A }
0N/A }
0N/A }
0N/A };
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the divider to use when the splitPane is configured to
0N/A * not continuously layout. This divider will only be used during a
0N/A * dragging session. It is recommended that the passed in component
0N/A * be a heavy weight.
0N/A */
0N/A protected void setNonContinuousLayoutDivider(Component newDivider) {
0N/A setNonContinuousLayoutDivider(newDivider, true);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the divider to use.
0N/A */
0N/A protected void setNonContinuousLayoutDivider(Component newDivider,
0N/A boolean rememberSizes) {
0N/A rememberPaneSizes = rememberSizes;
0N/A if(nonContinuousLayoutDivider != null && splitPane != null) {
0N/A splitPane.remove(nonContinuousLayoutDivider);
0N/A }
0N/A nonContinuousLayoutDivider = newDivider;
0N/A }
0N/A
0N/A private void addHeavyweightDivider() {
0N/A if(nonContinuousLayoutDivider != null && splitPane != null) {
0N/A
0N/A /* Needs to remove all the components and re-add them! YECK! */
0N/A // This is all done so that the nonContinuousLayoutDivider will
0N/A // be drawn on top of the other components, without this, one
0N/A // of the heavyweights will draw over the divider!
0N/A Component leftC = splitPane.getLeftComponent();
0N/A Component rightC = splitPane.getRightComponent();
0N/A int lastLocation = splitPane.
0N/A getDividerLocation();
0N/A
0N/A if(leftC != null)
0N/A splitPane.setLeftComponent(null);
0N/A if(rightC != null)
0N/A splitPane.setRightComponent(null);
0N/A splitPane.remove(divider);
0N/A splitPane.add(nonContinuousLayoutDivider, BasicSplitPaneUI.
0N/A NON_CONTINUOUS_DIVIDER,
0N/A splitPane.getComponentCount());
0N/A splitPane.setLeftComponent(leftC);
0N/A splitPane.setRightComponent(rightC);
0N/A splitPane.add(divider, JSplitPane.DIVIDER);
0N/A if(rememberPaneSizes) {
0N/A splitPane.setDividerLocation(lastLocation);
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the divider to use when the splitPane is configured to
0N/A * not continuously layout. This divider will only be used during a
0N/A * dragging session.
0N/A */
0N/A public Component getNonContinuousLayoutDivider() {
0N/A return nonContinuousLayoutDivider;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the splitpane this instance is currently contained
0N/A * in.
0N/A */
0N/A public JSplitPane getSplitPane() {
0N/A return splitPane;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates the default divider.
0N/A */
0N/A public BasicSplitPaneDivider createDefaultDivider() {
0N/A return new BasicSplitPaneDivider(this);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Messaged to reset the preferred sizes.
0N/A */
0N/A public void resetToPreferredSizes(JSplitPane jc) {
0N/A if(splitPane != null) {
0N/A layoutManager.resetToPreferredSizes();
0N/A splitPane.revalidate();
0N/A splitPane.repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the location of the divider to location.
0N/A */
0N/A public void setDividerLocation(JSplitPane jc, int location) {
0N/A if (!ignoreDividerLocationChange) {
0N/A dividerLocationIsSet = true;
0N/A splitPane.revalidate();
0N/A splitPane.repaint();
0N/A
0N/A if (keepHidden) {
0N/A Insets insets = splitPane.getInsets();
0N/A int orientation = splitPane.getOrientation();
0N/A if ((orientation == JSplitPane.VERTICAL_SPLIT &&
0N/A location != insets.top &&
0N/A location != splitPane.getHeight()-divider.getHeight()-insets.top) ||
0N/A (orientation == JSplitPane.HORIZONTAL_SPLIT &&
0N/A location != insets.left &&
0N/A location != splitPane.getWidth()-divider.getWidth()-insets.left)) {
0N/A setKeepHidden(false);
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A ignoreDividerLocationChange = false;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the location of the divider, which may differ from what
0N/A * the splitpane thinks the location of the divider is.
0N/A */
0N/A public int getDividerLocation(JSplitPane jc) {
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT)
0N/A return divider.getLocation().x;
0N/A return divider.getLocation().y;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the minimum location of the divider.
0N/A */
0N/A public int getMinimumDividerLocation(JSplitPane jc) {
0N/A int minLoc = 0;
0N/A Component leftC = splitPane.getLeftComponent();
0N/A
0N/A if ((leftC != null) && (leftC.isVisible())) {
0N/A Insets insets = splitPane.getInsets();
0N/A Dimension minSize = leftC.getMinimumSize();
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A minLoc = minSize.width;
0N/A } else {
0N/A minLoc = minSize.height;
0N/A }
0N/A if(insets != null) {
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A minLoc += insets.left;
0N/A } else {
0N/A minLoc += insets.top;
0N/A }
0N/A }
0N/A }
0N/A return minLoc;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the maximum location of the divider.
0N/A */
0N/A public int getMaximumDividerLocation(JSplitPane jc) {
0N/A Dimension splitPaneSize = splitPane.getSize();
0N/A int maxLoc = 0;
0N/A Component rightC = splitPane.getRightComponent();
0N/A
0N/A if (rightC != null) {
0N/A Insets insets = splitPane.getInsets();
0N/A Dimension minSize = new Dimension(0, 0);
0N/A if (rightC.isVisible()) {
0N/A minSize = rightC.getMinimumSize();
0N/A }
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A maxLoc = splitPaneSize.width - minSize.width;
0N/A } else {
0N/A maxLoc = splitPaneSize.height - minSize.height;
0N/A }
0N/A maxLoc -= dividerSize;
0N/A if(insets != null) {
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A maxLoc -= insets.right;
0N/A } else {
0N/A maxLoc -= insets.top;
0N/A }
0N/A }
0N/A }
0N/A return Math.max(getMinimumDividerLocation(splitPane), maxLoc);
0N/A }
0N/A
0N/A
0N/A /**
1999N/A * Called when the specified split pane has finished painting
1999N/A * its children.
0N/A */
1999N/A public void finishedPaintingChildren(JSplitPane sp, Graphics g) {
1999N/A if(sp == splitPane && getLastDragLocation() != -1 &&
0N/A !isContinuousLayout() && !draggingHW) {
0N/A Dimension size = splitPane.getSize();
0N/A
0N/A g.setColor(dividerDraggingColor);
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A g.fillRect(getLastDragLocation(), 0, dividerSize - 1,
0N/A size.height - 1);
0N/A } else {
0N/A g.fillRect(0, lastDragLocation, size.width - 1,
0N/A dividerSize - 1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
1999N/A * @inheritDoc
0N/A */
0N/A public void paint(Graphics g, JComponent jc) {
0N/A if (!painted && splitPane.getDividerLocation()<0) {
0N/A ignoreDividerLocationChange = true;
0N/A splitPane.setDividerLocation(getDividerLocation(splitPane));
0N/A }
0N/A painted = true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the preferred size for the passed in component,
0N/A * This is passed off to the current layoutmanager.
0N/A */
0N/A public Dimension getPreferredSize(JComponent jc) {
0N/A if(splitPane != null)
0N/A return layoutManager.preferredLayoutSize(splitPane);
0N/A return new Dimension(0, 0);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the minimum size for the passed in component,
0N/A * This is passed off to the current layoutmanager.
0N/A */
0N/A public Dimension getMinimumSize(JComponent jc) {
0N/A if(splitPane != null)
0N/A return layoutManager.minimumLayoutSize(splitPane);
0N/A return new Dimension(0, 0);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the maximum size for the passed in component,
0N/A * This is passed off to the current layoutmanager.
0N/A */
0N/A public Dimension getMaximumSize(JComponent jc) {
0N/A if(splitPane != null)
0N/A return layoutManager.maximumLayoutSize(splitPane);
0N/A return new Dimension(0, 0);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the insets. The insets are returned from the border insets
0N/A * of the current border.
0N/A */
0N/A public Insets getInsets(JComponent jc) {
0N/A return null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Resets the layout manager based on orientation and messages it
0N/A * with invalidateLayout to pull in appropriate Components.
0N/A */
0N/A protected void resetLayoutManager() {
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A layoutManager = new BasicHorizontalLayoutManager(0);
0N/A } else {
0N/A layoutManager = new BasicHorizontalLayoutManager(1);
0N/A }
0N/A splitPane.setLayout(layoutManager);
0N/A layoutManager.updateComponents();
0N/A splitPane.revalidate();
0N/A splitPane.repaint();
0N/A }
0N/A
0N/A /**
0N/A * Set the value to indicate if one of the splitpane sides is expanded.
0N/A */
0N/A void setKeepHidden(boolean keepHidden) {
0N/A this.keepHidden = keepHidden;
0N/A }
0N/A
0N/A /**
0N/A * The value returned indicates if one of the splitpane sides is expanded.
0N/A * @return true if one of the splitpane sides is expanded, false otherwise.
0N/A */
0N/A private boolean getKeepHidden() {
0N/A return keepHidden;
0N/A }
0N/A
0N/A /**
0N/A * Should be messaged before the dragging session starts, resets
0N/A * lastDragLocation and dividerSize.
0N/A */
0N/A protected void startDragging() {
0N/A Component leftC = splitPane.getLeftComponent();
0N/A Component rightC = splitPane.getRightComponent();
0N/A ComponentPeer cPeer;
0N/A
0N/A beginDragDividerLocation = getDividerLocation(splitPane);
0N/A draggingHW = false;
0N/A if(leftC != null && (cPeer = leftC.getPeer()) != null &&
0N/A !(cPeer instanceof LightweightPeer)) {
0N/A draggingHW = true;
0N/A } else if(rightC != null && (cPeer = rightC.getPeer()) != null
0N/A && !(cPeer instanceof LightweightPeer)) {
0N/A draggingHW = true;
0N/A }
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A setLastDragLocation(divider.getBounds().x);
0N/A dividerSize = divider.getSize().width;
0N/A if(!isContinuousLayout() && draggingHW) {
0N/A nonContinuousLayoutDivider.setBounds
0N/A (getLastDragLocation(), 0, dividerSize,
0N/A splitPane.getHeight());
0N/A addHeavyweightDivider();
0N/A }
0N/A } else {
0N/A setLastDragLocation(divider.getBounds().y);
0N/A dividerSize = divider.getSize().height;
0N/A if(!isContinuousLayout() && draggingHW) {
0N/A nonContinuousLayoutDivider.setBounds
0N/A (0, getLastDragLocation(), splitPane.getWidth(),
0N/A dividerSize);
0N/A addHeavyweightDivider();
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Messaged during a dragging session to move the divider to the
0N/A * passed in location. If continuousLayout is true the location is
0N/A * reset and the splitPane validated.
0N/A */
0N/A protected void dragDividerTo(int location) {
0N/A if(getLastDragLocation() != location) {
0N/A if(isContinuousLayout()) {
0N/A splitPane.setDividerLocation(location);
0N/A setLastDragLocation(location);
0N/A } else {
0N/A int lastLoc = getLastDragLocation();
0N/A
0N/A setLastDragLocation(location);
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A if(draggingHW) {
0N/A nonContinuousLayoutDivider.setLocation(
0N/A getLastDragLocation(), 0);
0N/A } else {
0N/A int splitHeight = splitPane.getHeight();
0N/A splitPane.repaint(lastLoc, 0, dividerSize,
0N/A splitHeight);
0N/A splitPane.repaint(location, 0, dividerSize,
0N/A splitHeight);
0N/A }
0N/A } else {
0N/A if(draggingHW) {
0N/A nonContinuousLayoutDivider.setLocation(0,
0N/A getLastDragLocation());
0N/A } else {
0N/A int splitWidth = splitPane.getWidth();
0N/A
0N/A splitPane.repaint(0, lastLoc, splitWidth,
0N/A dividerSize);
0N/A splitPane.repaint(0, location, splitWidth,
0N/A dividerSize);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Messaged to finish the dragging session. If not continuous display
0N/A * the dividers location will be reset.
0N/A */
0N/A protected void finishDraggingTo(int location) {
0N/A dragDividerTo(location);
0N/A setLastDragLocation(-1);
0N/A if(!isContinuousLayout()) {
0N/A Component leftC = splitPane.getLeftComponent();
0N/A Rectangle leftBounds = leftC.getBounds();
0N/A
0N/A if (draggingHW) {
0N/A if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
0N/A nonContinuousLayoutDivider.setLocation(-dividerSize, 0);
0N/A }
0N/A else {
0N/A nonContinuousLayoutDivider.setLocation(0, -dividerSize);
0N/A }
0N/A splitPane.remove(nonContinuousLayoutDivider);
0N/A }
0N/A splitPane.setDividerLocation(location);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3 this method is no longer used. Instead
0N/A * you should set the border on the divider.
0N/A * <p>
0N/A * Returns the width of one side of the divider border.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3, instead set the border on the
0N/A * divider.
0N/A */
0N/A @Deprecated
0N/A protected int getDividerBorderSize() {
0N/A return 1;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * LayoutManager for JSplitPanes that have an orientation of
0N/A * HORIZONTAL_SPLIT.
0N/A */
0N/A public class BasicHorizontalLayoutManager implements LayoutManager2
0N/A {
0N/A /* left, right, divider. (in this exact order) */
0N/A protected int[] sizes;
0N/A protected Component[] components;
0N/A /** Size of the splitpane the last time laid out. */
0N/A private int lastSplitPaneSize;
0N/A /** True if resetToPreferredSizes has been invoked. */
0N/A private boolean doReset;
0N/A /** Axis, 0 for horizontal, or 1 for veritcal. */
0N/A private int axis;
0N/A
0N/A
0N/A BasicHorizontalLayoutManager() {
0N/A this(0);
0N/A }
0N/A
0N/A BasicHorizontalLayoutManager(int axis) {
0N/A this.axis = axis;
0N/A components = new Component[3];
0N/A components[0] = components[1] = components[2] = null;
0N/A sizes = new int[3];
0N/A }
0N/A
0N/A //
0N/A // LayoutManager
0N/A //
0N/A
0N/A /**
0N/A * Does the actual layout.
0N/A */
0N/A public void layoutContainer(Container container) {
0N/A Dimension containerSize = container.getSize();
0N/A
0N/A // If the splitpane has a zero size then no op out of here.
0N/A // If we execute this function now, we're going to cause ourselves
0N/A // much grief.
0N/A if (containerSize.height <= 0 || containerSize.width <= 0 ) {
0N/A lastSplitPaneSize = 0;
0N/A return;
0N/A }
0N/A
0N/A int spDividerLocation = splitPane.getDividerLocation();
0N/A Insets insets = splitPane.getInsets();
0N/A int availableSize = getAvailableSize(containerSize,
0N/A insets);
0N/A int newSize = getSizeForPrimaryAxis(containerSize);
0N/A int beginLocation = getDividerLocation(splitPane);
0N/A int dOffset = getSizeForPrimaryAxis(insets, true);
0N/A Dimension dSize = (components[2] == null) ? null :
0N/A components[2].getPreferredSize();
0N/A
0N/A if ((doReset && !dividerLocationIsSet) || spDividerLocation < 0) {
0N/A resetToPreferredSizes(availableSize);
0N/A }
0N/A else if (lastSplitPaneSize <= 0 ||
0N/A availableSize == lastSplitPaneSize || !painted ||
0N/A (dSize != null &&
0N/A getSizeForPrimaryAxis(dSize) != sizes[2])) {
0N/A if (dSize != null) {
0N/A sizes[2] = getSizeForPrimaryAxis(dSize);
0N/A }
0N/A else {
0N/A sizes[2] = 0;
0N/A }
0N/A setDividerLocation(spDividerLocation - dOffset, availableSize);
0N/A dividerLocationIsSet = false;
0N/A }
0N/A else if (availableSize != lastSplitPaneSize) {
0N/A distributeSpace(availableSize - lastSplitPaneSize,
0N/A getKeepHidden());
0N/A }
0N/A doReset = false;
0N/A dividerLocationIsSet = false;
0N/A lastSplitPaneSize = availableSize;
0N/A
0N/A // Reset the bounds of each component
0N/A int nextLocation = getInitialLocation(insets);
0N/A int counter = 0;
0N/A
0N/A while (counter < 3) {
0N/A if (components[counter] != null &&
0N/A components[counter].isVisible()) {
0N/A setComponentToSize(components[counter], sizes[counter],
0N/A nextLocation, insets, containerSize);
0N/A nextLocation += sizes[counter];
0N/A }
0N/A switch (counter) {
0N/A case 0:
0N/A counter = 2;
0N/A break;
0N/A case 2:
0N/A counter = 1;
0N/A break;
0N/A case 1:
0N/A counter = 3;
0N/A break;
0N/A }
0N/A }
0N/A if (painted) {
0N/A // This is tricky, there is never a good time for us
0N/A // to push the value to the splitpane, painted appears to
0N/A // the best time to do it. What is really needed is
0N/A // notification that layout has completed.
0N/A int newLocation = getDividerLocation(splitPane);
0N/A
0N/A if (newLocation != (spDividerLocation - dOffset)) {
0N/A int lastLocation = splitPane.getLastDividerLocation();
0N/A
0N/A ignoreDividerLocationChange = true;
0N/A try {
0N/A splitPane.setDividerLocation(newLocation);
0N/A // This is not always needed, but is rather tricky
0N/A // to determine when... The case this is needed for
0N/A // is if the user sets the divider location to some
0N/A // bogus value, say 0, and the actual value is 1, the
0N/A // call to setDividerLocation(1) will preserve the
0N/A // old value of 0, when we really want the divider
0N/A // location value before the call. This is needed for
0N/A // the one touch buttons.
0N/A splitPane.setLastDividerLocation(lastLocation);
0N/A } finally {
0N/A ignoreDividerLocationChange = false;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds the component at place. Place must be one of
0N/A * JSplitPane.LEFT, RIGHT, TOP, BOTTOM, or null (for the
0N/A * divider).
0N/A */
0N/A public void addLayoutComponent(String place, Component component) {
0N/A boolean isValid = true;
0N/A
0N/A if(place != null) {
0N/A if(place.equals(JSplitPane.DIVIDER)) {
0N/A /* Divider. */
0N/A components[2] = component;
0N/A sizes[2] = getSizeForPrimaryAxis(component.
0N/A getPreferredSize());
0N/A } else if(place.equals(JSplitPane.LEFT) ||
0N/A place.equals(JSplitPane.TOP)) {
0N/A components[0] = component;
0N/A sizes[0] = 0;
0N/A } else if(place.equals(JSplitPane.RIGHT) ||
0N/A place.equals(JSplitPane.BOTTOM)) {
0N/A components[1] = component;
0N/A sizes[1] = 0;
0N/A } else if(!place.equals(
0N/A BasicSplitPaneUI.NON_CONTINUOUS_DIVIDER))
0N/A isValid = false;
0N/A } else {
0N/A isValid = false;
0N/A }
0N/A if(!isValid)
0N/A throw new IllegalArgumentException("cannot add to layout: " +
0N/A "unknown constraint: " +
0N/A place);
0N/A doReset = true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the minimum size needed to contain the children.
0N/A * The width is the sum of all the childrens min widths and
0N/A * the height is the largest of the childrens minimum heights.
0N/A */
0N/A public Dimension minimumLayoutSize(Container container) {
0N/A int minPrimary = 0;
0N/A int minSecondary = 0;
0N/A Insets insets = splitPane.getInsets();
0N/A
0N/A for (int counter=0; counter<3; counter++) {
0N/A if(components[counter] != null) {
0N/A Dimension minSize = components[counter].getMinimumSize();
0N/A int secSize = getSizeForSecondaryAxis(minSize);
0N/A
0N/A minPrimary += getSizeForPrimaryAxis(minSize);
0N/A if(secSize > minSecondary)
0N/A minSecondary = secSize;
0N/A }
0N/A }
0N/A if(insets != null) {
0N/A minPrimary += getSizeForPrimaryAxis(insets, true) +
0N/A getSizeForPrimaryAxis(insets, false);
0N/A minSecondary += getSizeForSecondaryAxis(insets, true) +
0N/A getSizeForSecondaryAxis(insets, false);
0N/A }
0N/A if (axis == 0) {
0N/A return new Dimension(minPrimary, minSecondary);
0N/A }
0N/A return new Dimension(minSecondary, minPrimary);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the preferred size needed to contain the children.
0N/A * The width is the sum of all the childrens preferred widths and
0N/A * the height is the largest of the childrens preferred heights.
0N/A */
0N/A public Dimension preferredLayoutSize(Container container) {
0N/A int prePrimary = 0;
0N/A int preSecondary = 0;
0N/A Insets insets = splitPane.getInsets();
0N/A
0N/A for(int counter = 0; counter < 3; counter++) {
0N/A if(components[counter] != null) {
0N/A Dimension preSize = components[counter].
0N/A getPreferredSize();
0N/A int secSize = getSizeForSecondaryAxis(preSize);
0N/A
0N/A prePrimary += getSizeForPrimaryAxis(preSize);
0N/A if(secSize > preSecondary)
0N/A preSecondary = secSize;
0N/A }
0N/A }
0N/A if(insets != null) {
0N/A prePrimary += getSizeForPrimaryAxis(insets, true) +
0N/A getSizeForPrimaryAxis(insets, false);
0N/A preSecondary += getSizeForSecondaryAxis(insets, true) +
0N/A getSizeForSecondaryAxis(insets, false);
0N/A }
0N/A if (axis == 0) {
0N/A return new Dimension(prePrimary, preSecondary);
0N/A }
0N/A return new Dimension(preSecondary, prePrimary);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes the specified component from our knowledge.
0N/A */
0N/A public void removeLayoutComponent(Component component) {
0N/A for(int counter = 0; counter < 3; counter++) {
0N/A if(components[counter] == component) {
0N/A components[counter] = null;
0N/A sizes[counter] = 0;
0N/A doReset = true;
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A //
0N/A // LayoutManager2
0N/A //
0N/A
0N/A
0N/A /**
0N/A * Adds the specified component to the layout, using the specified
0N/A * constraint object.
0N/A * @param comp the component to be added
0N/A * @param constraints where/how the component is added to the layout.
0N/A */
0N/A public void addLayoutComponent(Component comp, Object constraints) {
0N/A if ((constraints == null) || (constraints instanceof String)) {
0N/A addLayoutComponent((String)constraints, comp);
0N/A } else {
0N/A throw new IllegalArgumentException("cannot add to layout: " +
0N/A "constraint must be a " +
0N/A "string (or null)");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the alignment along the x axis. This specifies how
0N/A * the component would like to be aligned relative to other
0N/A * components. The value should be a number between 0 and 1
0N/A * where 0 represents alignment along the origin, 1 is aligned
0N/A * the furthest away from the origin, 0.5 is centered, etc.
0N/A */
0N/A public float getLayoutAlignmentX(Container target) {
0N/A return 0.0f;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the alignment along the y axis. This specifies how
0N/A * the component would like to be aligned relative to other
0N/A * components. The value should be a number between 0 and 1
0N/A * where 0 represents alignment along the origin, 1 is aligned
0N/A * the furthest away from the origin, 0.5 is centered, etc.
0N/A */
0N/A public float getLayoutAlignmentY(Container target) {
0N/A return 0.0f;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Does nothing. If the developer really wants to change the
0N/A * size of one of the views JSplitPane.resetToPreferredSizes should
0N/A * be messaged.
0N/A */
0N/A public void invalidateLayout(Container c) {
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the maximum layout size, which is Integer.MAX_VALUE
0N/A * in both directions.
0N/A */
0N/A public Dimension maximumLayoutSize(Container target) {
0N/A return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
0N/A }
0N/A
0N/A
0N/A //
0N/A // New methods.
0N/A //
0N/A
0N/A /**
0N/A * Marks the receiver so that the next time this instance is
0N/A * laid out it'll ask for the preferred sizes.
0N/A */
0N/A public void resetToPreferredSizes() {
0N/A doReset = true;
0N/A }
0N/A
0N/A /**
0N/A * Resets the size of the Component at the passed in location.
0N/A */
0N/A protected void resetSizeAt(int index) {
0N/A sizes[index] = 0;
0N/A doReset = true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the sizes to <code>newSizes</code>.
0N/A */
0N/A protected void setSizes(int[] newSizes) {
0N/A System.arraycopy(newSizes, 0, sizes, 0, 3);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the sizes of the components.
0N/A */
0N/A protected int[] getSizes() {
0N/A int[] retSizes = new int[3];
0N/A
0N/A System.arraycopy(sizes, 0, retSizes, 0, 3);
0N/A return retSizes;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the width of the passed in Components preferred size.
0N/A */
0N/A protected int getPreferredSizeOfComponent(Component c) {
0N/A return getSizeForPrimaryAxis(c.getPreferredSize());
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the width of the passed in Components minimum size.
0N/A */
0N/A int getMinimumSizeOfComponent(Component c) {
0N/A return getSizeForPrimaryAxis(c.getMinimumSize());
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the width of the passed in component.
0N/A */
0N/A protected int getSizeOfComponent(Component c) {
0N/A return getSizeForPrimaryAxis(c.getSize());
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the available width based on the container size and
0N/A * Insets.
0N/A */
0N/A protected int getAvailableSize(Dimension containerSize,
0N/A Insets insets) {
0N/A if(insets == null)
0N/A return getSizeForPrimaryAxis(containerSize);
0N/A return (getSizeForPrimaryAxis(containerSize) -
0N/A (getSizeForPrimaryAxis(insets, true) +
0N/A getSizeForPrimaryAxis(insets, false)));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the left inset, unless the Insets are null in which case
0N/A * 0 is returned.
0N/A */
0N/A protected int getInitialLocation(Insets insets) {
0N/A if(insets != null)
0N/A return getSizeForPrimaryAxis(insets, true);
0N/A return 0;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the width of the component c to be size, placing its
0N/A * x location at location, y to the insets.top and height
0N/A * to the containersize.height less the top and bottom insets.
0N/A */
0N/A protected void setComponentToSize(Component c, int size,
0N/A int location, Insets insets,
0N/A Dimension containerSize) {
0N/A if(insets != null) {
0N/A if (axis == 0) {
0N/A c.setBounds(location, insets.top, size,
0N/A containerSize.height -
0N/A (insets.top + insets.bottom));
0N/A }
0N/A else {
0N/A c.setBounds(insets.left, location, containerSize.width -
0N/A (insets.left + insets.right), size);
0N/A }
0N/A }
0N/A else {
0N/A if (axis == 0) {
0N/A c.setBounds(location, 0, size, containerSize.height);
0N/A }
0N/A else {
0N/A c.setBounds(0, location, containerSize.width, size);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * If the axis == 0, the width is returned, otherwise the height.
0N/A */
0N/A int getSizeForPrimaryAxis(Dimension size) {
0N/A if (axis == 0) {
0N/A return size.width;
0N/A }
0N/A return size.height;
0N/A }
0N/A
0N/A /**
0N/A * If the axis == 0, the width is returned, otherwise the height.
0N/A */
0N/A int getSizeForSecondaryAxis(Dimension size) {
0N/A if (axis == 0) {
0N/A return size.height;
0N/A }
0N/A return size.width;
0N/A }
0N/A
0N/A /**
0N/A * Returns a particular value of the inset identified by the
0N/A * axis and <code>isTop</code><p>
0N/A * axis isTop
0N/A * 0 true - left
0N/A * 0 false - right
0N/A * 1 true - top
0N/A * 1 false - bottom
0N/A */
0N/A int getSizeForPrimaryAxis(Insets insets, boolean isTop) {
0N/A if (axis == 0) {
0N/A if (isTop) {
0N/A return insets.left;
0N/A }
0N/A return insets.right;
0N/A }
0N/A if (isTop) {
0N/A return insets.top;
0N/A }
0N/A return insets.bottom;
0N/A }
0N/A
0N/A /**
0N/A * Returns a particular value of the inset identified by the
0N/A * axis and <code>isTop</code><p>
0N/A * axis isTop
0N/A * 0 true - left
0N/A * 0 false - right
0N/A * 1 true - top
0N/A * 1 false - bottom
0N/A */
0N/A int getSizeForSecondaryAxis(Insets insets, boolean isTop) {
0N/A if (axis == 0) {
0N/A if (isTop) {
0N/A return insets.top;
0N/A }
0N/A return insets.bottom;
0N/A }
0N/A if (isTop) {
0N/A return insets.left;
0N/A }
0N/A return insets.right;
0N/A }
0N/A
0N/A /**
0N/A * Determines the components. This should be called whenever
0N/A * a new instance of this is installed into an existing
0N/A * SplitPane.
0N/A */
0N/A protected void updateComponents() {
0N/A Component comp;
0N/A
0N/A comp = splitPane.getLeftComponent();
0N/A if(components[0] != comp) {
0N/A components[0] = comp;
0N/A if(comp == null) {
0N/A sizes[0] = 0;
0N/A } else {
0N/A sizes[0] = -1;
0N/A }
0N/A }
0N/A
0N/A comp = splitPane.getRightComponent();
0N/A if(components[1] != comp) {
0N/A components[1] = comp;
0N/A if(comp == null) {
0N/A sizes[1] = 0;
0N/A } else {
0N/A sizes[1] = -1;
0N/A }
0N/A }
0N/A
0N/A /* Find the divider. */
0N/A Component[] children = splitPane.getComponents();
0N/A Component oldDivider = components[2];
0N/A
0N/A components[2] = null;
0N/A for(int counter = children.length - 1; counter >= 0; counter--) {
0N/A if(children[counter] != components[0] &&
0N/A children[counter] != components[1] &&
0N/A children[counter] != nonContinuousLayoutDivider) {
0N/A if(oldDivider != children[counter]) {
0N/A components[2] = children[counter];
0N/A } else {
0N/A components[2] = oldDivider;
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A if(components[2] == null) {
0N/A sizes[2] = 0;
0N/A }
0N/A else {
0N/A sizes[2] = getSizeForPrimaryAxis(components[2].getPreferredSize());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Resets the size of the first component to <code>leftSize</code>,
0N/A * and the right component to the remainder of the space.
0N/A */
0N/A void setDividerLocation(int leftSize, int availableSize) {
0N/A boolean lValid = (components[0] != null &&
0N/A components[0].isVisible());
0N/A boolean rValid = (components[1] != null &&
0N/A components[1].isVisible());
0N/A boolean dValid = (components[2] != null &&
0N/A components[2].isVisible());
0N/A int max = availableSize;
0N/A
0N/A if (dValid) {
0N/A max -= sizes[2];
0N/A }
0N/A leftSize = Math.max(0, Math.min(leftSize, max));
0N/A if (lValid) {
0N/A if (rValid) {
0N/A sizes[0] = leftSize;
0N/A sizes[1] = max - leftSize;
0N/A }
0N/A else {
0N/A sizes[0] = max;
0N/A sizes[1] = 0;
0N/A }
0N/A }
0N/A else if (rValid) {
0N/A sizes[1] = max;
0N/A sizes[0] = 0;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of the minimum sizes of the components.
0N/A */
0N/A int[] getPreferredSizes() {
0N/A int[] retValue = new int[3];
0N/A
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A if (components[counter] != null &&
0N/A components[counter].isVisible()) {
0N/A retValue[counter] = getPreferredSizeOfComponent
0N/A (components[counter]);
0N/A }
0N/A else {
0N/A retValue[counter] = -1;
0N/A }
0N/A }
0N/A return retValue;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of the minimum sizes of the components.
0N/A */
0N/A int[] getMinimumSizes() {
0N/A int[] retValue = new int[3];
0N/A
0N/A for (int counter = 0; counter < 2; counter++) {
0N/A if (components[counter] != null &&
0N/A components[counter].isVisible()) {
0N/A retValue[counter] = getMinimumSizeOfComponent
0N/A (components[counter]);
0N/A }
0N/A else {
0N/A retValue[counter] = -1;
0N/A }
0N/A }
0N/A retValue[2] = (components[2] != null) ?
0N/A getMinimumSizeOfComponent(components[2]) : -1;
0N/A return retValue;
0N/A }
0N/A
0N/A /**
0N/A * Resets the components to their preferred sizes.
0N/A */
0N/A void resetToPreferredSizes(int availableSize) {
0N/A // Set the sizes to the preferred sizes (if fits), otherwise
0N/A // set to min sizes and distribute any extra space.
0N/A int[] testSizes = getPreferredSizes();
0N/A int totalSize = 0;
0N/A
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A if (testSizes[counter] != -1) {
0N/A totalSize += testSizes[counter];
0N/A }
0N/A }
0N/A if (totalSize > availableSize) {
0N/A testSizes = getMinimumSizes();
0N/A
0N/A totalSize = 0;
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A if (testSizes[counter] != -1) {
0N/A totalSize += testSizes[counter];
0N/A }
0N/A }
0N/A }
0N/A setSizes(testSizes);
0N/A distributeSpace(availableSize - totalSize, false);
0N/A }
0N/A
0N/A /**
0N/A * Distributes <code>space</code> between the two components
0N/A * (divider won't get any extra space) based on the weighting. This
0N/A * attempts to honor the min size of the components.
0N/A *
0N/A * @param keepHidden if true and one of the components is 0x0
0N/A * it gets none of the extra space
0N/A */
0N/A void distributeSpace(int space, boolean keepHidden) {
0N/A boolean lValid = (components[0] != null &&
0N/A components[0].isVisible());
0N/A boolean rValid = (components[1] != null &&
0N/A components[1].isVisible());
0N/A
0N/A if (keepHidden) {
0N/A if (lValid && getSizeForPrimaryAxis(
0N/A components[0].getSize()) == 0) {
0N/A lValid = false;
0N/A if (rValid && getSizeForPrimaryAxis(
0N/A components[1].getSize()) == 0) {
0N/A // Both aren't valid, force them both to be valid
0N/A lValid = true;
0N/A }
0N/A }
0N/A else if (rValid && getSizeForPrimaryAxis(
0N/A components[1].getSize()) == 0) {
0N/A rValid = false;
0N/A }
0N/A }
0N/A if (lValid && rValid) {
0N/A double weight = splitPane.getResizeWeight();
0N/A int lExtra = (int)(weight * (double)space);
0N/A int rExtra = (space - lExtra);
0N/A
0N/A sizes[0] += lExtra;
0N/A sizes[1] += rExtra;
0N/A
0N/A int lMin = getMinimumSizeOfComponent(components[0]);
0N/A int rMin = getMinimumSizeOfComponent(components[1]);
0N/A boolean lMinValid = (sizes[0] >= lMin);
0N/A boolean rMinValid = (sizes[1] >= rMin);
0N/A
0N/A if (!lMinValid && !rMinValid) {
0N/A if (sizes[0] < 0) {
0N/A sizes[1] += sizes[0];
0N/A sizes[0] = 0;
0N/A }
0N/A else if (sizes[1] < 0) {
0N/A sizes[0] += sizes[1];
0N/A sizes[1] = 0;
0N/A }
0N/A }
0N/A else if (!lMinValid) {
0N/A if (sizes[1] - (lMin - sizes[0]) < rMin) {
0N/A // both below min, just make sure > 0
0N/A if (sizes[0] < 0) {
0N/A sizes[1] += sizes[0];
0N/A sizes[0] = 0;
0N/A }
0N/A }
0N/A else {
0N/A sizes[1] -= (lMin - sizes[0]);
0N/A sizes[0] = lMin;
0N/A }
0N/A }
0N/A else if (!rMinValid) {
0N/A if (sizes[0] - (rMin - sizes[1]) < lMin) {
0N/A // both below min, just make sure > 0
0N/A if (sizes[1] < 0) {
0N/A sizes[0] += sizes[1];
0N/A sizes[1] = 0;
0N/A }
0N/A }
0N/A else {
0N/A sizes[0] -= (rMin - sizes[1]);
0N/A sizes[1] = rMin;
0N/A }
0N/A }
0N/A if (sizes[0] < 0) {
0N/A sizes[0] = 0;
0N/A }
0N/A if (sizes[1] < 0) {
0N/A sizes[1] = 0;
0N/A }
0N/A }
0N/A else if (lValid) {
0N/A sizes[0] = Math.max(0, sizes[0] + space);
0N/A }
0N/A else if (rValid) {
0N/A sizes[1] = Math.max(0, sizes[1] + space);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * LayoutManager used for JSplitPanes with an orientation of
0N/A * VERTICAL_SPLIT.
0N/A * <p>
0N/A */
0N/A public class BasicVerticalLayoutManager extends
0N/A BasicHorizontalLayoutManager
0N/A {
0N/A public BasicVerticalLayoutManager() {
0N/A super(1);
0N/A }
0N/A }
0N/A
0N/A
0N/A private class Handler implements FocusListener, PropertyChangeListener {
0N/A //
0N/A // PropertyChangeListener
0N/A //
0N/A /**
0N/A * Messaged from the <code>JSplitPane</code> the receiver is
0N/A * contained in. May potentially reset the layout manager and cause a
0N/A * <code>validate</code> to be sent.
0N/A */
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A if(e.getSource() == splitPane) {
0N/A String changeName = e.getPropertyName();
0N/A
0N/A if(changeName == JSplitPane.ORIENTATION_PROPERTY) {
0N/A orientation = splitPane.getOrientation();
0N/A resetLayoutManager();
0N/A } else if(changeName == JSplitPane.CONTINUOUS_LAYOUT_PROPERTY){
0N/A setContinuousLayout(splitPane.isContinuousLayout());
0N/A if(!isContinuousLayout()) {
0N/A if(nonContinuousLayoutDivider == null) {
0N/A setNonContinuousLayoutDivider(
0N/A createDefaultNonContinuousLayoutDivider(),
0N/A true);
0N/A } else if(nonContinuousLayoutDivider.getParent() ==
0N/A null) {
0N/A setNonContinuousLayoutDivider(
0N/A nonContinuousLayoutDivider,
0N/A true);
0N/A }
0N/A }
0N/A } else if(changeName == JSplitPane.DIVIDER_SIZE_PROPERTY){
0N/A divider.setDividerSize(splitPane.getDividerSize());
0N/A dividerSize = divider.getDividerSize();
0N/A splitPane.revalidate();
0N/A splitPane.repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A //
0N/A // FocusListener
0N/A //
0N/A public void focusGained(FocusEvent ev) {
0N/A dividerKeyboardResize = true;
0N/A splitPane.repaint();
0N/A }
0N/A
0N/A public void focusLost(FocusEvent ev) {
0N/A dividerKeyboardResize = false;
0N/A splitPane.repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A private static class Actions extends UIAction {
0N/A private static final String NEGATIVE_INCREMENT = "negativeIncrement";
0N/A private static final String POSITIVE_INCREMENT = "positiveIncrement";
0N/A private static final String SELECT_MIN = "selectMin";
0N/A private static final String SELECT_MAX = "selectMax";
0N/A private static final String START_RESIZE = "startResize";
0N/A private static final String TOGGLE_FOCUS = "toggleFocus";
0N/A private static final String FOCUS_OUT_FORWARD = "focusOutForward";
0N/A private static final String FOCUS_OUT_BACKWARD = "focusOutBackward";
0N/A
0N/A Actions(String key) {
0N/A super(key);
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent ev) {
0N/A JSplitPane splitPane = (JSplitPane)ev.getSource();
0N/A BasicSplitPaneUI ui = (BasicSplitPaneUI)BasicLookAndFeel.
0N/A getUIOfType(splitPane.getUI(), BasicSplitPaneUI.class);
0N/A
0N/A if (ui == null) {
0N/A return;
0N/A }
0N/A String key = getName();
0N/A if (key == NEGATIVE_INCREMENT) {
0N/A if (ui.dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(Math.max(
0N/A 0, ui.getDividerLocation
0N/A (splitPane) - ui.getKeyboardMoveIncrement()));
0N/A }
0N/A }
0N/A else if (key == POSITIVE_INCREMENT) {
0N/A if (ui.dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(
0N/A ui.getDividerLocation(splitPane) +
0N/A ui.getKeyboardMoveIncrement());
0N/A }
0N/A }
0N/A else if (key == SELECT_MIN) {
0N/A if (ui.dividerKeyboardResize) {
0N/A splitPane.setDividerLocation(0);
0N/A }
0N/A }
0N/A else if (key == SELECT_MAX) {
0N/A if (ui.dividerKeyboardResize) {
0N/A Insets insets = splitPane.getInsets();
0N/A int bottomI = (insets != null) ? insets.bottom : 0;
0N/A int rightI = (insets != null) ? insets.right : 0;
0N/A
0N/A if (ui.orientation == JSplitPane.VERTICAL_SPLIT) {
0N/A splitPane.setDividerLocation(splitPane.getHeight() -
0N/A bottomI);
0N/A }
0N/A else {
0N/A splitPane.setDividerLocation(splitPane.getWidth() -
0N/A rightI);
0N/A }
0N/A }
0N/A }
0N/A else if (key == START_RESIZE) {
0N/A if (!ui.dividerKeyboardResize) {
0N/A splitPane.requestFocus();
0N/A } else {
0N/A JSplitPane parentSplitPane =
0N/A (JSplitPane)SwingUtilities.getAncestorOfClass(
0N/A JSplitPane.class, splitPane);
0N/A if (parentSplitPane!=null) {
0N/A parentSplitPane.requestFocus();
0N/A }
0N/A }
0N/A }
0N/A else if (key == TOGGLE_FOCUS) {
0N/A toggleFocus(splitPane);
0N/A }
0N/A else if (key == FOCUS_OUT_FORWARD) {
0N/A moveFocus(splitPane, 1);
0N/A }
0N/A else if (key == FOCUS_OUT_BACKWARD) {
0N/A moveFocus(splitPane, -1);
0N/A }
0N/A }
0N/A
0N/A private void moveFocus(JSplitPane splitPane, int direction) {
0N/A Container rootAncestor = splitPane.getFocusCycleRootAncestor();
0N/A FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
0N/A Component focusOn = (direction > 0) ?
0N/A policy.getComponentAfter(rootAncestor, splitPane) :
0N/A policy.getComponentBefore(rootAncestor, splitPane);
614N/A HashSet<Component> focusFrom = new HashSet<Component>();
0N/A if (splitPane.isAncestorOf(focusOn)) {
0N/A do {
0N/A focusFrom.add(focusOn);
0N/A rootAncestor = focusOn.getFocusCycleRootAncestor();
0N/A policy = rootAncestor.getFocusTraversalPolicy();
0N/A focusOn = (direction > 0) ?
0N/A policy.getComponentAfter(rootAncestor, focusOn) :
0N/A policy.getComponentBefore(rootAncestor, focusOn);
0N/A } while (splitPane.isAncestorOf(focusOn) &&
0N/A !focusFrom.contains(focusOn));
0N/A }
0N/A if ( focusOn!=null && !splitPane.isAncestorOf(focusOn) ) {
0N/A focusOn.requestFocus();
0N/A }
0N/A }
0N/A
0N/A private void toggleFocus(JSplitPane splitPane) {
0N/A Component left = splitPane.getLeftComponent();
0N/A Component right = splitPane.getRightComponent();
0N/A
0N/A KeyboardFocusManager manager =
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager();
0N/A Component focus = manager.getFocusOwner();
0N/A Component focusOn = getNextSide(splitPane, focus);
0N/A if (focusOn != null) {
0N/A // don't change the focus if the new focused component belongs
0N/A // to the same splitpane and the same side
0N/A if ( focus!=null &&
0N/A ( (SwingUtilities.isDescendingFrom(focus, left) &&
0N/A SwingUtilities.isDescendingFrom(focusOn, left)) ||
0N/A (SwingUtilities.isDescendingFrom(focus, right) &&
0N/A SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
0N/A return;
0N/A }
0N/A SwingUtilities2.compositeRequestFocus(focusOn);
0N/A }
0N/A }
0N/A
0N/A private Component getNextSide(JSplitPane splitPane, Component focus) {
0N/A Component left = splitPane.getLeftComponent();
0N/A Component right = splitPane.getRightComponent();
614N/A Component next;
0N/A if (focus!=null && SwingUtilities.isDescendingFrom(focus, left) &&
0N/A right!=null) {
0N/A next = getFirstAvailableComponent(right);
0N/A if (next != null) {
0N/A return next;
0N/A }
0N/A }
0N/A JSplitPane parentSplitPane = (JSplitPane)SwingUtilities.getAncestorOfClass(JSplitPane.class, splitPane);
0N/A if (parentSplitPane!=null) {
0N/A // focus next side of the parent split pane
0N/A next = getNextSide(parentSplitPane, focus);
0N/A } else {
0N/A next = getFirstAvailableComponent(left);
0N/A if (next == null) {
0N/A next = getFirstAvailableComponent(right);
0N/A }
0N/A }
0N/A return next;
0N/A }
0N/A
0N/A private Component getFirstAvailableComponent(Component c) {
0N/A if (c!=null && c instanceof JSplitPane) {
0N/A JSplitPane sp = (JSplitPane)c;
0N/A Component left = getFirstAvailableComponent(sp.getLeftComponent());
0N/A if (left != null) {
0N/A c = left;
0N/A } else {
0N/A c = getFirstAvailableComponent(sp.getRightComponent());
0N/A }
0N/A }
0N/A return c;
0N/A }
0N/A }
0N/A}