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

📄 basictabbedpaneui.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)BasicTabbedPaneUI.java	1.153 05/03/03 * * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;import com.sun.java.swing.SwingUtilities2;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;import sun.swing.DefaultLookup;import sun.swing.UIAction;/** * 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;    private boolean tabsOverlapBorder;    private boolean tabsOpaque = true;    private boolean contentOpaque = true;    /**     * 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;// 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;// 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);    /**     * Tab that has focus.     */    private int focusIndex;    /**     * Combined listeners.     */    private Handler handler;    /**     * Index of the tab the mouse is over.     */    private int rolloverTabIndex;    /**     * This is set to true when a component is added/removed from the tab     * pane and set to false when layout happens.  If true it indicates that     * tabRuns is not valid and shouldn't be used.     */    private boolean isRunsDirty;// UI creation    public static ComponentUI createUI(JComponent c) {        return new BasicTabbedPaneUI();    }    static void loadActionMap(LazyActionMap map) {        map.put(new Actions(Actions.NEXT));        map.put(new Actions(Actions.PREVIOUS));        map.put(new Actions(Actions.RIGHT));        map.put(new Actions(Actions.LEFT));        map.put(new Actions(Actions.UP));        map.put(new Actions(Actions.DOWN));        map.put(new Actions(Actions.PAGE_UP));        map.put(new Actions(Actions.PAGE_DOWN));        map.put(new Actions(Actions.REQUEST_FOCUS));        map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));        map.put(new Actions(Actions.SET_SELECTED));        map.put(new Actions(Actions.SELECT_FOCUSED));        map.put(new Actions(Actions.SCROLL_FORWARD));        map.put(new Actions(Actions.SCROLL_BACKWARD));    }// UI Installation/De-installation        public void installUI(JComponent c) {        this.tabPane = (JTabbedPane)c;        rolloverTabIndex = -1;        focusIndex = -1;        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);            }        }    }    /**     * Creates and returns a JButton that will provide the user     * with a way to scroll the tabs in a particular direction. The     * returned JButton must be instance of UIResource.     *     * @param direction One of the SwingConstants constants:     * SOUTH, NORTH, EAST or WEST     * @return Widget for user to      * @see javax.swing.JTabbedPane#setTabPlacement     * @see javax.swing.SwingConstants     * @throws IllegalArgumentException if direction is not one of     *         NORTH, SOUTH, EAST or WEST     * @since 1.5     */    protected JButton createScrollButton(int direction) {        if (direction != SOUTH && direction != NORTH && direction != EAST &&                                  direction != WEST) {            throw new IllegalArgumentException("Direction must be one of: " +                                               "SOUTH, NORTH, EAST or WEST");        }        return new ScrollableTabButton(direction);    }    /**     * 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");	tabsOverlapBorder = UIManager.getBoolean("TabbedPane.tabsOverlapBorder");        contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");        tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");        tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");        contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");        Object opaque = UIManager.get("TabbedPane.opaque");        if (opaque == null) {            opaque = Boolean.FALSE;        }        LookAndFeel.installProperty(tabPane, "opaque", opaque);    }    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) {            tabPane.addMouseListener(mouseListener);        }        tabPane.addMouseMotionListener(getHandler());        if ((focusListener = createFocusListener()) != null) {            tabPane.addFocusListener(focusListener);        }        tabPane.addContainerListener(getHandler());        if (tabPane.getTabCount()>0) {            htmlViews = createHTMLVector();        }    }    protected void uninstallListeners() {        if (mouseListener != null) {            tabPane.removeMouseListener(mouseListener);            mouseListener = null;        }        tabPane.removeMouseMotionListener(getHandler());        if (focusListener != null) {            tabPane.removeFocusListener(focusListener);            focusListener = null;        }                    tabPane.removeContainerListener(getHandler());        if (htmlViews!=null) {            htmlViews.removeAllElements();            htmlViews = null;

⌨️ 快捷键说明

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