⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jext.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * 22:13 09/04/2003 * * Jext.java - A text editor for Java * Copyright (C) 1999-2003 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.net.*;import java.lang.reflect.Method;import java.io.*;import java.text.*;import java.util.*;import java.util.zip.*;import java.awt.Toolkit;import java.awt.Window;import javax.swing.UIManager;import javax.swing.plaf.metal.MetalLookAndFeel;import org.gjt.sp.jedit.textarea.DefaultInputHandler;import org.gjt.sp.jedit.textarea.TextUtilities;import org.jext.actions.*;import org.jext.gui.*;import org.jext.event.JextEvent;import org.jext.misc.TabSwitcher;import org.jext.misc.VersionCheck;import org.jext.oneclick.*;import org.jext.scripting.dawn.Run;import org.jext.search.Search;import org.jext.textarea.*;import org.jext.xml.OneClickActionsReader;import org.jext.xml.PyActionsReader;import org.jext.xml.XPropertiesReader;import org.python.util.PythonInterpreter;/** * 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, auto * indentation...). * @author Romain Guy * @version 5.0 */public class Jext{  //////////////////////////////////////////////////////////////////////////////////////////////  // PUBLIC CONSTANTS  //////////////////////////////////////////////////////////////////////////////////////////////  /* If you change any of the final values here, you'll need to recompile every class that uses them.   * So some lost their "final" at some point, but mustn't be modified anyway.   */  /** Current Jext's release. */  public static String RELEASE = "5.0 <Karsten/Tiger>";  /**   * Last Jext's build number. It's used actually only for plugin dependencies, so   * don't change it for simple bug-fix which don't bump the release number.*/  public static String BUILD = "05.00.01.00";  /** If true, Jext will delete user settings if this release is newer */  public static boolean DELETE_OLD_SETTINGS = true;  /** Debug mode(not final to avoid it being included in other .class files) */  public static boolean DEBUG = false;  /** Available new lines characters */  public static final String[] NEW_LINE = { "\r", "\n", "\r\n" };  /** Settings directory. */  public static final String SETTINGS_DIRECTORY = System.getProperty("user.home") +                                                  File.separator + ".jext" + File.separator;  /** Jext home directory. */  public static final String JEXT_HOME = System.getProperty("user.dir");  /** Jext server base port number. Used to load all Jext instances with only one JVM. **/  public static final int JEXT_SERVER_PORT = 49152;  //////////////////////////////////////////////////////////////////////////////////////////////  // BEGINNING OF STATIC PART  //////////////////////////////////////////////////////////////////////////////////////////////  // STATIC FIELDS  //////////////////////////////////////////////////////////////////////////////////////////////  // modes  public static ArrayList modes;  public static ArrayList modesFileFilters;  // selected language  private static String language = "English";  private static ZipFile languagePack;  private static ArrayList languageEntries;  // GUI option to have, or not flat menus  private static boolean flatMenus = true;  // GUI option to have non highlighted buttons  private static boolean buttonsHighlight = true;  // server socket  private static JextLoader jextLoader;  private static boolean isServerEnabled;  // plugins specific variables  private static ArrayList plugins;  // user properties filename  public static String usrProps;  // the splash screen  private static SplashScreen splash;  // the properties files  private static Properties props, defaultProps;  // contains all the instances of Jext  // this is an object we synchronize on to avoid window being created concurrently or when is not ready  // enough(for instance by JextLoader when we didn't call initProperties() yet).  private static ArrayList instances = new ArrayList(5);  // contains all the actions  private static HashMap actionHash;  // contains all the python actions  private static HashMap pythonActionHash = new HashMap();  // auto check  private static VersionCheck check;  // input handler  private static DefaultInputHandler inputHandler;  // user properties file name  private static final String USER_PROPS = SETTINGS_DIRECTORY + ".jext-props.xml";  // this property(set by loadInSingleJVMInstance), if true, says we must not show  private static boolean runInBg = false;  private static boolean keepInMemory = false;  //the default value found during loading must be stored for the option dialog  private static boolean defaultKeepInMemory = false;  // when the user runs jext -kill, we store this here and go to kill the server(see   // loadInSingleJVMInstance)  private static boolean goingToKill = false;  // the text area we pre-build if running in background, that will be shown when Jext is started  // by the user(so it will be very fast!)  private static JextFrame builtTextArea = null;  //////////////////////////////////////////////////////////////////////////////////////////////  // STATIC METHODS  //////////////////////////////////////////////////////////////////////////////////////////////  /**   * Returns true if highlight buttons should not be highlighted on mouse over.   */  public static boolean getButtonsHighlight()  {    return buttonsHighlight;  }  /**   * Returns true if menu should be flatened.   */  public static boolean getFlatMenus()  {    return flatMenus;  }  /**   * Stop the auto check function. We just interrupt the   * <code>Thread</code> and then 'kill' it.   */  public static void stopAutoCheck()  {    if (check != null)    {      check.interrupt();      check = null;    }  }  /**   * Returns the input handler.   */  public static DefaultInputHandler getInputHandler()  {    return inputHandler;  }  /**   * Add an action listener to the list.   * @param action The action listener   */  public static void addAction(MenuAction action)  {    String name = action.getName();    actionHash.put(name, action);    String keyStroke = getProperty(name.concat(".shortcut"));    if (keyStroke != null)      inputHandler.addKeyBinding(keyStroke, action);  }  /**   * Add a python action listener to the list.   * @param name Internal action name   * @param script The python source script   * @param editAction True if this is an edit action   */  public static void addPythonAction(String name, String script, boolean editAction)  {    PythonAction action;    if (!editAction)          action = new PythonAction(name, script);    else      action = new PythonEditAction(name, script);    pythonActionHash.put(name, action);    String keyStroke = getProperty(name.concat(".shortcut"));    if (keyStroke != null)      inputHandler.addKeyBinding(keyStroke, action);  }  /**   * Returns a named action.   * @param action The action   */  public static MenuAction getAction(String action)  {    Object o = actionHash.get(action);    if (o == null)      o = pythonActionHash.get(action);    return (MenuAction) o;  }  /**   * Load the action listeners.   */  private static void initActions()  {    actionHash = new HashMap();    inputHandler = new DefaultInputHandler();    inputHandler.addDefaultKeyBindings();    // Python written actions    loadXMLActions(Jext.class.getResourceAsStream("jext.actions.xml"), "jext.actions.xml");    // native Java actions    addAction(new BeginLine());    addAction(new BoxComment());    addAction(new CompleteWord());    addAction(new CompleteWordAll());    addAction(new CreateTemplate());    addAction(new EndLine());    addAction(new JoinAllLines());    addAction(new JoinLines());    addAction(new LeftIndent());    addAction(new OpenUrl());    addAction(new Print());//    addAction(new RemoveSpaces());    addAction(new RemoveWhitespace());    addAction(new RightIndent());    addAction(new SimpleComment());    addAction(new SimpleUnComment());    addAction(new SpacesToTabs());    addAction(new TabsToSpaces());    addAction(new ToLowerCase());    addAction(new ToUpperCase());    addAction(new WingComment());    addAction(new WordCount());    // init OneClick! actions    addAction(new OneAutoIndent());    // One Click !    loadXMLOneClickActions(Jext.class.getResourceAsStream("jext.oneclickactions.xml"),                                                          "jext.oneclickactions.xml");    //    addAction(new OneClickAction("one_paste",             "paste"));    //    addAction(new OneClickAction("one_reverse_paste",     "reverse_paste"));    //    addAction(new OneClickAction("one_delete_line",       "delete_line"));    //    addAction(new OneClickAction("one_join_lines",        "join_lines"));    //    addAction(new OneClickAction("one_right_indent",      "right_indent"));    //    addAction(new OneClickAction("one_left_indent",       "left_indent"));    //    addAction(new OneClickAction("one_simple_comment",    "simple_comment"));    //    addAction(new OneClickAction("one_simple_uncomment",  "simple_uncomment"));    //    addAction(new OneClickAction("one_complete_word",     "complete_word"));    // key bindings    addJextKeyBindings();  }  /**   * Adds Jext internal key bindings.   */  private static void addJextKeyBindings()  {    inputHandler.addKeyBinding("CA+UP",           new ScrollUp());    inputHandler.addKeyBinding("CA+PAGE_UP",      new ScrollPageUp());    inputHandler.addKeyBinding("CA+DOWN",         new ScrollDown());    inputHandler.addKeyBinding("CA+PAGE_DOWN",    new ScrollPageDown());    inputHandler.addKeyBinding("C+UP",            new PrevLineIndent());    inputHandler.addKeyBinding("C+DOWN",          new NextLineIndent());    inputHandler.addKeyBinding("ENTER",           new IndentOnEnter());    inputHandler.addKeyBinding("TAB",             new IndentOnTab());    inputHandler.addKeyBinding("S+TAB",           new LeftIndent());    inputHandler.addKeyBinding("C+INSERT",        getAction("copy"));    inputHandler.addKeyBinding("S+INSERT",        getAction("paste"));    inputHandler.addKeyBinding("CA+LEFT",         new CsWord(CsWord.NO_ACTION, TextUtilities.BACKWARD));    inputHandler.addKeyBinding("CA+RIGHT",        new CsWord(CsWord.NO_ACTION, TextUtilities.FORWARD));    inputHandler.addKeyBinding("CAS+LEFT",        new CsWord(CsWord.SELECT,    TextUtilities.BACKWARD));    inputHandler.addKeyBinding("CAS+RIGHT",       new CsWord(CsWord.SELECT,    TextUtilities.FORWARD));    inputHandler.addKeyBinding("CA+BACK_SPACE",   new CsWord(CsWord.DELETE,    TextUtilities.BACKWARD));    inputHandler.addKeyBinding("CAS+BACK_SPACE",  new CsWord(CsWord.DELETE,    TextUtilities.FORWARD));        if (Utilities.JDK_VERSION.charAt(2) >= '4')    {      inputHandler.addKeyBinding("C+PAGE_UP",     new TabSwitcher(false));      inputHandler.addKeyBinding("C+PAGE_DOWN",   new TabSwitcher(true));    }//end if JRE 1.4 or above  }  /**   * Loads plugins.   */  private static void initPlugins()  {    plugins = new ArrayList();    loadPlugins(JEXT_HOME + File.separator + "plugins");    loadPlugins(SETTINGS_DIRECTORY + "plugins");  }  /**   * Makes each mode know what plugins to start when it is selected.   */  public static void assocPluginsToModes()  {    Mode mode;    String modeName;    String pluginModes;    for (int i = 0; i < plugins.size(); i++)    {      Plugin plugin = (Plugin) plugins.get(i);      pluginModes = getProperty("plugin." + plugin.getClass().getName() + ".modes");      if (pluginModes != null)      {        StringTokenizer tok = new StringTokenizer(pluginModes);        while (tok.hasMoreTokens())        {          modeName = tok.nextToken();          mode = getMode(modeName);          mode.addPlugin( plugin);        }      }    }  }  /**   * Loads all plugins in a directory.   * @param directory The directory   */  public static void loadPlugins(String directory)  {    String[] args = { directory };    System.out.println(getProperty("jar.scanningdir", args));    File file = new File(directory);    if (!(file.exists() || file.isDirectory()))      return;    String[] plugins = file.list();    if (plugins == null)      return;    for (int i = 0; i < plugins.length; i++)    {      String plugin = plugins[i];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -