📄 guiutilities.java
字号:
// TODO: INPUT MAP return desktopMediator.getInputMap(condition); //return desktop.getInputMap(condition); } /** <p>Retrieves the applications <code>ActionMap</code>. * * @return the <code>ActionMap</code> */ public static ActionMap getActionMap() { // TODO: ACTION MAP return desktopMediator.getActionMap(); } /** <p>Registers the main menu bar with this class. * * @param the menu bar */ public static void registerMenuBar(JMenuBar menu) { menuBar = (MainMenu)menu; } /** * Initialises and starts the system logger. * The logger's stream is also registered for * <code>System.err</code> and <code>System.out</code>. */ public static void startLogger() { // init the cache if (dockedTabComponents == null) { dockedTabComponents = new HashMap<String, JPanel>(); } // add the output panel to the cache SystemOutputPanel panel = new SystemOutputPanel(); dockedTabComponents.put(SystemOutputPanel.PROPERTY_KEY, panel); // set system error stream to the output panel PrintStream stream = new PrintStream(new SystemErrLogger(), true); System.setErr(stream); //System.setOut(stream); } /** <p>Calculates and returns the centered position * of a dialog with the specified size to be added * to the desktop area - ie. taking into account the * size and location of all docked panels. * * @param the size of the dialog to be added as a * <code>Dimension</code> object * @return the <code>Point</code> at which to add the dialog */ public static Point getLocationForDialog(Dimension dialogDim) { return GUIUtils.getLocationForDialog(frame, dialogDim); } /** * Propagates the call to GUIUtils and schedules * the garbage collector to run. */ public static void scheduleGC() { GUIUtils.scheduleGC(); } /** * Returns whether the frame's glass pane is visible or not. * * @return true | false */ public static boolean isGlassPaneVisible() { return frame.getRootPane().getGlassPane().isVisible(); } /** * Shows/hides the frame's glass pane as specified. * * @param visible - true | false */ public static void setGlassPaneVisible(final boolean visible) { GUIUtils.invokeLater(new Runnable() { public void run() { if (isGlassPaneVisible() == visible) { return; } frame.getRootPane().getGlassPane().setVisible(visible); } }); } /** * Sets the application cursor to the system normal cursor */ public static void showNormalCursor() { GUIUtils.invokeAndWait(new Runnable() { public void run() { GUIUtils.showNormalCursor(frame); } }); //GUIUtils.showNormalCursor(frame); } /** * Sets the application cursor to the system wait cursor */ public static void showWaitCursor() { GUIUtils.invokeAndWait(new Runnable() { public void run() { GUIUtils.showWaitCursor(frame); } }); //GUIUtils.showWaitCursor(frame); } /** * Sets the application cursor to the system wait cursor * on the specified component. */ public static void showWaitCursor(final Component component) { GUIUtils.invokeAndWait(new Runnable() { public void run() { GUIUtils.showWaitCursor(component); } }); } /** * Sets the application cursor to the system normal cursor * on the specified component. */ public static void showNormalCursor(final Component component) { GUIUtils.invokeAndWait(new Runnable() { public void run() { GUIUtils.showNormalCursor(component); } }); } /** <p>Resets the tool bars. */ public static void resetToolBar(final boolean resetMenu) { SwingUtilities.invokeLater(new Runnable() { public void run() { toolBar.buildToolbars(true); ToolBarProperties.saveTools(); if (resetMenu) { initialiseViewToolsMenuItems(); } } }); } /** * Loads and returns the specified image with the specified name. * The default path to the image dir appended to the start of * the name is /org/executequery/images. * * @param name - the image file name to load * @return the loaded image */ public static ImageIcon loadImage(String name) { return IconUtilities.loadImage(IMAGE_PATH + name); } /** * Loads and returns the specified icon with the specified name. * The default path to the icon dir appended to the start of * the name is /org/executequery/icons. * * @param name - the icon file name to load * @return the loaded icon image */ public static ImageIcon loadIcon(String name) { return loadIcon(name, false); } /** * Loads and returns the specified icon with the specified name. * The default path to the icon dir appended to the start of * the name is /org/executequery/icons. * * @param name - the icon file name to load * @param store - whether to store the icon in the icon cache * for future use after loading * @return the loaded icon image */ public static ImageIcon loadIcon(String name, boolean store) { return IconUtilities.loadIcon(ICON_PATH + name, store); } /** * Returns the absolute icon resource path by appending * the package icon path to the specified icon file name. * * @param name - the icon file name * @return the absolute package path of the icon */ public static String getAbsoluteIconPath(String name) { return ICON_PATH + name; } /** * Sets the system display options and writes the * preferences to file if specified. * * @param whether to save the preferences to file */ public static void setDisplayOptions(boolean writeFile) { // apply these properties to relevant objects displayStatusBar(SystemProperties.getBooleanProperty( "user", "system.display.statusbar")); // set the menu's display options as retrieved above menuBar.setViewOptions(); // update the action shortcuts ActionBuilder.updateUserDefinedShortcuts( getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), SystemResources.getUserActionShortcuts()); } /** * Convenience method for consistent border colour. * * @return the system default border colour */ public static Color getDefaultBorderColour() { return UIManager.getColor("controlShadow"); } /** * Returns the docked component (non-central pane) with * the specified name. * * @param the name of the component * @return the panel component */ public static JPanel getDockedTabComponent(String key) { if (dockedTabComponents == null || dockedTabComponents.isEmpty() || !dockedTabComponents.containsKey(key)) { return null; } return dockedTabComponents.get(key); } /** * Initialises the docked tab view with the specified * property key. * * @param the property key of the panel to be initialised */ private static void initDockedTabView(String key) { if (dockedTabComponents.containsKey(key)) { return; } JPanel panel = null; // determine which panel to initialise if (key.equals(ConnectionsTreePanel.PROPERTY_KEY)) { panel = new ConnectionsTreePanel(); } else if (key.equals(DriversTreePanel.PROPERTY_KEY)) { panel = new DriversTreePanel(); } else if (key.equals(SystemPropertiesDockedTab.PROPERTY_KEY)) { panel = new SystemPropertiesDockedTab(); } else if (key.equals(SystemOutputPanel.PROPERTY_KEY)) { // init the logger // this method will add the output panel startLogger(); } else if (key.equals(KeywordsDockedPanel.PROPERTY_KEY)) { panel = new KeywordsDockedPanel(); } else if (key.equals(SQLStateCodesDockedPanel.PROPERTY_KEY)) { panel = new SQLStateCodesDockedPanel(); } if (panel != null) { dockedTabComponents.put(key, panel); } } /** * Returns the docked component (non-central pane) with * the specified name. If the option to display is set to * true, the component will be displayed in the default or * user preferred position. * * @param key - the property key of the component */ public static void ensureDockedTabVisible(String key) { JPanel panel = getDockedTabComponent(key); if (panel != null && panel instanceof DockedTabView) { DockedTabView _panel = (DockedTabView)panel; String title = _panel.getTitle(); // check if its visible already int position = getDockedComponentPosition(key); TabComponent tab = getTabComponent(position, title); if (tab == null) { // check if its minimised if (desktopMediator.isMinimised(position, title)) { desktopMediator.restore(position, title); } // otherwise add the component to the view else { addDockedTab(title, panel, position, true); layoutProperties.setDockedPaneVisible(key, true); SystemProperties.setBooleanProperty("user", key, true); } } else { // otherwise make sure its selected desktopMediator.setSelectedPane(position, title); } } else { // otherwise, initialise the tab initDockedTabView(key); ensureDockedTabVisible(key); // replay } } /** * Returns the user specified (or default) position for the * non-central pane docked component with the specified name. * * @param the key * @return the position (SwingConstants) */ public static int getDockedComponentPosition(String key) { int position = layoutProperties.getPosition(key); if (position == -1) { // default NORTH_WEST position position = SwingConstants.NORTH_WEST; } return position; } /** * Called to indicate that a docked tab view was selected. * * @param the property key */ public static void dockedTabComponentSelected(String key) { // update the system properties visible key SystemProperties.setBooleanProperty("user", key, true); // update the view menu item JPanel panel = getDockedTabComponent(key); if (panel != null && panel instanceof DockedTabView) { DockedTabView tab = (DockedTabView)panel; menuBar.setViewOption(tab.getMenuItemKey(), true); } // update properties to file updatePreferencesToFile(); } /** * Called to indicate that a docked tab view has closed. * * @param the property key
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -