📄 dockedtabcontainer.java
字号:
/* * DockedTabContainer.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.Component;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.ArrayList;import java.util.List;import javax.swing.Icon;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JSplitPane;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.UIManager;import org.underworldlabs.swing.VerticalTextIcon;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * The base component for a docked tab panel. * This will control the docked tab in addition to * provide minimised button panels, action controls * and tool tip creation. * * @author Takis Diakoumis * @version $Revision: 1.5 $ * @date $Date: 2006/07/15 14:56:32 $ */public class DockedTabContainer extends JPanel implements SwingConstants, PropertyChangeListener { /** the container's position */ private int orientation; /** The mediator/controller class */ private DesktopMediator desktopMediator; /** the north docked tab pane */ private DockedTabPane northTabPane; /** the south docked tab pane */ private DockedTabPane southTabPane; /** scrolling tab pane if this is a central container */ private ScrollingTabPane scrollingTabPane; /** the split pane for this container */ private TabContainerSplitPane splitPane; /** the minimised tabs button panel */ private ButtonPanel buttonPanel; /** the minimised tab components added to this panel */ private List<TabComponent> minimisedComponents; /** Registered tab pane listeners */ private List<DockedTabDragListener> listeners; /** The default divider location for vertical splits */ private static final double defaultDividerLocation = 0.75; /** Creates a new instance of DockedTabContainer */ public DockedTabContainer(DesktopMediator desktopMediator, int orientation) { super(new BorderLayout()); this.desktopMediator = desktopMediator; this.orientation = orientation; init(); } /** Initialises the state of this component */ private void init() { initSplitPane(); add(splitPane, BorderLayout.CENTER); splitPane.addPropertyChangeListener(this); } /** * Indicates whether this tab container has the focused tab pane. * * @return true | false */ protected boolean hasFocusedTabPane() { if (northTabPane != null && northTabPane.isFocused()) { return true; } else if (southTabPane != null && southTabPane.isFocused()) { return true; } else if (scrollingTabPane != null && scrollingTabPane.isFocused()) { return true; } return false; } /** * Returns the focused tab pane or null if no pane in this * container currently has the focus. * * @return the tab pane in focus */ protected TabPane getTabPaneInFocus() { if (northTabPane != null && northTabPane.isFocused()) { return northTabPane; } else if (southTabPane != null && southTabPane.isFocused()) { return southTabPane; } else if (scrollingTabPane != null && scrollingTabPane.isFocused()) { return scrollingTabPane; } return null; } /** * Indicates a focus change on the tab components.<br> * This is propagated to the mediator object. * * @param tabPane - the new focused tab pane */ protected void tabPaneFocusChange(TabPane tabPane) { if (tabPane == northTabPane || tabPane == scrollingTabPane) { // turn on the glass pane on non-selected components splitPane.setGlassPaneVisible(SwingUtilities.BOTTOM, true); // turn off the selected one splitPane.setGlassPaneVisible(SwingUtilities.TOP, false); // inform the other tab pane in the split if (southTabPane != null) { southTabPane.focusLost(); } } else if (tabPane == southTabPane) { splitPane.setGlassPaneVisible(SwingUtilities.TOP, true); splitPane.setGlassPaneVisible(SwingUtilities.BOTTOM, false); // inform the other tab panes in the split if (northTabPane != null) { northTabPane.focusLost(); } if (scrollingTabPane != null) { scrollingTabPane.focusLost(); } } desktopMediator.tabPaneFocusChange(this); } /** * Switches on the glass pane's of this container's tab panes. */ protected void tabPaneFocusLost() { if (northTabPane != null) { northTabPane.focusLost(); } if (scrollingTabPane != null) { scrollingTabPane.focusLost(); } if (southTabPane != null) { southTabPane.focusLost(); } splitPane.setGlassPaneVisible(SwingUtilities.TOP, true); splitPane.setGlassPaneVisible(SwingUtilities.BOTTOM, true); } /** * Sets the split pane divider location to that specified. * * @param the divider location */ public void setSplitPaneDividerLocation(int location) { if (splitPane != null) { splitPane.setDividerLocation(location); } } /** * Provides notification of split pane divider movement events. * * @param the change event */ public void propertyChange(PropertyChangeEvent e) { String name = e.getPropertyName(); if ("dividerLocation".equals(name)) { String value = e.getNewValue().toString(); desktopMediator.splitPaneDividerMoved(orientation, Integer.parseInt(value)); /* Log.debug("property change: " + e.getPropertyName() + " old value: " + e.getOldValue() + " new value: " + e.getNewValue()); */ } } /** * Notifies all registered listeners of a tab minimised event. * * @param the event */ public void fireTabMinimised(DockedTabEvent e) { desktopMediator.fireTabMinimised(e); } /** * Notifies all registered listeners of a tab selected event. * * @param the event */ public void fireTabSelected(DockedTabEvent e) { desktopMediator.fireTabSelected(e); } /** * Notifies all registered listeners of a tab deselected event. * * @param the event */ public void fireTabDeselected(DockedTabEvent e) { desktopMediator.fireTabDeselected(e); } /** * Notifies all registered listeners of a tab closed event. * * @param the event */ public void fireTabClosed(DockedTabEvent e) { desktopMediator.fireTabClosed(e); } /** * Notifies all registered listeners of a tab restored event. * * @param the event */ protected void fireTabRestored(DockedTabEvent e) { desktopMediator.fireTabRestored(e); } /** * Invoked when a mouse button is pressed on a tab and then dragged. * * @param the encapsulating event object */ public void fireDockedTabDragged(DockedDragEvent e) { desktopMediator.fireDockedTabDragged(e); } /** * Invoked when a mouse button has been released on a tab. * * @param the encapsulating event object */ public void fireDockedTabReleased(DockedDragEvent e) { desktopMediator.fireDockedTabReleased(e); } /** * Selects the next tab from the current selection. */ public void selectNextTab(int position) { TabPane tabPane = getTabPaneForPosition(position); tabPane.selectNextTab(); } /** * Selects the previous tab from the current selection. */ public void selectPreviousTab(int position) { TabPane tabPane = getTabPaneForPosition(position); tabPane.selectPreviousTab(); } /** * Closed the specfied tab component with name at the specified position. * * @param the name of the tab component * @param the position */ public void closeTabComponent(String name, int position) { switch (position) { case SwingConstants.NORTH: case SwingConstants.NORTH_WEST: case SwingConstants.NORTH_EAST: if (northTabPane != null) { northTabPane.closeTabComponent(name); } break; case SwingConstants.SOUTH: case SwingConstants.SOUTH_WEST: case SwingConstants.SOUTH_EAST: if (southTabPane != null) { southTabPane.closeTabComponent(name); } else { // wrong position - check north closeTabComponent(name, NORTH); } break; case SwingConstants.CENTER: if (scrollingTabPane != null) { scrollingTabPane.closeTabComponent(name); } break; } } /** * Returns the tab pane at the specified position. * * @param position - the position of the pane */ protected TabPane getTabPaneForPosition(int position) { switch (position) { case SwingConstants.NORTH: case SwingConstants.NORTH_WEST: case SwingConstants.NORTH_EAST: return northTabPane; case SwingConstants.SOUTH: case SwingConstants.SOUTH_WEST: case SwingConstants.SOUTH_EAST: return southTabPane; case SwingConstants.CENTER: return scrollingTabPane; } return null; } /** * Returns the selected tab component at the specified position. * * @param the component position - <br> * SwingConstants.NORTH<br> * SwingConstants.NORTH_WEST<br> * SwingConstants.NORTH_EAST<br> * SwingConstants.SOUTH<br> * SwingConstants.SOUTH_WEST<br> * SwingConstants.SOUTH_EAST<br> * SwingConstants.CENTER<br> */ public TabComponent getComponentAt(int position) { switch (position) { case SwingConstants.NORTH: case SwingConstants.NORTH_WEST: case SwingConstants.NORTH_EAST: if (northTabPane != null) { return northTabPane.getSelectedComponent(); } break; case SwingConstants.SOUTH: case SwingConstants.SOUTH_WEST: case SwingConstants.SOUTH_EAST: if (southTabPane != null) { return southTabPane.getSelectedComponent(); } break; case SwingConstants.CENTER: if (scrollingTabPane != null) { return scrollingTabPane.getSelectedComponent(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -