synthtabbedpaneui.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,888 行 · 第 1/5 页

JAVA
1,888
字号
/* * @(#)SynthTabbedPaneUI.java	1.25 03/05/08 * * 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.event.*;import javax.swing.plaf.*;import javax.swing.text.View;import java.awt.*;import java.awt.event.*;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.util.Vector;import java.util.Hashtable;// PENDING: nuke thisimport javax.swing.plaf.basic.BasicHTML;/** * A Basic L&F implementation of TabbedPaneUI. * * @version 1.25, 05/08/03 (based on BasicTabbedPaneUI v 1.123) * @author Amy Fowler * @author Philip Milne * @author Steve Wilson * @author Tom Santos * @author Dave Moore *//** * Looks up 'selectedTabPadInsets' from the Style, which will be additional * insets for the selected tab. */class SynthTabbedPaneUI extends TabbedPaneUI implements SynthUI, SwingConstants  {    private static Action scrollTabsForwardAction =                                new ScrollTabsForwardAction();    private static Action scrollTabsBackwardAction =                                 new ScrollTabsBackwardAction();// Instance variables initialized at installation    // PENDING: These should be fetched as necessary, eg not maintained as    // fields but passed around.    private SynthContext tabAreaContext;    private TabContext tabContext;    private SynthContext tabContentContext;    private SynthStyle style;    private SynthStyle tabStyle;    private SynthStyle tabAreaStyle;    private SynthStyle tabContentStyle;    private int tabRunOverlay;    protected JTabbedPane tabPane;// Transient variables (recalculated each time TabbedPane is layed out)    protected int tabRuns[] = new int[10];    protected int runCount = 0;    protected int selectedRun = -1;    protected Rectangle rects[] = new Rectangle[0];     protected int maxTabHeight;    protected int maxTabWidth;// Listeners    protected ChangeListener tabChangeListener;    protected PropertyChangeListener propertyChangeListener;    protected MouseInputListener mouseInputListener;    protected FocusListener focusListener;    // PENDING(api): See comment for ContainerHandler    private   ContainerListener containerListener;// Private instance data    private Insets currentPadInsets = new Insets(0,0,0,0);    private Insets currentTabAreaInsets = new Insets(0,0,0,0);    private Component visibleComponent;    // PENDING(api): See comment for ContainerHandler    private Vector htmlViews;    private Hashtable mnemonicToIndexMap;    /**     * InputMap used for mnemonics. Only non-null if the JTabbedPane has     * mnemonics associated with it. Lazily created in initMnemonics.     */    private InputMap mnemonicInputMap;    // For use when tabLayoutPolicy = SCROLL_TAB_LAYOUT    private ScrollableTabSupport tabScroller;    /**     * A rectangle used for general layout calculations in order     * to avoid constructing many new Rectangles on the fly.     */    protected transient Rectangle calcRect = new Rectangle(0,0,0,0);    /**     * Number of tabs. When the count differs, the mnemonics are updated.     */    // PENDING: This wouldn't be necessary if JTabbedPane had a better    // way of notifying listeners when the count changed.    private int tabCount;    /**     * Index of the tab the mouse is over.     */    private int mouseIndex;    /**     * Index of the tab that has focus.     */    private boolean selectionFollowsFocus = true;    private int focusIndex = -1;    /**     * Bounds of the tab under the mouse.     */    private Rectangle mouseBounds;// UI creation    public static ComponentUI createUI(JComponent c) {        return new SynthTabbedPaneUI();    }    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("navigateNext", new NextAction());	map.put("navigatePrevious", new PreviousAction());	map.put("navigateRight", new RightAction());	map.put("navigateLeft", new LeftAction());	map.put("navigateUp", new UpAction());	map.put("navigateDown", new DownAction());	map.put("navigatePageUp", new PageUpAction());	map.put("navigatePageDown", new PageDownAction());	map.put("requestFocus", new RequestFocusAction());	map.put("requestFocusForVisibleComponent",		new RequestFocusForVisibleAction());        map.put("setSelectedIndex", new SetSelectedIndexAction());        map.put("selectTabWithFocus", new SelectFocusIndexAction());	map.put("scrollTabsForwardAction", scrollTabsForwardAction);        map.put("scrollTabsBackwardAction", scrollTabsBackwardAction);    }// UI Installation/De-installation        public void installUI(JComponent c) {        this.tabPane = (JTabbedPane)c;        c.setLayout(createLayoutManager());	installComponents();        installDefaults();         installListeners();        installKeyboardActions();    }    public void uninstallUI(JComponent c) {        uninstallKeyboardActions();        uninstallListeners();        uninstallDefaults();	uninstallComponents();        c.setLayout(null);         this.tabPane = null;    }    /**     * Invoked by <code>installUI</code> to create     * a layout manager object to manage     * the <code>JTabbedPane</code>.     *     * @return a layout manager object     *     * @see TabbedPaneLayout     * @see javax.swing.JTabbedPane#getTabLayoutPolicy     */    protected LayoutManager createLayoutManager() {	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {	    return new TabbedPaneScrollLayout();	} else { /* WRAP_TAB_LAYOUT */            return new TabbedPaneLayout();	}    }    /* In an attempt to preserve backward compatibility for programs     * which have extended BasicTabbedPaneUI to do their own layout, the     * UI uses the installed layoutManager (and not tabLayoutPolicy) to     * determine if scrollTabLayout is enabled.     */    private boolean scrollableTabLayoutEnabled() {	return (tabPane.getLayout() instanceof TabbedPaneScrollLayout);    }    /**     * Creates and installs any required subcomponents for the JTabbedPane.     * Invoked by installUI.     *     * @since 1.4     */    protected void installComponents() {	if (scrollableTabLayoutEnabled()) {	    if (tabScroller == null) {		tabScroller = new ScrollableTabSupport(tabPane.getTabPlacement());	        tabPane.add(tabScroller.viewport);	        tabPane.add(tabScroller.scrollForwardButton);	        tabPane.add(tabScroller.scrollBackwardButton);	    }	}    }    /**     * Removes any installed subcomponents from the JTabbedPane.     * Invoked by uninstallUI.     *     * @since 1.4     */    protected void uninstallComponents() {	if (scrollableTabLayoutEnabled()) {	    tabPane.remove(tabScroller.viewport);	    tabPane.remove(tabScroller.scrollForwardButton);	    tabPane.remove(tabScroller.scrollBackwardButton);	    tabScroller = null;	}    }    protected void installDefaults() {        fetchStyle(tabPane);    }    private void fetchStyle(JTabbedPane c) {        SynthContext context = getContext(c, ENABLED);        SynthStyle oldStyle = style;        style = SynthLookAndFeel.updateStyle(context, this);        // Add properties other than JComponent colors, Borders and        // opacity settings here:        if (style != oldStyle) {            tabRunOverlay = 0;            Integer value = (Integer)context.getStyle().get(                                 context, "tabRunOverlay");            if (value != null) {                tabRunOverlay = value.intValue();            }            selectionFollowsFocus = context.getStyle().getBoolean(context,                                             "TabbedPane.selectionFollowsFocus",                                            true);        }        context.dispose();        if (tabContext != null) {            tabContext.dispose();        }        tabContext = (TabContext)getContext(c, Region.TABBED_PANE_TAB,                                            ENABLED);        this.tabStyle = SynthLookAndFeel.updateStyle(tabContext, this);        if (tabAreaContext != null) {            tabAreaContext.dispose();        }        tabAreaContext = getContext(c, Region.TABBED_PANE_TAB_AREA, ENABLED);        this.tabAreaStyle = SynthLookAndFeel.updateStyle(tabAreaContext, this);        if (tabContentContext != null) {            tabContentContext.dispose();        }        tabContentContext = getContext(c, Region.TABBED_PANE_CONTENT, ENABLED);        this.tabContentStyle = SynthLookAndFeel.updateStyle(tabContentContext,                                                            this);    }    protected void uninstallDefaults() {        SynthContext context = getContext(tabPane, ENABLED);        style.uninstallDefaults(context);        context.dispose();        style = null;        context = getContext(tabPane, Region.TABBED_PANE_TAB, ENABLED);        tabStyle.uninstallDefaults(context);        context.dispose();        tabStyle = null;        context = getContext(tabPane,Region.TABBED_PANE_TAB_AREA, ENABLED);        tabAreaStyle.uninstallDefaults(context);        context.dispose();        tabAreaStyle = null;        context = getContext(tabPane, Region.TABBED_PANE_CONTENT, ENABLED);        tabContentStyle.uninstallDefaults(context);        context.dispose();        tabContentStyle = null;    }    protected void installListeners() {        if ((propertyChangeListener = createPropertyChangeListener()) != null) {            tabPane.addPropertyChangeListener(propertyChangeListener);        }        if ((tabChangeListener = createChangeListener()) != null) {                        tabPane.addChangeListener(tabChangeListener);        }        if ((mouseInputListener = createMouseInputListener()) != null) {	    if (scrollableTabLayoutEnabled()) { 		tabScroller.tabPanel.addMouseListener(mouseInputListener);		tabScroller.tabPanel.addMouseMotionListener(mouseInputListener);	    } else { // WRAP_TAB_LAYOUT                tabPane.addMouseListener(mouseInputListener);                tabPane.addMouseMotionListener(mouseInputListener);	    }        }                if ((focusListener = createFocusListener()) != null) {            tabPane.addFocusListener(focusListener);        }	// PENDING(api) : See comment for ContainerHandler        if ((containerListener = new ContainerHandler()) != null) {            tabPane.addContainerListener(containerListener);	    if (tabPane.getTabCount()>0) {		htmlViews = createHTMLVector();	    }	}    }    protected void uninstallListeners() {        if (mouseInputListener != null) {	    if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT		tabScroller.tabPanel.removeMouseListener(mouseInputListener);		tabScroller.tabPanel.removeMouseMotionListener(                            mouseInputListener);	    } else { // WRAP_TAB_LAYOUT                tabPane.removeMouseListener(mouseInputListener);                tabPane.removeMouseMotionListener(mouseInputListener);	    }            mouseInputListener = null;        }        if (focusListener != null) {            tabPane.removeFocusListener(focusListener);            focusListener = null;        }	    	// PENDING(api): See comment for ContainerHandler        if (containerListener != null) {            tabPane.removeContainerListener(containerListener);            containerListener = null;	    if (htmlViews!=null) {		htmlViews.removeAllElements();		htmlViews = null;	    }        }        if (tabChangeListener != null) {            tabPane.removeChangeListener(tabChangeListener);            tabChangeListener = null;        }        if (propertyChangeListener != null) {            tabPane.removePropertyChangeListener(propertyChangeListener);            propertyChangeListener = null;        }    }    protected MouseInputListener createMouseInputListener() {        return new MouseHandler();    }    protected FocusListener createFocusListener() {        return new FocusHandler();    }        protected ChangeListener createChangeListener() {

⌨️ 快捷键说明

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