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

📄 abstracttabpane.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * AbstractTabPane.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * */package org.executequery.base;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.Color;import java.awt.Component;import java.util.ArrayList;import java.util.List;import javax.swing.BorderFactory;import javax.swing.Icon;import javax.swing.JPanel;import javax.swing.UIManager;import org.underworldlabs.swing.plaf.UIUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * Abstract tab pane base. * * @author   Takis Diakoumis * @version  $Revision: 1.7 $ * @date     $Date: 2006/07/15 14:57:21 $ */public abstract class AbstractTabPane extends JPanel                                      implements TabPane {        /** the components added to this panel */    protected List<TabComponent> components;    /** the display panel layout manager */    protected CardLayout cardLayout;    /** the currently selected index */    protected int selectedIndex;    /** this pane's parent container */    protected DockedTabContainer parent;    /** the tab component panel */    protected JPanel componentPanel;    /** Whether this tab pane is the focused tab pane */    protected boolean isFocusedTabPane;        /** Initialises the state of this object */    protected void initComponents() {        selectedIndex = -1;        // repo for added components        components = new ArrayList<TabComponent>();        // panel and layout for components        cardLayout = new CardLayout();        componentPanel = new JPanel(cardLayout);        componentPanel.setBorder(BorderFactory.createMatteBorder(                                            0, 1, 1, 1, UIManager.getColor("controlShadow")));        add(componentPanel, BorderLayout.CENTER);    }    /** the selected tab background */    private Color selectedTabBackground;    /**     * Returns the active selection background colour for a tab.     *     * @return the selected background colour     */    protected Color getSelectedTabBackground() {        if (selectedTabBackground == null) {            if ((UIUtils.isMetalLookAndFeel()) ||// && !UIUtils.usingOcean()) ||                    UIUtils.isMotifLookAndFeel() || UIUtils.isWindowsLookAndFeel()) {                selectedTabBackground =                         UIUtils.getDefaultActiveBackgroundColour();            }            else {                double darker = 0.9;                // check that the normal panel bg is not                 // the same as the tab selection bg                Color color1 = UIManager.getColor("TabbedPane.selected");                Color color2 = UIManager.getColor("TabbedPane.background");                if (color1 != null && color2 != null) {                    if (color1.getRGB() == color2.getRGB()) {                        selectedTabBackground = UIUtils.getDarker(color1, darker);                    } else {                        selectedTabBackground = color1;                    }                }                else if (color1 == null && color2 != null) {                    selectedTabBackground = UIUtils.getDarker(color2, darker);                }                else if (color2 == null && color1 != null) {                    selectedTabBackground = color1;                }            }        }        return selectedTabBackground;    }    /** the selected tab foreground */    private Color selectedTabForeground;    /**     * Returns the active selection foreground colour for a tab.     *     * @return the selected foreground colour     */    protected Color getSelectedTabForeground() {        return getTabForeground();    }    /** the selected tab foreground */    private Color tabForeground;    /**     * Returns the default foreground colour for a tab.     *     * @return the foreground colour     */    protected Color getTabForeground() {        if (tabForeground == null) {            tabForeground = UIManager.getColor("TabbedPane.foreground");        }        return tabForeground;    }    /** the default tab background */    private Color tabBackground;    /**     * Returns the default background colour for a tab.     *     * @return the background colour     */    protected Color getTabBackground() {        if (tabBackground == null) {            tabBackground = getBackground();        }        return tabBackground;    }    /** the selected no-focus tab background */    private Color nofocusTabBackground;    /**     * Returns the no-focus tab background.     *     * @return the no-focus background     */    protected Color getNofocusTabBackground() {        if (nofocusTabBackground == null) {            nofocusTabBackground = UIUtils.getBrighter(getTabBackground(), 0.9);        }        return nofocusTabBackground;    }        /**     * Indicates a top-level focus change.     */    protected abstract void focusChanged();        /**     * Indicates whether this tab pane has focus.     *     * @return true | false     */    public boolean isFocused() {        return isFocusedTabPane;    }    /**     * Indicates a focus gain.     */    public void focusGained() {        if (isFocusedTabPane) {            return;        }        isFocusedTabPane = true;        focusChanged();        parent.tabPaneFocusChange(this);    }    /**     * Indicates a focus loss.     */    public void focusLost() {        if (!isFocusedTabPane) {            return;        }        isFocusedTabPane = false;        focusChanged();    }    /**     * Returns the position of this tab pane.     */    public int getPosition() {        return parent.getOrientation();    }    /**     * Sets the title of the specified component to title which can be null.      * An internal exception is raised if there is no tab for the      * specified component.     *     * @param the component where the title should be set     * @param the title to be displayed in the tab     */    public void setTabTitleForComponent(Component component, String title) {        int index = indexOfComponent(component);        if (index == -1) {            throw new IndexOutOfBoundsException("Tab pane component not found.");        }        setTabTitleAt(index, title);    }    /**     * Selects the next tab from the current selection.     */    public void selectNextTab() {        int tabCount = getTabCount();        if (tabCount > 0) {            if (selectedIndex < tabCount - 1) {                setSelectedIndex(selectedIndex + 1);            }        }    }    /**     * Selects the previous tab from the current selection.     */    public void selectPreviousTab() {        int tabCount = getTabCount();        if (tabCount > 0) {            if (selectedIndex > 0) {                setSelectedIndex(selectedIndex - 1);            }        }    }    /**     * Sets the title at index to title which can be null.      * An internal exception is raised if there is no tab at that index.     *     * @param the tab index where the title should be set     * @param the title to be displayed in the tab     */    public void setTabTitleAt(int index, String title) {                //Log.debug("Setting tab title at: " + index + " to: " + title);                if (components == null || components.isEmpty()) {            throw new IndexOutOfBoundsException("Tab pane is empty.");        }        TabComponent tabComponent = components.get(index);        tabComponent.setTitle(title);        // make sure the title is unique        String suffix = getTitleSuffix(tabComponent);        if (suffix != null) {            tabComponent.setTitleSuffix(suffix);        }        //TODO: implement property change event stuff    }    /**     * Returns a unique title for the specified tab component.     */    protected String getTitleSuffix(TabComponent tabComponent) {        int componentCount = components.size();        // make sure the title is unique        if (componentCount > 1) {            int counterIndex = 0;            String title = tabComponent.getTitle();            for (int i = 0; i < componentCount; i++) {                TabComponent _tabComponent = components.get(i);                if (_tabComponent != tabComponent) {                    String _title = _tabComponent.getTitle();                    if (_title.equals(title)) {

⌨️ 快捷键说明

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