📄 baseapplicationpane.java
字号:
/* * BaseApplicationPane.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.Cursor;import java.awt.Point;import java.awt.Rectangle;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.BorderFactory;import javax.swing.JPanel;import javax.swing.JRootPane;import javax.swing.JSplitPane;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.border.Border;import org.underworldlabs.swing.FlatSplitPane;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author Takis Diakoumis * @version $Revision: 1.5 $ * @date $Date: 2006/06/14 16:11:00 $ */public class BaseApplicationPane extends JPanel implements PropertyChangeListener { /** Whether panel is being dragged */ private boolean dragging; /** The outline panel shown when dragging */ private DragPanel dragPanel; /** Temp value for the tab pane a move is occurring from */ private DockedTabPane fromTabPane; /** Temp value for the tab pane a move is occurring to */ private DockedTabPane toTabPane; /** The primary application frame */ private ApplicationFrame frame; /** The tab pane position for a new tab */ private int newTabPanePosition; /** The mediator/controller class */ private DesktopMediator desktopMediator; // --------------------------------------- // primary desktop components // --------------------------------------- /** the content panel border */ private Border contentBorder; /** the left main split pane */ private FlatSplitPane leftSplitPane; /** the right main split pane */ private FlatSplitPane rightSplitPane; /** Creates a new instance of BaseApplicationPane */ public BaseApplicationPane(DesktopMediator desktopMediator) { super(new BorderLayout()); this.desktopMediator = desktopMediator; init(); } private void init() { // init the main split panes leftSplitPane = new FlatSplitPane(JSplitPane.HORIZONTAL_SPLIT); leftSplitPane.setDividerSize(0); //configureSplitPane(leftSplitPane); rightSplitPane = new FlatSplitPane(JSplitPane.HORIZONTAL_SPLIT); rightSplitPane.setResizeWeight(1.0); rightSplitPane.setDividerSize(0); //configureSplitPane(rightSplitPane); leftSplitPane.setBorder(null); rightSplitPane.setBorder(null);// leftSplitPane.setBorder(BorderFactory.createEmptyBorder(1,3,0,0));// rightSplitPane.setBorder(BorderFactory.createEmptyBorder(1,0,0,1)); // add the left main pane to the right main pane rightSplitPane.setLeftComponent(leftSplitPane); add(rightSplitPane, BorderLayout.CENTER); leftSplitPane.addPropertyChangeListener(this); rightSplitPane.addPropertyChangeListener(this); } /** * 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)) { int position = -1; String value = e.getNewValue().toString(); Object source = e.getSource(); if (source == leftSplitPane) { if (leftSplitPane.getLeftComponent() == null) { return; } position = SwingConstants.LEFT; } else if (source == rightSplitPane) { if (rightSplitPane.getRightComponent() == null) { return; } position = SwingConstants.RIGHT; } desktopMediator.splitPaneDividerMoved(position, Integer.parseInt(value));/* Log.debug("property change: " + e.getPropertyName() + " old value: " + e.getOldValue() + " new value: " + e.getNewValue());*/ } } /** * Sets the split pane divider location for the split pane * at the specified location <code>SwingConstants.LEFT | * SwingConstants.RIGHT</code> to the specified value. * * @param the split pane location * @param the divider location */ public void setSplitPaneDividerLocation(int position, int location) { if (position == SwingConstants.LEFT) { if (leftSplitPane != null) { if (leftSplitPane.getLeftComponent() != null && leftSplitPane.getRightComponent() != null) { leftSplitPane.setDividerLocation(location); } } } else if (position == SwingConstants.RIGHT) { if (rightSplitPane != null) { if (rightSplitPane.getLeftComponent() != null && rightSplitPane.getRightComponent() != null) { rightSplitPane.setDividerLocation(location); } } } } /** * 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); } /** * Common split pane configuration routines. */ private void configureSplitPane(JSplitPane splitPane) { splitPane.setDividerSize(ApplicationConstants.SPLIT_PANE_DIVIDER_SIZE); } /** * Resets the split pane component in the specified * position to the preferred sizes of the split pane * children components. * * @param the position of the pane */ public void resetPaneToPreferredSizes(int position, boolean restore) { switch (position) { case SwingConstants.WEST: if (!restore) { leftSplitPane.storeDividerLocation(); leftSplitPane.setDividerLocation( leftSplitPane.getMinimumDividerLocation()); } else { leftSplitPane.restoreDividerLocation(); } break; case SwingConstants.EAST: if (!restore) { rightSplitPane.storeDividerLocation(); rightSplitPane.setDividerLocation( rightSplitPane.getMaximumDividerLocation()); } else { rightSplitPane.restoreDividerLocation(); } break; } } /** * Indicates whether the split pane at the specified * position (left or right) is visible. * This will always return true for a center position. * * @param SwingConstants.LEFT | SwingConstants.RIGHT * @return true if visible, false otherwise */ public boolean isSplitPaneVisible(int position) { switch (position) { case SwingConstants.WEST: return leftSplitPane.getLeftComponent() != null; case SwingConstants.EAST: return rightSplitPane.getRightComponent() != null; } return true; } public void removeComponent(int position) { switch (position) { case SwingConstants.WEST: leftSplitPane.storeDividerLocation(); leftSplitPane.setLeftComponent(null); leftSplitPane.setDividerSize(0); break; case SwingConstants.CENTER: leftSplitPane.setRightComponent(null); leftSplitPane.setDividerSize(0); break; case SwingConstants.EAST: rightSplitPane.storeDividerLocation(); rightSplitPane.setRightComponent(null); rightSplitPane.setDividerSize(0); break; } } /** * Adds the component to a bordered base panel. * * @param the component to add */ private JPanel createBasePanel(Component c) { if (c == null) { return null; } if (contentBorder == null) { contentBorder = BorderFactory.createEmptyBorder( ApplicationConstants.TAB_COMPONENT_BORDER_THICKNESS, ApplicationConstants.TAB_COMPONENT_BORDER_THICKNESS, ApplicationConstants.TAB_COMPONENT_BORDER_THICKNESS, ApplicationConstants.TAB_COMPONENT_BORDER_THICKNESS); } JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(contentBorder); panel.add(c, BorderLayout.CENTER); return panel; } /** * Adds the specified component in the specified position. * * @param the component to add * @param the position this component is to be added<br> * one of: <code>SwingConstants.WEST | CENTER | EAST</code> */ public void addComponent(Component c, int position) { switch (position) { case SwingConstants.WEST: leftSplitPane.setLeftComponent(c); configureSplitPane(leftSplitPane); break; case SwingConstants.CENTER: leftSplitPane.setRightComponent(c); configureSplitPane(leftSplitPane); break; case SwingConstants.EAST: rightSplitPane.setRightComponent(c); configureSplitPane(rightSplitPane); rightSplitPane.setDividerLocation(0.8); break; /* case SwingConstants.WEST: if (leftSplitPane == null) { leftSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); } // check if we have a component at this position // and move al if required if (leftSplitPane.getLeftComponent() != null) { } leftSplitPane.setLeftComponent(c); break; case SwingConstants.CENTER: if (leftSplitPane == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -