📄 guiutilities.java
字号:
// ------------------------------------------------------- /** <p>Retrieves the parent frame of the application. * * @return the parent frame */ public static Frame getParentFrame() { return frame; } /** * Selects the next tab from the current selection. */ public static void selectNextTab() { desktopMediator.selectNextTab(); } /** * Selects the previous tab from the current selection. */ public static void selectPreviousTab() { desktopMediator.selectPreviousTab(); } public static void setMaximumOpenEditors(int _maxOpenEditors) { maxOpenEditors = _maxOpenEditors; } /** <p>Builds and sets the main tool bar. */ public static void createToolBar() { toolBar = new ToolBarManager(); frame.add(toolBar.getToolBarBasePanel(), BorderLayout.NORTH); } /** * <p>Determines whether upon selection of the print * action, the currently open and in focus frame does * have a printable area - is an instance of a <code> * BrowserPanel</code> or <code>TextEditor</code>. * * @return whether printing may be performed from the * open frame */ public static boolean canPrint() { // check the dialog in focus first if (focusedDialog != null) { if (focusedDialog instanceof PrintFunction) { return ((PrintFunction)focusedDialog).canPrint(); } } Object object = getSelectedCentralPane(); if (!(object instanceof PrintFunction)) { return false; } PrintFunction printFunction = (PrintFunction)object; return printFunction.canPrint(); } /** <p>Returns the <code>PrintFunction</code> object * from the currently in-focus frame. If the in-focus * frame is not an instance of <code>PrintFunction</code>, * <code>null</code> is returned. * * @return the in-focus <code>PrintFunction</code> object */ public static PrintFunction getPrintableInFocus() { // check the open dialogs first 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.isModal() || dialog.isFocused()) { if (dialog instanceof BaseDialog) { // check the content panel JPanel panel = ((BaseDialog)dialog).getConentPanel(); if (panel instanceof PrintFunction) { return (PrintFunction)panel; } } else if (dialog instanceof PrintFunction) { return (PrintFunction)dialog; } } } } // check the open panels register if (register.getOpenPanelCount() > 0) { Component component = register.getSelectedComponent(); //Log.debug("test print component: "+ component.getClass().getName()); if (component instanceof PrintFunction) { return (PrintFunction)component; } } return null;/* // check the dialog in focus first if (focusedDialog != null) { if (focusedDialog instanceof PrintFunction) { return (PrintFunction)focusedDialog; } } Object object = getSelectedCentralPane(); if (object instanceof PrintFunction) { return (PrintFunction)object; } else { return null; } */ } /** * Sets the selected tab in the central pane as the tab * component with the specified name. * * @param the name of the tab to be selected in the central pane */ public static void setSelectedCentralPane(String name) { desktopMediator.setSelectedPane(SwingConstants.CENTER, name); } public static JPanel getCentralPane(String name) { return (JPanel)register.getOpenPanel(name); /* TabComponent tabComponent = desktopMediator.getTabComponent(SwingConstants.CENTER, name); if (tabComponent != null) { return ((JPanel)tabComponent.getComponent()); } */ } /** * Returns the tab component with the specified name at * the specified position within the tab structure. * * @param the position (SwingContants) * @name the panel name/title */ public static TabComponent getTabComponent(int position, String name) { return desktopMediator.getTabComponent(position, name); } public static JPanel getSelectedCentralPane(String name) { return (JPanel)register.getSelectedComponent(); /* TabComponent tabComponent = desktopMediator.getSelectedComponent(SwingConstants.CENTER); //JInternalFrame frame = desktop.getSelectedFrame(); if (tabComponent != null) { // if its a name check if (name != null) { if (tabComponent.getTitle().startsWith(name)) { return (JPanel)tabComponent.getComponent(); //return ((BaseInternalFrame)frame).getFrameContents(); } } return (JPanel)tabComponent.getComponent(); } return null; */ } /** * Registers the specified dialog with the cache. * * @param the dialog to be registered */ public static void registerDialog(JDialog dialog) { register.addDialog(dialog); } /** * Registers the specified dialog with the cache. * * @param the dialog to be registered */ public static void deregisterDialog(JDialog dialog) { register.removeDialog(dialog); } public static void setFocusedDialog(JDialog _focusedDialog) { focusedDialog = _focusedDialog; } public static void removeFocusedDialog(JDialog _focusedDialog) { if (focusedDialog == _focusedDialog) { focusedDialog = null; } } /** * Retrieves the <code>TextEditor</code> instance * that currently has focus or NULL if none exists. * * @return that instance of <code>TeTextEditorcode> */ public static TextEditor getTextEditorInFocus() { // check the open dialogs first 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 focused or not modal if (!dialog.isModal() || dialog.isFocused()) { // check if its a base dialog if (dialog instanceof BaseDialog) { // check the content panel JPanel panel = ((BaseDialog)dialog).getConentPanel(); if (panel instanceof TextEditor) { return (TextEditor)panel; } else if (panel instanceof TextEditorContainer) { return ((TextEditorContainer)panel).getTextEditor(); } } else if (dialog instanceof TextEditor) { return (TextEditor)dialog; } else if (dialog instanceof TextEditorContainer) { return ((TextEditorContainer)dialog).getTextEditor(); } } } } // check the open panels register if (register.getOpenPanelCount() > 0) { Component component = register.getSelectedComponent(); if (component instanceof TextEditor) { return (TextEditor)component; } else if (component instanceof TextEditorContainer) { return ((TextEditorContainer)component).getTextEditor(); } } return null; } /** <p>Retrieves the contents of the in-focus * internal frame as a <code>JPanel</code>. * * @return the panel in focus */ public static JPanel getSelectedCentralPane() { return getSelectedCentralPane(null); } /** <p>Retrieves the <code>SaveFunction</code> in focus. * * @return the <code>SaveFunction</code> in focus */ public static SaveFunction getSaveFunctionInFocus() { // check the open dialogs first 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 focused // TODO: try a focus lost on the dialog ????????????????? if (!dialog.isModal() || dialog.isFocused()) { // check if its a base dialog if (dialog instanceof BaseDialog) { // check the content panel JPanel panel = ((BaseDialog)dialog).getConentPanel(); if (panel instanceof SaveFunction) { return (SaveFunction)panel; } } else if (dialog instanceof SaveFunction) { return (SaveFunction)dialog; } } } } // check the open panels register if (register.getOpenPanelCount() > 0) { Component component = register.getSelectedComponent(); if (component instanceof SaveFunction) { return (SaveFunction)component; } } return null; } public static UndoableComponent getUndoableInFocus() { // check the open dialogs first 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 focused if (dialog.isFocused()) { if (dialog instanceof UndoableComponent) { return (UndoableComponent)dialog; } } } } // check the open panels register if (register.getOpenPanelCount() > 0) { Component component = register.getSelectedComponent(); if (component instanceof UndoableComponent) { return (UndoableComponent)component; } } return null; /* // check the dialog in focus first if (focusedDialog != null) { if (focusedDialog instanceof UndoableComponent) { return (UndoableComponent)focusedDialog; } } else { JPanel panel = getSelectedCentralPane(); if (panel instanceof UndoableComponent) { return (UndoableComponent)panel; } else { return null; } } return null; */ } public static void registerUndoRedoComponent(UndoableComponent undoable) { BaseActionCommand undo = (BaseActionCommand)ActionBuilder.get("undo-command"); BaseActionCommand redo = (BaseActionCommand)ActionBuilder.get("redo-command"); if (undoable == null) { undo.setEnabled(false); redo.setEnabled(false); } UndoCommand _undo = (UndoCommand)undo.getCommand(); RedoCommand _redo = (RedoCommand)redo.getCommand(); _undo.setUndoableComponent(undoable); _redo.setUndoableComponent(undoable); } /** <p>Retrieves the applications <code>InputMap</code>. * * @return the <code>InputMap</code> */ public static InputMap getInputMap(int condition) {// return desktop.getDesktopInputMap(condition);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -