?? basicsplitpaneui.java
字號(hào):
/* * @(#)BasicSplitPaneUI.java 1.80 04/05/18 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;import sun.swing.DefaultLookup;import sun.swing.UIAction;import javax.swing.*;import javax.swing.border.Border;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.awt.peer.ComponentPeer;import java.awt.peer.LightweightPeer;import java.beans.*;import java.util.*;import javax.swing.plaf.ActionMapUIResource;import javax.swing.plaf.SplitPaneUI;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.UIResource;/** * A Basic L&F implementation of the SplitPaneUI. * * @version 1.80 05/18/04 * @author Scott Violet * @author Steve Wilson * @author Ralph Kar */public class BasicSplitPaneUI extends SplitPaneUI{ /** * The divider used for non-continuous layout is added to the split pane * with this object. */ protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider"; /** * How far (relative) the divider does move when it is moved around by * the cursor keys on the keyboard. */ protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3; /** * JSplitPane instance this instance is providing * the look and feel for. */ protected JSplitPane splitPane; /** * LayoutManager that is created and placed into the split pane. */ protected BasicHorizontalLayoutManager layoutManager; /** * Instance of the divider for this JSplitPane. */ protected BasicSplitPaneDivider divider; /** * Instance of the PropertyChangeListener for this JSplitPane. */ protected PropertyChangeListener propertyChangeListener; /** * Instance of the FocusListener for this JSplitPane. */ protected FocusListener focusListener; private Handler handler; /** * Keys to use for forward focus traversal when the JComponent is * managing focus. */ private static Set managingFocusForwardTraversalKeys; /** * Keys to use for backward focus traversal when the JComponent is * managing focus. */ private static Set managingFocusBackwardTraversalKeys; /** * The size of the divider while the dragging session is valid. */ protected int dividerSize; /** * Instance for the shadow of the divider when non continuous layout * is being used. */ protected Component nonContinuousLayoutDivider; /** * Set to true in startDragging if any of the children * (not including the nonContinuousLayoutDivider) are heavy weights. */ protected boolean draggingHW; /** * Location of the divider when the dragging session began. */ protected int beginDragDividerLocation; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke upKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke downKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke leftKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke rightKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke homeKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke endKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected KeyStroke dividerResizeToggleKey; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected ActionListener keyboardUpLeftListener; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected ActionListener keyboardDownRightListener; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected ActionListener keyboardHomeListener; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected ActionListener keyboardEndListener; /** * As of Java 2 platform v1.3 this previously undocumented field is no * longer used. * Key bindings are now defined by the LookAndFeel, please refer to * the key bindings specification for further details. * * @deprecated As of Java 2 platform v1.3. */ @Deprecated protected ActionListener keyboardResizeToggleListener; // Private data of the instance private int orientation; private int lastDragLocation; private boolean continuousLayout; private boolean dividerKeyboardResize; private boolean dividerLocationIsSet; // needed for tracking // the first occurrence of // setDividerLocation() private Color dividerDraggingColor; private boolean rememberPaneSizes; // Indicates wether the one of splitpane sides is expanded private boolean keepHidden = false; /** Indicates that we have painted once. */ // This is used by the LayoutManager to determine when it should use // the divider location provided by the JSplitPane. This is used as there // is no way to determine when the layout process has completed. boolean painted; /** If true, setDividerLocation does nothing. */ boolean ignoreDividerLocationChange; /** * Creates a new BasicSplitPaneUI instance */ public static ComponentUI createUI(JComponent x) { return new BasicSplitPaneUI(); } static void loadActionMap(LazyActionMap map) { map.put(new Actions(Actions.NEGATIVE_INCREMENT)); map.put(new Actions(Actions.POSITIVE_INCREMENT)); map.put(new Actions(Actions.SELECT_MIN)); map.put(new Actions(Actions.SELECT_MAX)); map.put(new Actions(Actions.START_RESIZE)); map.put(new Actions(Actions.TOGGLE_FOCUS)); map.put(new Actions(Actions.FOCUS_OUT_FORWARD)); map.put(new Actions(Actions.FOCUS_OUT_BACKWARD)); } /** * Installs the UI. */ public void installUI(JComponent c) { splitPane = (JSplitPane) c; dividerLocationIsSet = false; dividerKeyboardResize = false; keepHidden = false; installDefaults(); installListeners(); installKeyboardActions(); setLastDragLocation(-1); } /** * Installs the UI defaults. */ protected void installDefaults(){ LookAndFeel.installBorder(splitPane, "SplitPane.border"); LookAndFeel.installColors(splitPane, "SplitPane.background", "SplitPane.foreground"); LookAndFeel.installProperty(splitPane, "opaque", Boolean.TRUE); if (divider == null) divider = createDefaultDivider(); divider.setBasicSplitPaneUI(this); Border b = divider.getBorder(); if (b == null || !(b instanceof UIResource)) { divider.setBorder(UIManager.getBorder("SplitPaneDivider.border")); } dividerDraggingColor = UIManager.getColor("SplitPaneDivider.draggingColor"); setOrientation(splitPane.getOrientation()); // This plus 2 here is to provide backwards consistancy. Previously, // the old size did not include the 2 pixel border around the divider, // it now does. LookAndFeel.installProperty(splitPane, "dividerSize", UIManager.get("SplitPane.dividerSize")); divider.setDividerSize(splitPane.getDividerSize()); dividerSize = divider.getDividerSize(); splitPane.add(divider, JSplitPane.DIVIDER); setContinuousLayout(splitPane.isContinuousLayout()); resetLayoutManager(); /* Install the nonContinuousLayoutDivider here to avoid having to add/remove everything later. */ if(nonContinuousLayoutDivider == null) { setNonContinuousLayoutDivider( createDefaultNonContinuousLayoutDivider(), true); } else { setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true); } // focus forward traversal key if (managingFocusForwardTraversalKeys==null) { managingFocusForwardTraversalKeys = new TreeSet(); managingFocusForwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); } splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, managingFocusForwardTraversalKeys); // focus backward traversal key if (managingFocusBackwardTraversalKeys==null) { managingFocusBackwardTraversalKeys = new TreeSet(); managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); } splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, managingFocusBackwardTraversalKeys); } /** * Installs the event listeners for the UI. */ protected void installListeners() { if ((propertyChangeListener = createPropertyChangeListener()) != null) { splitPane.addPropertyChangeListener(propertyChangeListener); } if ((focusListener = createFocusListener()) != null) { splitPane.addFocusListener(focusListener); } } /** * Installs the keyboard actions for the UI. */ protected void installKeyboardActions() { InputMap km = getInputMap(JComponent. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(splitPane, JComponent. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km); LazyActionMap.installLazyActionMap(splitPane, BasicSplitPaneUI.class, "SplitPane.actionMap"); } InputMap getInputMap(int condition) { if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { return (InputMap)DefaultLookup.get(splitPane, this, "SplitPane.ancestorInputMap"); } return null; } /** * Uninstalls the UI. */ public void uninstallUI(JComponent c) { uninstallKeyboardActions(); uninstallListeners(); uninstallDefaults(); dividerLocationIsSet = false; dividerKeyboardResize = false;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -