📄 jextframe.java
字号:
/* * 05/25/2002 - 22:10:17 * * JextFrame.java - A text editor for Java * Copyright (C) 1999-2001 Romain Guy * Portions copyright (C) 1998-2000 Slava Pestov * romain.guy@jext.org * www.jext.org * * 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.jext;import java.io.File;import java.util.ArrayList;import java.util.List;import java.util.Iterator;import java.util.Random;import java.util.Vector;import java.util.HashMap;import java.awt.*;import java.awt.dnd.*;import java.awt.datatransfer.*;import java.awt.event.*;import javax.swing.*;import javax.swing.text.*;import javax.swing.border.*;import org.gjt.sp.jedit.gui.KeyEventWorkaround;import org.gjt.sp.jedit.syntax.SyntaxDocument;import org.gjt.sp.jedit.syntax.SyntaxStyle;import org.gjt.sp.jedit.syntax.Token;import org.gjt.sp.jedit.textarea.*;import org.jext.console.Console;import org.jext.event.JextEvent;import org.jext.event.JextListener;import org.jext.gui.JextButton;import org.jext.gui.JextHighlightButton;import org.jext.gui.JextToggleButton;import org.jext.gui.VoidComponent;import org.jext.gui.Dockable;import org.jext.menus.JextMenuBar;import org.jext.menus.JextRecentMenu;import org.jext.misc.AutoSave;import org.jext.misc.FindAccessory;import org.jext.misc.ProjectPanel;import org.jext.misc.SaveDialog;import org.jext.misc.VirtualFolders;import org.jext.misc.Workspaces;import org.jext.project.Project;import org.jext.project.ProjectManager;import org.jext.project.ProjectManagement;import org.jext.project.DefaultProjectManager;import org.jext.project.DefaultProjectManagement;import org.jext.scripting.dawn.DawnLogWindow;import org.jext.scripting.python.PythonLogWindow;import org.jext.scripting.AbstractLogWindow;import org.jext.search.Search;import org.jext.toolbar.JextToolBar;import org.jext.xinsert.XTree;import org.jext.xml.XBarReader;import org.jext.xml.XMenuReader;import com.jgoodies.uif_lite.component.Factory;import com.jgoodies.uif_lite.panel.SimpleInternalFrame;import com.jgoodies.plaf.plastic.theme.*;import com.jgoodies.plaf.HeaderStyle;import com.jgoodies.plaf.Options;/** * Jext is a fully featured, 100% Pure Java, text editor. It * has been mainly designed for programmers, and provides also * very useful functions for them (syntax colorization, methods * seeker, auto indentation...). * @author Romain Guy */public class JextFrame extends JFrame{ ////////////////////////////////////////////////////////////////////////////////////////////// // LOCAL PRIVATE FIELDS ////////////////////////////////////////////////////////////////////////////////////////////// // GUI private members private JextToolBar toolBar; private JMenu pluginsMenu; private JextRecentMenu menuRecent; private int _dividerSize; // GUI components private XTree xtree; private Console console; private AbstractLogWindow dawnLogWindow; private AbstractLogWindow pythonLogWindow; private Workspaces workspaces; private VirtualFolders virtualFolders; // misc private AutoSave auto; private JFileChooser chooser; private FindAccessory accessory; // gui private JPanel centerPane; private JextTabbedPane textAreasPane; private JSplitPane split; private JTabbedPane hTabbedPane, vTabbedPane; private JSplitPane splitter; private JSplitPane textAreaSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT); private SimpleInternalFrame rightFrame; private SimpleInternalFrame leftFrame; private SimpleInternalFrame consolesFrame; // splitted edition private JextTextArea splittedTextArea; // labels private JLabel message = new JLabel(); private JLabel status = new JLabel("v" + Jext.RELEASE + " - (C)1999-2001 Romain Guy - www.jext.org"); // misc datas private int waitCount, batchMode; private ArrayList jextListeners = new ArrayList(); private ArrayList transientItems = new ArrayList(); private boolean transientSwitch; private KeyListener keyEventInterceptor; private InputHandler inputHandler; private ProjectManager currentProjectMgr; private HashMap projectMgmts; private ProjectManagement defaultProjectMgmt; ////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC AND PRIVATE NON-STATIC METHODS ////////////////////////////////////////////////////////////////////////////////////////////// /** * Returns the tabbed pane in which text areas are put. */ public JextTabbedPane getTabbedPane() { return textAreasPane; } /** * Returns the XTree's tabbed pane. */ public JTabbedPane getVerticalTabbedPane() { return vTabbedPane; } /** * Returns the console's tabbed pane. */ public JTabbedPane getHorizontalTabbedPane() { return hTabbedPane; } /** * Some external functions may need to manipulate the tree. * The XTree itself needs to get other instances to reload'em. * @return Current <code>XTree</code> used by Jext */ public XTree getXTree() { return xtree; } /** * Returns the Virtual Folders panel. */ public VirtualFolders getVirtualFolders() { return virtualFolders; } /** * Returns the Workspaces panel. */ public Workspaces getWorkspaces() { return workspaces; } /** * Some external functions may need to manipulate the console. * The Scripting system, for instance, need it to launch OS * specific commands. * @return Current <code>Console</code> used by Jext */ public Console getConsole() { if (console == null) { Console c = new Console(this); c.setPromptPattern(Jext.getProperty("console.prompt")); c.displayPrompt(); return c; } return console; } /** * The log window is used by scripting actions. * @return Current <code>DawnLogWindow</code> window used by Jext */ public AbstractLogWindow getDawnLogWindow() { if (dawnLogWindow == null) //dawnLogWindow = new DawnLogWindow(this); dawnLogWindow = (AbstractLogWindow) DawnLogWindow.getInstance(this).getFrame(); return dawnLogWindow; } /** * The log window is used by scripting actions. * @return Current <code>PythonLogWindow</code> window used by Jext */ public AbstractLogWindow getPythonLogWindow() { if (pythonLogWindow == null) //pythonLogWindow = new PythonLogWindow(this); pythonLogWindow = (AbstractLogWindow) PythonLogWindow.getInstance(this).getFrame(); return pythonLogWindow; } /** * Returns the dock holding the current Dawn LogWindow */ public Dockable getDawnDock() { return getDawnLogWindow().getContainingDock(); } /** * Returns the dock holding the current Python LogWindow */ public Dockable getPythonDock() { return getPythonLogWindow().getContainingDock(); } /** * Return the JFileChooser object used to open and save documents * By maintaining a single file chooser for each instance of Jext * instead of creating and disposing one each time a file is opened * or saved, we should see a drastic improvement in memory usage * @param mode the mode to open the dialog in * @return the file chooser * @author Ian D. Stewart <idstewart@softhome.net> & Romain Guy */ public JFileChooser getFileChooser(int mode) { if (chooser == null) { chooser = new JFileChooser(); accessory = new FindAccessory(chooser); } switch (mode) { case Utilities.OPEN: default: chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle(Jext.getProperty("filechooser.open.title")); if (chooser.getAccessory() == null) chooser.setAccessory(accessory); if (chooser.getChoosableFileFilters().length > 1) break; ModeFileFilter filter; ModeFileFilter selectedFilter = null; String _mode = getTextArea().getColorizingMode(); for (int i = 0; i < Jext.modesFileFilters.size(); i++) { filter = (ModeFileFilter) Jext.modesFileFilters.get(i); chooser.addChoosableFileFilter(filter); if (selectedFilter == null && _mode.equals(filter.getModeName())) selectedFilter = filter; } chooser.setFileFilter(selectedFilter == null ? chooser.getAcceptAllFileFilter() : selectedFilter); break; case Utilities.SCRIPT: chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle(Jext.getProperty("filechooser.script.title")); chooser.setAccessory(accessory); chooser.resetChoosableFileFilters(); break; case Utilities.SAVE: chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setDialogTitle(Jext.getProperty("filechooser.save.title")); chooser.setAccessory(null); chooser.resetChoosableFileFilters(); break; } chooser.setSelectedFile(new File("")); chooser.rescanCurrentDirectory(); return chooser; } /** * Set batch mode state. Batch mode must be set when several operations are * made over many text areas. It avoids tools like JBrowse to perform tasks. */ public void setBatchMode(boolean on) { if (on && batchMode == 0) fireJextEvent(JextEvent.BATCH_MODE_SET); else if (!on && batchMode == 1) fireJextEvent(JextEvent.BATCH_MODE_UNSET); batchMode += (on ? 1 : -1); if (batchMode < 0) batchMode = 0; } /** * Returns batch mode state. */ public boolean getBatchMode() { return batchMode > 0; } /** * Returns the listener that will handle all key events in this * view, if any. */ public final KeyListener getKeyEventInterceptor() { return keyEventInterceptor; } /** * Sets the listener that will handle all key events in this * view. For example, the complete word command uses this so * that all key events are passed to the word list popup while * it is visible. * @param comp The component */ public void setKeyEventInterceptor(KeyListener listener) { this.keyEventInterceptor = listener; } /** * Records the componence of the GUI for later restauration. * Called after basic initialization of the GUI. */ public void freeze() { // getJextMenuBar().freeze(); transientSwitch = true; getJextToolBar().freeze(); } /** * Called after adding a new item to the GUI */ public void itemAdded(Component comp) { if (transientSwitch == true) transientItems.add(comp); } /** * Restores the basic GUI. */ public void reset() { getJextToolBar().reset(); for (int i = 0; i < transientItems.size(); i++) { Component comp = (Component) transientItems.get(i); if (comp != null) { Container parent = comp.getParent(); if (parent != null) parent.remove(comp); } } if (getJextMenuBar() != null) getJextMenuBar().reset(); } /** * Sets the menu to be used as 'plugins'. * @param menu The <code>JMenu</code> used as plugins menu */ public void setPluginsMenu(JMenu menu) { pluginsMenu = menu; } /** * Fires a Jext event. * @param type Event type */ public void fireJextEvent(int type) { JextEvent evt = new JextEvent(this, type); Iterator iterator = jextListeners.iterator(); while (iterator.hasNext()) ((JextListener) iterator.next()).jextEventFired(evt); } /** * Fires a Jext event. * @param textArea Related event text area * @param type Event type */ public void fireJextEvent(JextTextArea textArea, int type) { JextEvent evt = new JextEvent(this, textArea, type); Iterator iterator = jextListeners.iterator(); while (iterator.hasNext()) try { ((JextListener) iterator.next()).jextEventFired(evt); } catch (Throwable t) { t.printStackTrace(); } } /** * Removes all the listeners associated with this instance. */ public void removeAllJextListeners() { jextListeners.clear(); } /** * Adds a propertiesL listener to this class. * @param l The <code>JextListener</code> to add */ public void addJextListener(JextListener l) { jextListeners.add(l); } /** * Remove a specified jext listener from the list. * @param l The listener to remove */ public void removeJextListener(JextListener l) { jextListeners.remove(l); } /** * Load options states from the properties file. * Moreover, it sets up the corresponding internal * variables and menu items. */ public void loadProperties() { loadProperties(true); } public void loadProperties(boolean triggerPanes) { if (Jext.getBooleanProperty("editor.autoSave")) startAutoSave();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -