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

📄 basictabbedpaneui.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)BasicTabbedPaneUI.java	1.126 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;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;/** * A Basic L&F implementation of TabbedPaneUI. * * @version 1.87 06/08/99 * @author Amy Fowler * @author Philip Milne * @author Steve Wilson * @author Tom Santos * @author Dave Moore */public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants {// Instance variables initialized at installation    protected JTabbedPane tabPane;    protected Color highlight;    protected Color lightHighlight;    protected Color shadow;    protected Color darkShadow;    protected Color focus;    private   Color selectedColor;    protected int textIconGap;    protected int tabRunOverlay;    protected Insets tabInsets;    protected Insets selectedTabPadInsets;    protected Insets tabAreaInsets;    protected Insets contentBorderInsets;    /**     * 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.     */    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.     */    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.     */    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.     */    protected KeyStroke rightKey;// 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 MouseListener mouseListener;    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;// UI creation    public static ComponentUI createUI(JComponent c) {        return new BasicTabbedPaneUI();    }// 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() {        LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background",                                    "TabbedPane.foreground", "TabbedPane.font");             highlight = UIManager.getColor("TabbedPane.light");        lightHighlight = UIManager.getColor("TabbedPane.highlight");        shadow = UIManager.getColor("TabbedPane.shadow");        darkShadow = UIManager.getColor("TabbedPane.darkShadow");        focus = UIManager.getColor("TabbedPane.focus");	selectedColor = UIManager.getColor("TabbedPane.selected");        textIconGap = UIManager.getInt("TabbedPane.textIconGap");        tabInsets = UIManager.getInsets("TabbedPane.tabInsets");        selectedTabPadInsets = UIManager.getInsets("TabbedPane.selectedTabPadInsets");        tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");        contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");        tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");    }    protected void uninstallDefaults() {        highlight = null;        lightHighlight = null;        shadow = null;        darkShadow = null;        focus = null;        tabInsets = null;        selectedTabPadInsets = null;        tabAreaInsets = null;        contentBorderInsets = null;    }    protected void installListeners() {        if ((propertyChangeListener = createPropertyChangeListener()) != null) {            tabPane.addPropertyChangeListener(propertyChangeListener);        }        if ((tabChangeListener = createChangeListener()) != null) {                        tabPane.addChangeListener(tabChangeListener);        }        if ((mouseListener = createMouseListener()) != null) {	    if (scrollableTabLayoutEnabled()) { 		tabScroller.tabPanel.addMouseListener(mouseListener);	    } else { // WRAP_TAB_LAYOUT                tabPane.addMouseListener(mouseListener);	    }        }                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 (mouseListener != null) {	    if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT		tabScroller.tabPanel.removeMouseListener(mouseListener);	    } else { // WRAP_TAB_LAYOUT                tabPane.removeMouseListener(mouseListener);	    }            mouseListener = 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 MouseListener createMouseListener() {        return new MouseHandler();    }    protected FocusListener createFocusListener() {        return new FocusHandler();    }        protected ChangeListener createChangeListener() {        return new TabSelectionHandler();    }    protected PropertyChangeListener createPropertyChangeListener() {        return new PropertyChangeHandler();    }    protected void installKeyboardActions() {	InputMap km = getInputMap(JComponent.				  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);	SwingUtilities.replaceUIInputMap(tabPane, JComponent.					 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,					 km);	km = getInputMap(JComponent.WHEN_FOCUSED);	SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, km);	ActionMap am = getActionMap();	SwingUtilities.replaceUIActionMap(tabPane, am);	if (scrollableTabLayoutEnabled()) {	    tabScroller.scrollForwardButton.setAction(am.get("scrollTabsForwardAction"));	    tabScroller.scrollBackwardButton.setAction(am.get("scrollTabsBackwardAction"));	}    }    InputMap getInputMap(int condition) {	if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {	    return (InputMap)UIManager.get("TabbedPane.ancestorInputMap");	}	else if (condition == JComponent.WHEN_FOCUSED) {	    return (InputMap)UIManager.get("TabbedPane.focusInputMap");	}	return null;    }    ActionMap getActionMap() {	ActionMap map = (ActionMap)UIManager.get("TabbedPane.actionMap");	if (map == null) {	    map = createActionMap();	    if (map != null) {		UIManager.getLookAndFeelDefaults().put("TabbedPane.actionMap",                                                       map);	    }	}	return map;    }    ActionMap createActionMap() {	ActionMap map = new ActionMapUIResource();

⌨️ 快捷键说明

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