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

📄 jedit.java

📁 Java写的文本编辑器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	private static void initSiteProperties()	{		// site properties are loaded as default properties, overwriting		// jEdit's system properties		String siteSettingsDirectory = MiscUtilities.constructPath(			jEditHome, "properties");		File siteSettings = new File(siteSettingsDirectory);		if (!(siteSettings.exists() && siteSettings.isDirectory()))			return;		String[] snippets = siteSettings.list();		if (snippets == null)			return;		MiscUtilities.quicksort(snippets,			new MiscUtilities.StringICaseCompare());		for (int i = 0; i < snippets.length; ++i)		{			String snippet = snippets[i];			if(!snippet.toLowerCase().endsWith(".props"))				continue;			try			{				String path = MiscUtilities.constructPath(					siteSettingsDirectory,snippet);				Log.log(Log.DEBUG,jEdit.class,					"Loading site snippet: " + path);				loadProps(new FileInputStream(new File(path)),true);			}			catch(FileNotFoundException fnf)			{				Log.log(Log.DEBUG,jEdit.class,fnf);			}			catch(IOException e)			{				Log.log(Log.ERROR,jEdit.class,"Cannot load site snippet "					+ snippet);				Log.log(Log.ERROR,jEdit.class,e);			}		}	}	/**	 * Load actions.	 */	private static void initActions()	{		Reader in = new BufferedReader(new InputStreamReader(			jEdit.class.getResourceAsStream("actions.xml")));		if(!loadActions("actions.xml",in,false))			System.exit(1);	}	/**	 * Loads plugins.	 */	private static void initPlugins()	{		if(jEditHome != null)			loadPlugins(MiscUtilities.constructPath(jEditHome,"jars"));		else		{			// load firewall plugin 'manually' in web start version			// this is really bad, but we have to do it because			// we need firewall functionality in order for the			// user to be able to download and install plugins.			try			{				InputStream in = jEdit.class.getResourceAsStream("Firewall.props");				if(in != null)				{					loadProps(in,true);					Class clazz;					ClassLoader loader = jEdit.class.getClassLoader();					if(loader != null)						clazz = loader.loadClass("FirewallPlugin");					else						clazz = Class.forName("FirewallPlugin");					EditPlugin plugin = (EditPlugin)clazz.newInstance();					addPlugin(plugin);				}			}			catch(Throwable t)			{				Log.log(Log.ERROR,jEdit.class,"Could not load firewall plugin:");				Log.log(Log.ERROR,jEdit.class,t);			}		}		if(settingsDirectory != null)		{			File jarsDirectory = new File(settingsDirectory,"jars");			if(!jarsDirectory.exists())				jarsDirectory.mkdir();			loadPlugins(jarsDirectory.getPath());		}	}	/**	 * Loads user properties.	 */	private static void initUserProperties()	{		props = new Properties(defaultProps);		if(settingsDirectory != null)		{			File file = new File(MiscUtilities.constructPath(				settingsDirectory,"properties"));			propsModTime = file.lastModified();			try			{				loadProps(new FileInputStream(file),false);			}			catch(FileNotFoundException fnf)			{				Log.log(Log.DEBUG,jEdit.class,fnf);			}			catch(IOException e)			{				Log.log(Log.ERROR,jEdit.class,e);			}		}	}	/**	 * Sets the Swing look and feel.	 */	private static void initPLAF()	{		/* // People seem to hate the default Metal fonts because they are bold		MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()		{			FontUIResource plain12 = new FontUIResource(new Font(				"Dialog",Font.PLAIN,12));			FontUIResource mono12 = new FontUIResource(new Font(				"Monospaced",Font.PLAIN,12));			public String getName()			{				return "jEdit";			}			public FontUIResource getControlTextFont()			{				return plain12;			}			public FontUIResource getSystemTextFont()			{				return mono12;			}			public FontUIResource getUserTextFont()			{				return plain12;			}			public FontUIResource getMenuTextFont()			{				return plain12;			}		}); */		String lf = getProperty("lookAndFeel");		try		{			if(lf != null && lf.length() != 0)				UIManager.setLookAndFeel(lf);		}		catch(Exception e)		{			Log.log(Log.ERROR,jEdit.class,e);		}	}	/**	 * Runs scripts in the site startup directory, and user startup directory.	 */	private static void runStartupScripts(File directory)	{		if (!directory.isDirectory())			return;		String[] snippets = directory.list();		if (snippets == null)			return;		MiscUtilities.quicksort(snippets,			new MiscUtilities.StringICaseCompare());		for(int i = 0; i < snippets.length; ++i)		{			String snippet = snippets[i];			if(!snippet.toLowerCase().endsWith(".bsh"))				continue;			String path = new File(directory,snippet).getPath();			BeanShell.runScript(null,path,false,false);		}	}	private static void getNotLoadedPluginJARs(Vector returnValue,		String dir, String[] list)	{loop:		for(int i = 0; i < list.length; i++)		{			String name = list[i];			if(!name.toLowerCase().endsWith(".jar"))				continue loop;			String path = MiscUtilities.constructPath(dir,name);			for(int j = 0; j < jars.size(); j++)			{				EditPlugin.JAR jar = (EditPlugin.JAR)					jars.elementAt(j);				String jarPath = jar.getPath();				String jarName = MiscUtilities.getFileName(jarPath);				if(path.equals(jarPath))					continue loop;				else if(!new File(jarPath).exists()					&& name.equals(jarName))					continue loop;			}			returnValue.addElement(path);		}	}	private static void gotoMarker(final View view, final Buffer buffer,		final String marker)	{		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				int pos;				// Handle line number				if(marker.startsWith("+line:"))				{					try					{						int line = Integer.parseInt(marker.substring(6));						Element lineElement = buffer.getDefaultRootElement()							.getElement(line - 1);						pos = lineElement.getStartOffset();					}					catch(Exception e)					{						return;					}				}				// Handle marker				else if(marker.startsWith("+marker:"))				{					if(marker.length() != 9)						return;					Marker m = buffer.getMarker(marker.charAt(8));					if(m == null)						return;					pos = m.getPosition();				}				// Can't happen				else					throw new InternalError();				if(view != null && view.getBuffer() == buffer)					view.getTextArea().setCaretPosition(pos);				else					buffer.putProperty(Buffer.CARET,new Integer(pos));			}		});	}	private static void addBufferToList(Buffer buffer)	{		// if only one, clean, 'untitled' buffer is open, we		// replace it		if(viewCount <= 1 && buffersFirst != null			&& buffersFirst == buffersLast			&& buffersFirst.isUntitled()			&& !buffersFirst.isDirty())		{			Buffer oldBuffersFirst = buffersFirst;			buffersFirst = buffersLast = buffer;			EditBus.send(new BufferUpdate(oldBuffersFirst,null,				BufferUpdate.CLOSED));			return;		}		bufferCount++;		if(buffersFirst == null)		{			buffersFirst = buffersLast = buffer;			return;		}		else if(sortBuffers)		{			String name1 = (sortByName ? buffer.getName()				: buffer.getPath()).toLowerCase();			Buffer _buffer = buffersFirst;			while(_buffer != null)			{				String name2 = (sortByName ? _buffer.getName()					: _buffer.getPath()).toLowerCase();				if(name1.compareTo(name2) <= 0)				{					buffer.next = _buffer;					buffer.prev = _buffer.prev;					_buffer.prev = buffer;					if(_buffer != buffersFirst)						buffer.prev.next = buffer;					else						buffersFirst = buffer;					return;				}				_buffer = _buffer.next;			}		}		buffer.prev = buffersLast;		buffersLast.next = buffer;		buffersLast = buffer;	}	private static void removeBufferFromList(Buffer buffer)	{		bufferCount--;		if(buffer == buffersFirst && buffer == buffersLast)		{			buffersFirst = buffersLast = null;			return;		}		if(buffer == buffersFirst)		{			buffersFirst = buffer.next;			buffer.next.prev = null;		}		else		{			buffer.prev.next = buffer.next;		}		if(buffer == buffersLast)		{			buffersLast = buffersLast.prev;			buffer.prev.next = null;		}		else		{			buffer.next.prev = buffer.prev;		}		// fixes the hang that can occur if we 'save as' to a new		// filename which requires re-sorting		buffer.next = buffer.prev = null;	}	private static void addViewToList(View view)	{		viewCount++;		if(viewsFirst == null)			viewsFirst = viewsLast = view;		else		{			view.prev = viewsLast;			viewsLast.next = view;			viewsLast = view;		}	}	private static void removeViewFromList(View view)	{		viewCount--;		if(viewsFirst == viewsLast)		{			viewsFirst = viewsLast = null;			return;		}		if(view == viewsFirst)		{			viewsFirst = view.next;			view.next.prev = null;		}		else		{			view.prev.next = view.next;		}		if(view == viewsLast)		{			viewsLast = viewsLast.prev;			view.prev.next = null;		}		else		{			view.next.prev = view.prev;		}	}	/**	 * closeView() used by exit().	 */	private static void closeView(View view, boolean callExit)	{		if(viewsFirst == viewsLast && callExit)			exit(view,false); /* exit does editor event & save */		else		{			EditBus.send(new ViewUpdate(view,ViewUpdate.CLOSED));			view.close();			removeViewFromList(view);		}	}	/**	 * Loads a mode catalog file.	 * @since jEdit 3.2pre2	 */	private static void loadModeCatalog(String path, boolean resource)	{		Log.log(Log.MESSAGE,jEdit.class,"Loading mode catalog file " + path);		ModeCatalogHandler handler = new ModeCatalogHandler(			MiscUtilities.getParentOfPath(path),resource);		XmlParser parser = new XmlParser();		parser.setHandler(handler);		try		{			InputStream _in;			if(resource)				_in = jEdit.class.getResourceAsStream(path);			else				_in = new FileInputStream(path);			BufferedReader in = new BufferedReader(				new InputStreamReader(_in));			parser.parse(null, null, in);		}		catch(XmlException xe)		{			int line = xe.getLine();			String message = xe.getMessage();			Log.log(Log.ERROR,jEdit.class,path + ":" + line				+ ": " + message);		}		catch(Exception e)		{			Log.log(Log.ERROR,jEdit.class,e);		}	}	/**	 * Loads all plugins in a directory.	 * @param directory The directory	 */	private static void loadPlugins(String directory)	{		Log.log(Log.NOTICE,jEdit.class,"Loading plugins from "			+ directory);		File file = new File(directory);		if(!(file.exists() && file.isDirectory()))			return;		String[] plugins = file.list();		if(plugins == null)			return;		MiscUtilities.quicksort(plugins,new MiscUtilities.StringICaseCompare());		for(int i = 0; i < plugins.length; i++)		{			String plugin = plugins[i];			if(!plugin.toLowerCase().endsWith(".jar"))				continue;			String path = MiscUtilities.constructPath(directory,plugin);			if(plugin.equals("EditBuddy.jar")				|| plugin.equals("PluginManager.jar")				|| plugin.equals("jaxp.jar")				|| plugin.equals("crimson.jar")				|| plugin.equals("Tidy.jar"))			{				String[] args = { plugin };				GUIUtilities.error(null,"plugin.obsolete",args);				continue;			}			try			{				Log.log(Log.DEBUG,jEdit.class,					"Scanning JAR file: " + path);				new JARClassLoader(path);			}			catch(IOException io)			{				Log.log(Log.ERROR,jEdit.class,"Cannot load"					+ " plugin " + plugin);				Log.log(Log.ERROR,jEdit.class,io);				String[] args = { plugin, io.toString() };				GUIUtilities.error(null,"plugin.load-error",args);			}		}	}	/**	 * Loads all key bindings from the properties.	 * @since 3.1pre1	 */	private static void initKeyBindings()	{		inputHandler.removeAllKeyBindings();		EditAction[] actions = getActions();		for(int i = 0; i < actions.length; i++)		{			EditAction action = actions[i];			String shortcut1 = jEdit.getProperty(action.getName()				+ ".shortcut");			if(shortcut1 != null)				inputHandler.addKeyBinding(shortcut1,action);			String shortcut2 = jEdit.getProperty(action.getName()				+ ".shortcut2");			if(shortcut2 != null)				inputHandler.addKeyBinding(shortcut2,action);		}		Vector macros = Macros.getMacroList();		for(int i = 0; i < macros.size(); i++)		{			Macros.Macro macro = (Macros.Macro)macros.elementAt(i);			String shortcut1 = jEdit.getProperty(macro.name + ".shortcut");			if(shortcut1 != null)				jEdit.getInputHandler().addKeyBi

⌨️ 快捷键说明

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