📄 guiutilities.java
字号:
/* * GUIUtilities.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;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Frame;import java.awt.Point;import java.io.File;import java.io.PrintStream;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.swing.ActionMap;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLayeredPane;import javax.swing.JMenuBar;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.UIManager;import org.executequery.components.StatusBarPanel;import org.executequery.gui.MainMenu;import org.executequery.gui.editor.QueryEditor;import org.executequery.gui.text.TextEditorContainer;import org.underworldlabs.swing.toolbar.ToolBarProperties;import org.executequery.toolbars.ToolBarManager;import org.underworldlabs.swing.actions.BaseActionCommand;import org.executequery.actions.editcommands.*;import org.underworldlabs.swing.actions.ActionBuilder;import org.executequery.base.DesktopMediator;import org.executequery.base.DockedTabListener;import org.executequery.base.DockedTabView;import org.executequery.base.TabComponent;import org.underworldlabs.swing.ExceptionErrorDialog;import org.underworldlabs.swing.util.IconUtilities;import org.executequery.util.SystemResources;import org.executequery.gui.SaveFunction;import org.executequery.print.PrintFunction;import org.executequery.gui.text.TextEditor;import org.executequery.databasemediators.DatabaseConnection;import org.executequery.gui.BaseDialog;import org.executequery.gui.MultiplePanelInstance;import org.executequery.gui.OpenComponentRegister;import org.executequery.gui.PanelCacheObject;import org.executequery.gui.SystemOutputPanel;import org.executequery.gui.SystemPropertiesDockedTab;import org.executequery.gui.UndoableComponent;import org.underworldlabs.jdbc.DataSourceException;import org.executequery.gui.browser.ConnectionsTreePanel;import org.executequery.gui.drivers.DriversTreePanel;import org.executequery.gui.editor.QueryEditorSettings;import org.executequery.gui.keywords.KeywordsDockedPanel;import org.executequery.gui.sqlstates.SQLStateCodesDockedPanel;import org.executequery.util.Log;import org.executequery.util.SystemErrLogger;import org.underworldlabs.swing.GUIUtils;import org.underworldlabs.util.SystemProperties;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * <p>The GUIUtilities is the primary 'controller' class for all * Execute Query GUI components. It provides access to resources * in addition to many utility helper methods such as displaying * simple dialogs and updating menus. * * <p>This class will hold a reference to all primary components * for access by other classes. This includes those currently in-focus * components such as the Query Editor or other text components. * * <p>All internal frames are added (and closed via relevant 'Close' * buttons as may apply) from here. * * @author Takis Diakoumis * @version $Revision: 1.14 $ * @date $Date: 2006/09/06 09:30:58 $ */public class GUIUtilities { /** The tool bar manager instance */ private static ToolBarManager toolBar; /** The window status bar */ private static StatusBarPanel statusBar; /** The window menu bar */ private static MainMenu menuBar; /** The currently installed look and feel */ private static int lookAndFeel; /** The maximum allowable open query editors */ private static int maxOpenEditors; /** The open dialog in focus */ private static JDialog focusedDialog; /** register for all open components - dialogs, tabs etc. */ private static OpenComponentRegister register; /** the application frame */ private static JFrame frame; /** panel and desktop mediator object */ private static DesktopMediator desktopMediator; /** default icon for open tabs - when none is provided */ private static Icon defaultIcon; /** the layout properties controller */ private static UserLayoutProperties layoutProperties; /** docked panel cache of non-central pane tabs */ private static Map<String,JPanel> dockedTabComponents; /** the resource path to the image directory */ public static final String IMAGE_PATH = "/org/executequery/images/"; /** the resource path to the icon directory */ public static final String ICON_PATH = "/org/executequery/icons/"; /** private constructor */ private GUIUtilities() {} public static void initDesktop(JFrame aFrame) { frame = aFrame; // create the mediator object desktopMediator = new DesktopMediator(frame); // initialise and add the status bar statusBar = new StatusBarPanel(" Not Connected", Constants.EMPTY); statusBar.setFourthLabelText( "JDK" + System.getProperty("java.version").substring(0,5), SwingConstants.CENTER); frame.add(statusBar, BorderLayout.SOUTH); // init the layout properties layoutProperties = new UserLayoutProperties(); } public static void initPanels() { // init the open component register and set as a listener register = new OpenComponentRegister(); desktopMediator.addDockedTabListener(register); // setup the default docked tabs and their positions setDockedTabViews(false); // add a query editor addCentralPane(QueryEditor.TITLE, QueryEditor.FRAME_ICON, new QueryEditor(), null, false); // divider locations setDividerLocations(); // add the split pane divider listener desktopMediator.addPropertyChangeListener(layoutProperties); desktopMediator.addDockedTabDragListener(layoutProperties); desktopMediator.addDockedTabListener(layoutProperties); // select the first main panel desktopMediator.setSelectedPane(SwingConstants.CENTER, 0); //desktopMediator.resetPaneToPreferredSizes(SwingConstants.WEST, false); } /** * Sets the divider locations to previously saved (or default) values. */ protected static void setDividerLocations() { String[] keys = DesktopMediator.DIVIDER_LOCATION_KEYS; for (int i = 0; i < keys.length; i++) { String key = keys[i]; int location = SystemProperties.getIntProperty("user", key); //Log.debug("key: "+key+" loc: "+location); if (location > 0) { desktopMediator.setSplitPaneDividerLocation(key, location); } } } /** * Removes the specified docked tab listener. * * @param the listener */ public void removeDockedTabListener(DockedTabListener listener) { desktopMediator.removeDockedTabListener(listener); } /** * Adds the specified docked tab listener. * * @param the listener */ public void addDockedTabListener(DockedTabListener listener) { desktopMediator.addDockedTabListener(listener); } /** * Sets the default icon to that specified. * * @param the icon to be set as the default */ public static void setDefaultIcon(Icon icon) { defaultIcon = icon; } /** * Adds the specified component as a docked tab component * in the specified position. * * @param the tab title * @param the tab icon * @param the component * @param the tab's tool tip */ public static void addCentralPane(String title, Icon icon, Component component, String tip, boolean selected) { addDockedTab(title, icon, component, tip, SwingConstants.CENTER, selected); } /** * Adds the specified component as a docked tab component * in the specified position. * * @param the tab title * @param the tab icon * @param the component * @param the tab's tool tip */ public static void addCentralPane(String title, String icon, Component component, String tip, boolean selected) { addDockedTab(title, loadIcon(icon, true), component, tip, SwingConstants.CENTER, selected); } /** * Adds the specified component as a docked tab component * in the specified position. * * @param the tab title * @param the component * @param the position */ public static void addDockedTab(String title, Component component, int position, boolean selected) { addDockedTab(title, null, component, null, position, selected); } /** * Adds the specified component as a docked tab component * in the specified position. * * @param the tab title * @param the tab icon * @param the component * @param the position */ public static void addDockedTab(String title, Icon icon, Component component, int position, boolean selected) { addDockedTab(title, icon, component, null, position, selected); } /** * Adds the specified component as a docked tab component * in the specified position. * * @param the tab title * @param the tab icon * @param the component * @param the tab's tool tip * @param the position */ public static void addDockedTab(String title, Icon icon, Component component, String tip, int position, boolean selected) { // change the title if a save function if (component instanceof MultiplePanelInstance) { MultiplePanelInstance mpi = (MultiplePanelInstance)component; String _title = mpi.getDisplayName(); if (_title.length() > 0) { title = _title; tip = _title; } } // if this is a main window component, add to cache if (position == SwingConstants.CENTER) { register.addOpenPanel(title, component); } desktopMediator.addDockedTab(title, icon, component, tip, position, selected); GUIUtils.scheduleGC(); } /** * Closed the specfied docked component with name at the specified position. * * @param the name of the tab component * @param the position */ public static void closeDockedComponent(String name, int position) { desktopMediator.closeTabComponent(name, position); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -