📄 guiutilities.java
字号:
} } } } public static final void shuttingDown() { Log.info("System exiting..."); /* JPanel panel = getDockedTabComponent(SystemOutputPanel.PROPERTY_KEY); if (panel != null) { ((SystemOutputPanel)panel).shuttingDown(); }*/ } /** * Sets the title for the specified component to the newTitle * within central tab pane. * * @param the component to be renamed * @the new title to set */ public static void setTabTitleForComponent(JPanel contents, String newTitle) { setTabTitleForComponent(SwingUtilities.CENTER, contents, newTitle); } /** * Sets the tool tip for the specified component to toolTipText. * * @param the tab pane position * @param the component where the tool tip should be set * @param the tool tip text to be displayed in the tab */ public static void setToolTipTextForComponent(int position, Component component, String toolTipText) { desktopMediator.setToolTipTextForComponent(position, component, toolTipText); } /** * Sets the title for the specified component to toolTipText. * * @param the tab pane position * @param the component where the tool tip should be set * @param the title to be displayed in the tab */ public static void setTabTitleForComponent(int position, Component component, String title) { desktopMediator.setTabTitleForComponent(position, component, title); } /** * Sets the tool tip for the specified component within the * central main pane to title. * * @param the component where the tool tip should be set * @param the tool tip text to be displayed in the tab */ public static void setToolTipTextForComponent(Component component, String toolTipText) { setToolTipTextForComponent(SwingConstants.CENTER, component, toolTipText); } /** * Sets the title for the specified component within the * central main pane to toolTipText. * * @param the component where the tool tip should be set * @param the title text to be displayed in the tab */ public static void setTabTitleForComponent(Component component, String title) { setTabTitleForComponent(SwingConstants.CENTER, component, title); } /** * Attempts to locate the actionable dialog that is * currently open and brings it to the front. */ public static void acionableDialogToFront() { if (register.getOpenDialogCount() > 0) { List<JDialog> list = register.getOpenDialogs(); for (int i = 0, k = list.size(); i < k; i++) { JDialog dialog = list.get(i); // check if its a BaseDialog if (dialog instanceof BaseDialog) { // check the content panel JPanel panel = ((BaseDialog)dialog).getConentPanel(); if (panel instanceof ActiveComponent) { dialog.toFront(); } } else if (dialog instanceof ActiveComponent) { dialog.toFront(); } } } } /** * Checks if an actionable dialog is currently open. * * @return true | false */ public static boolean isActionableDialogOpen() { if (register.getOpenDialogCount() > 0) { List<JDialog> list = register.getOpenDialogs(); for (int i = 0, k = list.size(); i < k; i++) { JDialog dialog = list.get(i); // check if its a BaseDialog if (dialog instanceof BaseDialog) { // check the content panel JPanel panel = ((BaseDialog)dialog).getConentPanel(); if (panel instanceof ActiveComponent) { return true; } } else if (dialog instanceof ActiveComponent) { return true; } } } return false; } public static boolean hasValidSaveFunction() { // check the open panels register first if (register.getOpenPanelCount() > 0) { List<PanelCacheObject> list = register.getOpenPanels(); for (int i = 0, k = list.size(); i < k; i++) { Component component = list.get(i).getComponent(); if (component instanceof SaveFunction) { SaveFunction saveFunction = (SaveFunction)component; if (saveFunction.promptToSave()) { return true; } } } } // check the open dialogs if (register.getOpenDialogCount() > 0) { List<JDialog> list = register.getOpenDialogs(); for (int i = 0, k = list.size(); i < k; i++) { JDialog dialog = list.get(i); if (dialog instanceof SaveFunction) { SaveFunction saveFunction = (SaveFunction)dialog; if (saveFunction.promptToSave()) { return true; } } } } return false; /* // if we have none return false if (desktopMediator.getTabCount(SwingConstants.CENTER) == 0) { return false; } List<TabComponent> tabs = desktopMediator.getOpenTabs(SwingConstants.CENTER); for (int i = 0, k = tabs.size(); i < k; i++) { TabComponent tab = tabs.get(i); Component component = tab.getComponent(); if (component instanceof SaveFunction) { SaveFunction saveFunction = (SaveFunction)component; if (saveFunction.promptToSave()) { return true; } } } return false; /* JInternalFrame[] _frames = getAllOpenFrames(); for (int i = 0; i < _frames.length; i++) { if (_frames[i] instanceof BaseInternalFrame) { BaseInternalFrame frame = (BaseInternalFrame)_frames[i]; JPanel contents = frame.getFrameContents(); if (contents instanceof SaveFunction) { SaveFunction saveFunction = (SaveFunction)contents; if (saveFunction.promptToSave()) { validSaves = true; break; } } } } return validSaves; */ } /** * Checks if the panel with the specified title is open. * * @return true | false */ public static boolean isPanelOpen(String title) { return register.isPanelOpen(title); //return getCentralPane(title) != null; //return getOpenFrame(title) != null; } /** * Checks if the dialog with the specified title is open. * * @return true | false */ public static boolean isDialogOpen(String title) { return register.isDialogOpen(title); } /** * Checks if the dialog with the specified title is open. * * @return true | false */ public static void setSelectedDialog(String title) { JDialog dialog = register.getOpenDialog(title); if (dialog != null) { dialog.toFront(); } } public static JPanel getOpenFrame(String title) { return (JPanel)register.getOpenPanel(title); } /** * Resets (clears) the system output log. */ private static void resetSystemOutputLog() { JPanel panel = getDockedTabComponent(SystemOutputPanel.PROPERTY_KEY); if (panel != null) { ((SystemOutputPanel)panel).resetSystemLog(); } } public static void resetSystemLog() { int yesno = displayConfirmDialog( "Are you sure you want to reset the system activity log?"); if (yesno == JOptionPane.YES_OPTION) { resetSystemOutputLog(); } } public static void resetImportLog() { int yesno = displayConfirmDialog( "Are you sure you want to reset the data import log?"); if (yesno == JOptionPane.YES_OPTION) { SystemResources.resetLog("import.log"); } } public static void resetExportLog() { int yesno = displayConfirmDialog( "Are you sure you want to reset the data export log?"); if (yesno == JOptionPane.YES_OPTION) { SystemResources.resetLog("export.log"); } } public static void resetAllLogs() { int yesno = displayConfirmDialog( "Are you sure you want to reset ALL system logs?"); if (yesno == JOptionPane.YES_OPTION) { resetSystemOutputLog(); SystemResources.resetLog("export.log"); SystemResources.resetLog("import.log"); } } public static boolean saveOpenChanges(SaveFunction saveFunction) { int result = displayConfirmCancelDialog( "Do you wish to save changes to " + saveFunction.getDisplayName() + "?"); if (result == JOptionPane.YES_OPTION) { int saved = saveFunction.save(false); if (saved != SaveFunction.SAVE_COMPLETE) { return false; } } else if (result == JOptionPane.CANCEL_OPTION) { return false; } return true; } /** * Displays the error dialog displaying the stack trace from a * throws/caught exception. * * @param message - the error message to display * @param e - the throwable */ public static void displayExceptionErrorDialog( final String message, final Throwable e) { GUIUtils.invokeAndWait(new Runnable() { public void run() { new ExceptionErrorDialog(frame, message, e); } }); } // ------------------------------------------------------- // ------ Helper methods for various option dialogs ------ // ------------------------------------------------------- // These have been revised to use JDialog as the wrapper to // ensure the dialog is centered within the dektop pane and not // within the entire screen as you get with JOptionPane.showXXX() public static final void displayInformationMessage(String message) { GUIUtils.displayInformationMessage(frame, message); } public static final void displayWarningMessage(String message) { GUIUtils.displayWarningMessage(frame, message); } public static final void displayErrorMessage(String message) { GUIUtils.displayErrorMessage(frame, message); } public static final String displayInputMessage(String title, String message) { return GUIUtils.displayInputMessage(frame, title, message); } public static final int displayConfirmCancelErrorMessage(String message) { return GUIUtils.displayConfirmCancelErrorMessage(frame, message); } public static final int displayYesNoDialog(String message, String title) { return GUIUtils.displayYesNoDialog(frame, message, title); } public static final int displayConfirmCancelDialog(String message) { return GUIUtils.displayConfirmCancelDialog(frame, message); } public static final int displayConfirmDialog(String message) { return GUIUtils.displayConfirmDialog(frame, message); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -