synthsplitpaneui.java
来自「java jdk 1.4的源码」· Java 代码 · 共 2,043 行 · 第 1/5 页
JAVA
2,043 行
/* * @(#)SynthSplitPaneUI.java 1.12 03/09/04 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;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.12, 09/04/03 (based on BasicSplitPaneUI v 1.72) * @author Scott Violet * @author Steve Wilson * @author Ralph Kar */class SynthSplitPaneUI extends SplitPaneUI implements SynthUI { /** * The divider used for non-continuous layout is added to the split pane * with this object. */ private static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider"; /** * How far (relativ) 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; /** * Instance of the divider for this JSplitPane. */ protected Divider divider; /** * Instance of the PropertyChangeListener for this JSplitPane. */ protected PropertyChangeListener propertyChangeListener; /** * Instance of the FocusListener for this JSplitPane. */ protected FocusListener focusListener; /** * 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; // 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 boolean rememberPaneSizes; /** 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; /** * Style for the JSplitPane. */ private SynthStyle style; /** * Style for the divider. */ private SynthStyle dividerStyle; /** * Size of the one touch buttons. */ private int oneTouchSize; /** * Amount to offset one touch buttons. */ private int oneTouchOffset; /** * Creates a new SynthSplitPaneUI instance */ public static ComponentUI createUI(JComponent x) { return new SynthSplitPaneUI(); } public static void loadActionMap(ActionMap map) { // NOTE: this needs to remain static. If you have a need to // have Actions that reference the UI in the ActionMap, // then you'll also need to change the registeration of the // ActionMap. map.put("negativeIncrement", new KeyboardUpLeftAction()); map.put("positiveIncrement", new KeyboardDownRightAction()); map.put("selectMin", new KeyboardHomeAction()); map.put("selectMax", new KeyboardEndAction()); map.put("startResize", new KeyboardResizeToggleAction()); map.put("toggleFocus", new ToggleSideFocusAction()); map.put("focusOutForward", new MoveFocusOutAction(1)); map.put("focusOutBackward", new MoveFocusOutAction(-1)); } /** * Installs the UI. */ public void installUI(JComponent c) { splitPane = (JSplitPane) c; dividerLocationIsSet = false; dividerKeyboardResize = false; installComponents(); installDefaults(); installListeners(); installKeyboardActions(); setLastDragLocation(-1); } protected void installComponents() { divider = new Divider(splitPane); splitPane.add(divider, JSplitPane.DIVIDER); } /** * Installs the UI defaults. */ protected void installDefaults() { setOrientation(splitPane.getOrientation()); setContinuousLayout(splitPane.isContinuousLayout()); fetchStyle(splitPane); 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); } private void fetchStyle(JSplitPane splitPane) { SynthContext context = getContext(splitPane, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { splitPane.setDividerSize(((Number)style.get( context,"SplitPaneDivider.size")).intValue()); divider.setDividerSize(splitPane.getDividerSize()); } context.dispose(); context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); dividerStyle = SynthLookAndFeel.updateStyle(context, this); divider.setOpaque(dividerStyle.isOpaque(context)); oneTouchSize = dividerStyle.getInt(context, "SplitPaneDivider.oneTouchButtonSize", 6); oneTouchOffset = dividerStyle.getInt(context, "SplitPaneDivider.oneTouchOffset", 6); context.dispose(); } /** * 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, SynthSplitPaneUI.class, "SplitPane.actionMap"); } InputMap getInputMap(int condition) { if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { SynthContext context = getContext(splitPane, ENABLED); InputMap map = (InputMap)context.getStyle().get(context, "SplitPane.ancestorInputMap"); context.dispose(); return map; } return null; } /** * Uninstalls the UI. */ public void uninstallUI(JComponent c) { uninstallKeyboardActions(); uninstallListeners(); uninstallDefaults(); uninstallComponents(); dividerLocationIsSet = false; dividerKeyboardResize = false; splitPane = null; } private void uninstallComponents() { if(nonContinuousLayoutDivider != null) { splitPane.remove(nonContinuousLayoutDivider); } splitPane.remove(divider); divider = null; } /** * Uninstalls the UI defaults. */ protected void uninstallDefaults() { if (splitPane.getLayout() instanceof UIResource) { splitPane.setLayout(null); } SynthContext context = getContext(splitPane, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); dividerStyle.uninstallDefaults(context); context.dispose(); dividerStyle = null; nonContinuousLayoutDivider = null; setNonContinuousLayoutDivider(null); // sets the focus forward and backward traversal keys to null // to restore the defaults splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); } /** * Uninstalls the event listeners for the UI. */ protected void uninstallListeners() { if (propertyChangeListener != null) { splitPane.removePropertyChangeListener(propertyChangeListener); propertyChangeListener = null; } if (focusListener != null) { splitPane.removeFocusListener(focusListener); focusListener = null; } } /** * Uninstalls the keyboard actions for the UI. */ protected void uninstallKeyboardActions() { SwingUtilities.replaceUIActionMap(splitPane, null); SwingUtilities.replaceUIInputMap(splitPane, JComponent. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { return SynthContext.getContext(SynthContext.class, c, region, style, state); } private int getComponentState(JComponent c, Region subregion) { int state = SynthLookAndFeel.getComponentState(c); if (divider.isMouseOver()) { state |= MOUSE_OVER; } return state; } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?