📄 jextframe.java
字号:
updateStatus(textArea); } /** * When the text change, we warn the user while displaying a text * in the lower right corner. * @param textArea The text area which was modified */ public void setChanged(JextTextArea textArea) { /*if (!textArea.isDirty()) {*/ //textArea.setDirty(); //checks moved to JextTextArea textAreasPane.setDirtyIcon(textArea); setStatus(textArea); //} } /** * When the user saves its text, we have to reset modifications done * by <code>setChanged()</code>. */ public void setSaved(JextTextArea textArea) { /*if (textArea.isDirty()) {*/ //textArea.clean() textAreasPane.setCleanIcon(textArea); message.setText(""); //} } /** * Close current window after having checked dirty state * of each opened file. It should be called only by {@link Jext#closeToQuit(JextFrame)}, * which also closes Jext if needed, handling all the background server related issues. */ public void closeToQuit() { //new SaveDialog(this, SaveDialog.CLOSE_WINDOW); workspaces.closeAllWorkspaces(); Iterator it = projectMgmts.values().iterator(); while (it.hasNext()) { ProjectManager pm = ((ProjectManagement)(it.next())).getProjectManager(); Project[] project = pm.getProjects(); for (int i = 0; i < project.length; i++) { pm.saveProject(project[i]); }//end for i... }//end while more project managements... } /** * Destroys current window and close JVM. */ public void closeWindow() { closeWindow(true); } /** * Destroy current window and close JVM if necessary. However the correct way to close a JextFrame * (as of Jext3.2pre3) is to call {@link Jext#closeToQuit(JextFrame)} * @param jvm If true, we terminate the JVM * @deprecated Use closeWindow(), since the JVM is not closed anyway. */ public void closeWindow(boolean jvm) { //fireJextEvent((Jext.getWindowsCount() == 1) ? JextEvent.KILLING_JEXT : JextEvent.CLOSING_WINDOW); //fireJextEvent(JextEvent.CLOSING_WINDOW); //events are handled by Jext.closeToQuit. But so they are dispatched before the Save on exit dialog. //Will work? if (console != null) console.stop(); stopAutoSave(); removeAllJextListeners(); Jext.getInstances().remove(this); this.dispose(); /*if (console != null && Jext.getBooleanProperty("console.save")) console.save(); GUIUtilities.saveGeometry(this, "jext"); Jext.saveXMLProps("Jext v" + Jext.RELEASE + " b" + Jext.BUILD);*/ //cleanMemory(); /* // real exit is done by the calling Jext.closeToQuit(); // if all windows have been closed and we are not running the jext background server, and we // have been asked to do, then we actually close Jext. if (Jext.getWindowsCount() == 0 && ! Jext.isRunningBg() && jvm) Jext.finalCleanupBeforeExit();*/ } /* so Jext.java can save the console */ /*friendly*/ void saveConsole() { if (console != null && Jext.getBooleanProperty("console.save")) console.save(); } // helps GC to clean up memory a bit /*friendly*/ void cleanMemory() { workspaces.clear(); workspaces = null; transientItems.clear(); toolBar = null; pluginsMenu = null; menuRecent = null; xtree = null; console = null; auto = null; chooser = null; accessory = null; centerPane = null; textAreaSplitter = split = splitter = null; vTabbedPane = hTabbedPane = null; textAreasPane = null; splittedTextArea = null; inputHandler = null; transientItems = jextListeners = null; keyEventInterceptor = null; System.gc(); } /** * Check if content of text area has to be saved or not. * @return true if user want to close the area, false otherwise */ public boolean checkContent(JextTextArea textArea) { if (textArea.isDirty() && !textArea.isEmpty()) { textAreasPane.setSelectedComponent(textArea); String[] args = { textArea.getName() }; int response = JOptionPane.showConfirmDialog(this, Jext.getProperty("general.save.question", args), Jext.getProperty("general.save.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (response) { case 0: textArea.saveContent(); break; case 1: break; case 2: return false; } } return true; } /** * Sets the menu to be used as 'recent'. * @param menu The <code>JMenu</code> used as recent menu */ public void setRecentMenu(JextRecentMenu menu) { menuRecent = menu; reloadRecent(); } /** * Called by the RecentListener to reload the recent menu. */ public void reloadRecent() { menuRecent.createRecent(); } /** * Clears recent menu. */ public void removeRecent() { menuRecent.removeRecent(); } /** * Saves a file as a recent. */ public void saveRecent(String file) { menuRecent.saveRecent(file); } /** * Shows the wait cursor. */ public void showWaitCursor() { if (waitCount++ == 0) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); setCursor(cursor); JextTextArea[] textAreas = getTextAreas(); for (int i = 0; i < textAreas.length; i++) textAreas[i].getPainter().setCursor(cursor); } } /** * Hides the wait cursor. */ public void hideWaitCursor() { if (waitCount > 0) waitCount--; if (waitCount == 0) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); setCursor(cursor); cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR); JextTextArea[] textAreas = getTextAreas(); for(int i = 0; i < textAreas.length; i++) textAreas[i].getPainter().setCursor(cursor); } }/** * Selects the specified form of project management; returns <CODE>true</CODE> * if successful. * @return <CODE>boolean</CODE>. */ public boolean selectProjectManagement(String name) { boolean success = (projectMgmts.containsKey(name) && projectMgmts.get(name) != null); if (success) { ProjectManager newPM = ((ProjectManagement)(projectMgmts.get(name))).getProjectManager(); if (success = (newPM != null)) { if (currentProjectMgr != newPM) { if (currentProjectMgr != null) { vTabbedPane.remove(currentProjectMgr.getUI()); }//end if there is an old ProjectManager currentProjectMgr = newPM; if (currentProjectMgr.getUI() != null) { vTabbedPane.add(Jext.getProperty("vTabbedPane.project"), newPM.getUI()); }//end if the new ProjectManager has a UI }//end if the new one is different from the current one... }//end if still okay... }//end if such a name... return success; }//end selectProjectManagement/** * Returns the current <CODE>ProjectManager</CODE>. * @return <CODE>ProjectManager</CODE>. */ public ProjectManager getProjectManager() { return currentProjectMgr; }//end getProjectManager /** * Set Jext's toolbar. SHOULD NOT BE CALLED BY AN * EXTERNAL PLUGIN ! * @param bar The new toolbar */ public void setJextToolBar(JextToolBar bar) { bar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); toolBar = bar; } /** * Get Jext's toolbar */ public JextToolBar getJextToolBar() { return toolBar; } /** * Returns Jext menu bar. */ public JextMenuBar getJextMenuBar() { return (JextMenuBar) getJMenuBar(); } /** * Returns current selected text area. */ public JextTextArea getTextArea() { if (splittedTextArea != null && splittedTextArea.hasFocus()) return splittedTextArea; return getNSTextArea(); } /** * Returns current selected text area, excluding the splitted area. */ public JextTextArea getNSTextArea() { Component c = textAreasPane.getSelectedComponent(); if (c instanceof JextTextArea) { return (JextTextArea) c; } else { for (int i = textAreasPane.getTabCount() - 1; i >= 0; i--) { if ((c = textAreasPane.getComponentAt(i)) instanceof JextTextArea) return (JextTextArea) c; } } return null; } /** * Returns an array containing all the text areas opened * in current window. */ public JextTextArea[] getTextAreas() { Component c; Vector _v = new Vector(textAreasPane.getTabCount()); for (int i = 0; i < textAreasPane.getTabCount(); i++) { if ((c = textAreasPane.getComponentAt(i)) instanceof JextTextArea) _v.addElement(c); } JextTextArea[] areas = new JextTextArea[_v.size()]; _v.copyInto(areas); _v = null; return areas; } /** * Close a specified file and checks if file is dirty first. * @param textArea The file to close */ public void close(JextTextArea textArea) { close(textArea, true); } /** * Closes a specified file. * @param textArea The file to close * @param checkContent If true, Jext check if text area is dirty before saving */ public void close(JextTextArea textArea, boolean checkContent) { if (checkContent && !checkContent(textArea)) return; int index = textAreasPane.indexOfComponent(textArea); if (index != -1) { workspaces.removeFile(textArea); textAreasPane.removeTabAt(index); textArea.getPainter().setDropTarget(null); fireJextEvent(textArea, JextEvent.TEXT_AREA_CLOSED); if (getTextAreas().length == 0) createFile(); // saves memory and helps GC textArea = null; } } /** * Close all the opened files. */ public void closeAll() { SaveDialog saveDialog = new SaveDialog(this, SaveDialog.CLOSE_TEXT_AREAS_ONLY); ////////////////////////////////////////////// // JextTextArea[] textAreas = getTextAreas(); // for (int i = 0; i < textAreas.length; i++) // close(textAreas[i]); } /** * Opens a file in a new tabbed pane. In case it is already opened, we ask user if * he wants to reload it or open it in a new pane. */ public JextTextArea open(String file) { return open(file, true); } /** * Opens a file in a new tabbed pane. In case it is already opened, we ask user if * he wants to reload it or open it in a new pane. * @param addToRecentList If false, the file name is not added to recent list */ public JextTextArea open(String file, boolean addToRecentList) { if (file == null) return null; if (!(new File(file)).exists()) { String[] args = { file }; Utilities.showError(Jext.getProperty("textarea.file.notfound", args)); return null; } String _file; JextTextArea textArea; JextTextArea[] areas = getTextAreas();out: for (int i = 0; i < areas.length; i++) { textArea = areas[i]; if (textArea.isNew()) continue; _file = textArea.getCurrentFile(); if (_file != null && _file.equals(file)) { int response = JOptionPane.showConfirmDialog(this, Jext.getProperty("textarea.file.opened.msg", new Object[] { _file }), Jext.getProperty("textarea.file.opened.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (response) { case 0: textArea.open(_file, addToRecentList); textAreasPane.setSelectedComponent(textArea); return textArea; case 1: break out; default: return null; } } } textArea = createTextArea(); textArea.open(file, addToRecentList); addTextAreaInTabbedPane(textArea); JextTextArea firstTextArea = (JextTextArea) textAreasPane.getComponentAt(0); if (textAreasPane.getTabCount() == 2 && firstTextArea.isNew() && firstTextArea.getLength() == 0) close(firstTextArea); return textArea; } public JextTextArea openForLoading(String file) { if (file == null) return null; if (!(new File(file)).exists()) { String[] args = { file }; Utilities.showError(Jext.getProperty("textarea.file.notfound", args)); return null; } JextTextArea textArea = new JextTextArea(this); new DropTarget(textArea.getPainter(), new DnDHandler()); textArea.setDocument(new SyntaxDocument()); textArea.open(file, false); addTextAreaInTabbedPane(textArea); return textArea; } // creates a new text area: it constructs it, gives it an // input handler, sets default document and finally loads // its properties from users settings
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -