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

📄 dockedtabpane.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * DockedTabPane.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.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Insets;import java.awt.Rectangle;import java.awt.RenderingHints;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import javax.swing.Icon;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.SwingUtilities;import javax.swing.ToolTipManager;import javax.swing.UIManager;import javax.swing.event.MouseInputListener;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * Left, right and bottom docked tab pane. * * @author   Takis Diakoumis * @version  $Revision: 1.6 $ * @date     $Date: 2006/08/11 12:33:14 $ */public class DockedTabPane extends AbstractTabPane {        /** the currently dragging index */    private int draggingIndex;        /** the tab panel */    private TabPanel tabPanel;        /** the tab popup menu */    private TabPopupMenu tabPopupMenu;        /**      * Creates a new instance of DockedTabPane with     * the specified parent container     *     * @param the enclosing tab container     */    public DockedTabPane(DockedTabContainer parent) {        setLayout(new BorderLayout());        this.parent = parent;        init();    }    /** Initialises the state of this object */    private void init() {        super.initComponents();        // panel where actual tabs are drawn        tabPanel = new TabPanel();        setTabPanel(tabPanel);    }    /**     * Indicates a top-level focus change.     */    protected void focusChanged() {        tabPanel.repaint();    }        /**      * Adds the specified tab component to the pane.     *     * @param the component to be added     */    public void addTab(TabComponent tabComponent) {        components.add(tabComponent);                Component component = tabComponent.getComponent();        String layoutName = tabComponent.getLayoutName();        componentPanel.add(component, layoutName);        cardLayout.addLayoutComponent(component, layoutName);                // inform the tab of its position        tabComponent.setIndex(components.indexOf(tabComponent));        tabComponent.setPosition(parent.getTabPanePosition(this));                if (components.size() == 1) {            setSelectedTab(tabComponent);        }    }            protected void calculateTabRects(int tabCount) {        // check that we still have the right count        if (tabRects.length != tabCount) {            tabRects = new Rectangle[tabCount];        }        int tabWidth = getTabWidth(tabCount);        for (int i = 0; i < tabCount; i++) {            Rectangle rect = null;            if (tabRects[i] == null) {                rect = new Rectangle();                tabRects[i] = rect;            } else {                rect = tabRects[i];            }            if (i > 0) {                rect.x = tabRects[i-1].x + tabRects[i-1].width;            } else {                rect.x = 0;            }            rect.y = 0;            rect.width = tabWidth;            rect.height = tabPanel.getTabHeight();        }    }    /**     * Returns whether the specified x-y coordinates      * intersect the tab area (tab panel).     *      * @param the x coordinate     * @param the x coordinate     * @return true if the point intersects, false otherwise     */    protected boolean intersectsTabArea(int x, int y) {        return tabPanel.getBounds().contains(x, y);    }        /**     * Returns the index of the tab currently being dragged.     *     * @return the tab index dragged     */    protected int getDraggingIndex() {        return draggingIndex;    }        private int getTabWidth(int tabCount) {        return (getWidth() / tabCount);    }        /**     * Calculates the close icon rectangle for the specified     * tab bounds.     *     * @param the tab bounds     * @return the close icon bounds     */    private Rectangle getCloseIconRectangle(Rectangle tabRect) {        int y = tabRect.y + ((tabRect.height - TabControlIcon.ICON_HEIGHT) / 2);        int x = tabRect.x + ((int)(tabRect.width - TabControlIcon.ICON_WIDTH - 6));        return new Rectangle(x, y, TabControlIcon.ICON_WIDTH, TabControlIcon.ICON_HEIGHT);    }    /**     * Calculates the minimise icon rectangle for the specified     * tab bounds.     *     * @param the tab bounds     * @return the close icon bounds     */    private Rectangle getMinimizeIconRectangle(Rectangle tabRect) {        int y = tabRect.y + ((tabRect.height - TabControlIcon.ICON_HEIGHT) / 2);        int x = tabRect.x + ((int)(tabRect.width - (TabControlIcon.ICON_WIDTH * 2) - 10));        return new Rectangle(x, y, TabControlIcon.ICON_WIDTH, TabControlIcon.ICON_HEIGHT);    }    protected Rectangle getTabRectangleAtLocation(int x, int y) {        int index = getTabAtLocation(x, y);        if (index == -1) {            return null;        }        return tabRects[index];    }    /**     * Returns the index in the tab pane of the specified     * tab rectangle. if the specified tab rectangle is      * not in the tab pane, -1 is returned.     *     * @param the tab rectangle     * @return the index of the tab rectangle or -1 if its     *         not present     */    protected int getTabRectangleIndex(Rectangle tabRect) {        for (int i = 0; i < tabRects.length; i++) {            if (tabRects[i] == tabRect) {                return i;            }        }        return -1;    }    /**     * Returns the tab component object at the      * specified x and y coordinate.     *     * @param x coordinate     * @param y coordinate     * @return the component index at the x-y coords     */    protected int getTabAtLocation(int x, int y) {        for (int i = 0; i < tabRects.length; i++) {            if (tabRects[i].contains(x, y)) {                return i;            }        }        return -1;    }    public void setSelectedIndex(int index) {        super.setSelectedIndex(index);        tabPanel.repaint();        fireTabSelected(new DockedTabEvent(components.get(index)));    }        protected void insertTab(TabComponent tabComponent, int toIndex) {        if (tabComponent == null || toIndex == -1) {            return;        }        components.add(toIndex, tabComponent);        componentPanel.add(tabComponent.getComponent(), tabComponent.getTitle());        // reset the layout        cardLayout.invalidateLayout(componentPanel);                int tabCount = components.size();        for (int i = 0; i < tabCount; i++) {            TabComponent _tabComponent = components.get(i);            cardLayout.addLayoutComponent(_tabComponent.getComponent(),                                           _tabComponent.getLayoutName());        }        // inform the tab of its position        tabComponent.setIndex(toIndex);        tabComponent.setPosition(parent.getTabPanePosition(this));        setSelectedIndex(toIndex);    }        protected void moveTab(int fromIndex, int toIndex) {        if (fromIndex == toIndex || (fromIndex == -1 || toIndex == -1)) {            return;        }        TabComponent tabComponent = components.get(fromIndex);                tabComponent.setIndex(toIndex);        // remove from the component cache        components.remove(fromIndex);        components.add(toIndex, tabComponent);        setSelectedIndex(toIndex);    }    /**     * Returns the height of the tab itself ie. the selection part with     * the title etc.     *      * @return the tab height     */    public int getTabHeight() {        return tabPanel.getHeight();    }        /**     * Minimises all the tabs in the panel     */    protected void minimiseAll() {        for (int i = 0, k = components.size(); i < k; i++) {            TabComponent tabComponent = components.get(i);            parent.minimiseComponent(tabComponent);            fireTabMinimised(new DockedTabEvent(tabComponent));        }        removeAllTabs();    }    /**     * Minimises the tab from the panel at the specified index.     *     * @param the index to be removed     */    protected void minimiseIndex(int index) {        if (index < 0) {            return;        }

⌨️ 快捷键说明

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