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

📄 jedit.java

📁 Java写的文本编辑器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * jEdit.java - Main class of the jEdit editor * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov * * 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.gjt.sp.jedit;import com.microstar.xml.*;import javax.swing.plaf.metal.*;import javax.swing.plaf.FontUIResource;import javax.swing.text.Element;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.text.MessageFormat;import java.util.*;import org.gjt.sp.jedit.browser.VFSBrowser;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.io.*;import org.gjt.sp.jedit.search.SearchAndReplace;import org.gjt.sp.jedit.syntax.*;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;/** * The main class of the jEdit text editor. * @author Slava Pestov * @version $Id: jEdit.java,v 1.3 2001/09/08 04:50:46 spestov Exp $ */public class jEdit{	/**	 * Returns the jEdit version as a human-readable string.	 */	public static String getVersion()	{		return MiscUtilities.buildToVersion(getBuild());	}	/**	 * Returns the internal version. String.compareTo() can be used	 * to compare different internal versions.	 */	public static String getBuild()	{		// (major).(minor).(<99 = preX, 99 = final).(bug fix)		return "03.02.99.02";	}	/**	 * The main method of the jEdit application.	 * <p>	 * This should never be invoked directly.	 * @param args The command line arguments	 */	public static void main(String[] args)	{		// for developers: run 'jedit 0' to get extensive logging		int level = Log.WARNING;		if(args.length >= 1)		{			String levelStr = args[0];			if(levelStr.length() == 1 && Character.isDigit(				levelStr.charAt(0)))			{				level = Integer.parseInt(levelStr);				args[0] = null;			}		}		// Parse command line		boolean endOpts = false;		settingsDirectory = MiscUtilities.constructPath(			System.getProperty("user.home"),".jedit");		String portFile = "server";		boolean restore = true;		boolean noStartupScripts = false;		String userDir = System.getProperty("user.dir");		// script to run		String scriptFile = null;		for(int i = 0; i < args.length; i++)		{			String arg = args[i];			if(arg == null)				continue;			else if(arg.length() == 0)				args[i] = null;			else if(arg.startsWith("-") && !endOpts)			{				if(arg.equals("--"))					endOpts = true;				else if(arg.equals("-usage"))				{					version();					System.err.println();					usage();					System.exit(1);				}				else if(arg.equals("-version"))				{					version();					System.exit(1);				}				else if(arg.equals("-nosettings"))					settingsDirectory = null;				else if(arg.startsWith("-settings="))					settingsDirectory = arg.substring(10);				else if(arg.startsWith("-noserver"))					portFile = null;				else if(arg.equals("-server"))					portFile = "server";				else if(arg.startsWith("-server="))					portFile = arg.substring(8);				else if(arg.startsWith("-background"))					background = true;				else if(arg.equals("-norestore"))					restore = false;				else if(arg.equals("-nostartupscripts"))					noStartupScripts = true;				else if(arg.startsWith("-run="))					scriptFile = arg.substring(5);				else				{					System.err.println("Unknown option: "						+ arg);					usage();					System.exit(1);				}				args[i] = null;			}		}		if(settingsDirectory != null && portFile != null)			portFile = MiscUtilities.constructPath(settingsDirectory,portFile);		else			portFile = null;		Log.init(true,level);		// Try connecting to another running jEdit instance		if(portFile != null && new File(portFile).exists())		{			int port, key;			try			{				BufferedReader in = new BufferedReader(new FileReader(portFile));				port = Integer.parseInt(in.readLine());				key = Integer.parseInt(in.readLine());				in.close();				Socket socket = new Socket(InetAddress.getByName("127.0.0.1"),port);				Writer out = new OutputStreamWriter(socket.getOutputStream(),"UTF8");				out.write(String.valueOf(key));				out.write('\n');				String script = makeServerScript(restore,args,scriptFile);				out.write(script);				out.close();				System.exit(0);			}			catch(Exception e)			{				// ok, this one seems to confuse newbies				// endlessly, so log it as NOTICE, not				// ERROR				Log.log(Log.NOTICE,jEdit.class,"An error occurred"					+ " while connecting to the jEdit server instance.");				Log.log(Log.NOTICE,jEdit.class,"This probably means that"					+ " jEdit crashed and/or exited abnormally");				Log.log(Log.NOTICE,jEdit.class,"the last time it was run.");				Log.log(Log.NOTICE,jEdit.class,"If you don't"					+ " know what this means, don't worry.");				Log.log(Log.NOTICE,jEdit.class,e);			}		}		// MacOS X GUI hacks		if(System.getProperty("os.name").indexOf("Mac") != -1)		{			// put the menu bar at the top of the screen, as opposed to			// inside the jEdit window			System.getProperties().put("com.apple.macos.useScreenMenuBar","true");		}		// Initialize activity log and settings directory		boolean showSplash = true;		Writer stream;		if(settingsDirectory != null)		{			File _settingsDirectory = new File(settingsDirectory);			if(!_settingsDirectory.exists())				_settingsDirectory.mkdirs();			File _macrosDirectory = new File(settingsDirectory,"macros");			if(!_macrosDirectory.exists())				_macrosDirectory.mkdir();			String logPath = MiscUtilities.constructPath(				settingsDirectory,"activity.log");			try			{				stream = new BufferedWriter(new FileWriter(logPath));			}			catch(Exception e)			{				e.printStackTrace();				stream = null;			}			// don't show splash screen if there is a file named			// 'nosplash' in the settings directory			if(new File(settingsDirectory,"nosplash").exists())				showSplash = false;		}		else		{			stream = null;		}		// Show the kool splash screen		if(showSplash)			GUIUtilities.showSplashScreen();		Log.setLogWriter(stream);		Log.log(Log.NOTICE,jEdit.class,"jEdit version " + getVersion());		Log.log(Log.MESSAGE,jEdit.class,"Settings directory is "			+ settingsDirectory);		// Initialize server		if(portFile != null)		{			server = new EditServer(portFile);			if(!server.isOK())				server = null;		}		else		{			if(background)			{				background = false;				System.err.println("You cannot specify both the"					+ " -background and -noserver switches");			}		}		// Get things rolling		initMisc();		initSystemProperties();		BeanShell.init();		GUIUtilities.advanceSplashProgress();		if(jEditHome != null)			initSiteProperties();		initUserProperties();		initActions();		initPlugins();		if(settingsDirectory != null)		{			File history = new File(MiscUtilities.constructPath(				settingsDirectory,"history"));			if(history.exists())				historyModTime = history.lastModified();			HistoryModel.loadHistory(history);			File recent = new File(MiscUtilities.constructPath(				settingsDirectory,"recent.xml"));			if(recent.exists())				recentModTime = recent.lastModified();			BufferHistory.load(recent);		}		Abbrevs.load();		GUIUtilities.advanceSplashProgress();		// Buffer sort		sortBuffers = getBooleanProperty("sortBuffers");		sortByName = getBooleanProperty("sortByName");		initPLAF();		reloadModes();		GUIUtilities.advanceSplashProgress();		SearchAndReplace.load();		FavoritesVFS.loadFavorites();		Macros.loadMacros();		GUIUtilities.advanceSplashProgress();		// Start plugins		for(int i = 0; i < jars.size(); i++)		{			((EditPlugin.JAR)jars.elementAt(i)).getClassLoader()				.startAllPlugins();		}		// Run startup scripts, after plugins, proeprties, etc		// are loaded		if(!noStartupScripts && jEditHome != null)		{			String path = MiscUtilities.constructPath(jEditHome,"startup");			File file = new File(path);			if(file.exists())				runStartupScripts(file);		}		if(!noStartupScripts && settingsDirectory != null)		{			String path = MiscUtilities.constructPath(settingsDirectory,"startup");			File file = new File(path);			if(!file.exists())				file.mkdirs();			else				runStartupScripts(file);		}		// Run script specified with -run= parameter		if(scriptFile != null)		{			scriptFile = MiscUtilities.constructPath(userDir,scriptFile);			BeanShell.runScript(null,scriptFile,false,false);		}		// Must be after plugins are started!!!		propertiesChanged();		GUIUtilities.advanceSplashProgress();		Buffer buffer = openFiles(null,userDir,args);		String splitConfig = null;		if(restore && settingsDirectory != null			&& jEdit.getBooleanProperty("restore")			&& (bufferCount == 0 || jEdit.getBooleanProperty("restore.cli")))		{			splitConfig = restoreOpenFiles();		}		// Create the view and hide the splash screen.		final Buffer _buffer = buffer;		final String _splitConfig = splitConfig;		GUIUtilities.advanceSplashProgress();		SwingUtilities.invokeLater(new Runnable() {			public void run()			{				if(bufferCount == 0)					newFile(null);				EditBus.send(new EditorStarted(null));				View view;				if(_buffer != null)					view = newView(null,_buffer);				else					view = newView(null,_splitConfig);				// show tip of the day				if(jEdit.getBooleanProperty("firstTime"))					new HelpViewer("jeditresource:/doc/welcome.html");				else if(jEdit.getBooleanProperty("tip.show"))					new TipOfTheDay(view);				setBooleanProperty("firstTime",false);				// Start I/O threads				VFSManager.start();				// Start edit server				if(server != null)					server.start();				GUIUtilities.hideSplashScreen();				Log.log(Log.MESSAGE,jEdit.class,"Startup "					+ "complete");			}		});	}	/**	 * Returns the properties object which contains all known	 * jEdit properties.	 * @since jEdit 3.1pre4	 */	public static final Properties getProperties()	{		return props;	}	/**	 * Fetches a property, returning null if it's not defined.	 * @param name The property	 */	public static final String getProperty(String name)	{		return props.getProperty(name);	}	/**	 * Fetches a property, returning the default value if it's not	 * defined.	 * @param name The property	 * @param def The default value	 */	public static final String getProperty(String name, String def)	{		return props.getProperty(name,def);	}	/**	 * Returns the property with the specified name, formatting it with	 * the <code>java.text.MessageFormat.format()</code> method.	 * @param name The property	 * @param args The positional parameters	 */	public static final String getProperty(String name, Object[] args)	{		if(name == null)			return null;		if(args == null)			return props.getProperty(name);		else		{			String value = props.getProperty(name);			if(value == null)				return null;			else				return MessageFormat.format(value,args);		}	}	/**	 * Returns the value of a boolean property.	 * @param name The property	 */	public static final boolean getBooleanProperty(String name)	{		return getBooleanProperty(name,false);	}	/**	 * Returns the value of a boolean property.	 * @param name The property	 * @param def The default value	 */	public static final boolean getBooleanProperty(String name, boolean def)	{		String value = getProperty(name);		if(value == null)			return def;		else if(value.equals("true") || value.equals("yes")			|| value.equals("on"))			return true;		else if(value.equals("false") || value.equals("no")			|| value.equals("off"))			return false;		else			return def;	}	/**	 * Sets a property to a new value.	 * @param name The property	 * @param value The new value	 */	public static final void setProperty(String name, String value)	{		/* if value is null:		 * - if default is null, unset user prop		 * - else set user prop to ""		 * else		 * - if default equals value, ignore		 * - if default doesn't equal value, set user		 */		if(value == null || value.length() == 0)		{			String prop = (String)defaultProps.get(name);			if(prop == null || prop.length() == 0)				props.remove(name);			else				props.put(name,"");		}		else		{			String prop = (String)defaultProps.get(name);			if(value.equals(prop))				props.remove(name);			else				props.put(name,value);		}	}	/**	 * Sets a property to a new value. Properties set using this	 * method are not saved to the user properties list.	 * @param name The property	 * @param value The new value	 * @since jEdit 2.3final	 */	public static final void setTemporaryProperty(String name, String value)	{		props.remove(name);		defaultProps.put(name,value);	}	/**	 * @deprecated As of jEdit 2.3final. Use setTemporaryProperty()	 * instead.	 */	public static final void setDefaultProperty(String name, String value)	{		setTemporaryProperty(name,value);	}	/**	 * Sets a boolean property.	 * @param name The property	 * @param value The value	 */	public static final void setBooleanProperty(String name, boolean value)	{		setProperty(name,value ? "true" : "false");	}	/**	 * Unsets (clears) a property.	 * @param name The property	 */	public static final void unsetProperty(String name)	{		if(defaultProps.get(name) != null)			props.put(name,"");		else			props.remove(name);

⌨️ 快捷键说明

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