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

📄 view.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * View.java - jEdit view * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1998, 2003 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;//{{{ Importsimport javax.swing.event.*;import javax.swing.text.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.IOException;import java.io.StreamTokenizer;import java.io.StringReader;import java.net.Socket;import java.util.*;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.search.*;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;//}}}/** * A <code>View</code> is jEdit's top-level frame window.<p> * * In a BeanShell script, you can obtain the current view instance from the * <code>view</code> variable.<p> * * The largest component it contains is an {@link EditPane} that in turn * contains a {@link org.gjt.sp.jedit.textarea.JEditTextArea} that displays a * {@link Buffer}. * A view can have more than one edit pane in a split window configuration. * A view also contains a menu bar, an optional toolbar and other window * decorations, as well as docked windows.<p> * * The <b>View</b> class performs two important operations * dealing with plugins: creating plugin menu items, and managing dockable * windows. * * <ul> * <li>When a view is being created, its initialization routine * iterates through the collection of loaded plugins and constructs the * <b>Plugins</b> menu using the properties as specified in the * {@link EditPlugin} class.</li> * <li>The view also creates and initializes a * {@link org.gjt.sp.jedit.gui.DockableWindowManager} * object.  This object is * responsible for creating, closing and managing dockable windows.</li> * </ul> * * This class does not have a public constructor. * Views can be opened and closed using methods in the <code>jEdit</code> * class. * * @see org.gjt.sp.jedit.jEdit#newView(View) * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer) * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer,boolean) * @see org.gjt.sp.jedit.jEdit#closeView(View) * * @author Slava Pestov * @author John Gellene (API documentation) * @version $Id: View.java,v 1.109 2004/03/20 06:08:49 spestov Exp $ */public class View extends JFrame implements EBComponent{	//{{{ User interface	//{{{ ToolBar-related constants	//{{{ Groups	/**	 * The group of tool bars above the DockableWindowManager	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int TOP_GROUP = 0;	/**	 * The group of tool bars below the DockableWindowManager	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int BOTTOM_GROUP = 1;	public static final int DEFAULT_GROUP = TOP_GROUP;	//}}}	//{{{ Layers	// Common layers	/**	 * The highest possible layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int TOP_LAYER = Integer.MAX_VALUE;	/**	 * The default layer for tool bars with no preference.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int DEFAULT_LAYER = 0;	/**	 * The lowest possible layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int BOTTOM_LAYER = Integer.MIN_VALUE;	// Layers for top group	/**	 * Above system tool bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int ABOVE_SYSTEM_BAR_LAYER = 150;	/**	 * System tool bar layer.	 * jEdit uses this for the main tool bar.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int SYSTEM_BAR_LAYER = 100;	/**	 * Below system tool bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int BELOW_SYSTEM_BAR_LAYER = 75;	/**	 * Search bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int SEARCH_BAR_LAYER = 75;	/**	 * Below search bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.0pre7	 */	public static final int BELOW_SEARCH_BAR_LAYER = 50;	// Layers for bottom group	/**	 * @deprecated Status bar no longer added as a tool bar.	 */	public static final int ABOVE_ACTION_BAR_LAYER = -50;	/**	 * Action bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.2pre1	 */	public static final int ACTION_BAR_LAYER = -75;	/**	 * Status bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.2pre1	 */	public static final int STATUS_BAR_LAYER = -100;	/**	 * Status bar layer.	 * @see #addToolBar(int,int,java.awt.Component)	 * @since jEdit 4.2pre1	 */	public static final int BELOW_STATUS_BAR_LAYER = -150;	//}}}	//}}}	//{{{ getDockableWindowManager() method	/**	 * Returns the dockable window manager associated with this view.	 * @since jEdit 2.6pre3	 */	public DockableWindowManager getDockableWindowManager()	{		return dockableWindowManager;	} //}}}	//{{{ getToolBar() method	/**	 * Returns the view's tool bar.	 * @since jEdit 4.2pre1	 */	public Box getToolBar()	{		return toolBar;	} //}}}	//{{{ addToolBar() method	/**	 * Adds a tool bar to this view.	 * @param toolBar The tool bar	 */	public void addToolBar(Component toolBar)	{		addToolBar(DEFAULT_GROUP, DEFAULT_LAYER, toolBar);	} //}}}	//{{{ addToolBar() method	/**	 * Adds a tool bar to this view.	 * @param group The tool bar group to add to	 * @param toolBar The tool bar	 * @see org.gjt.sp.jedit.gui.ToolBarManager	 * @since jEdit 4.0pre7	 */	public void addToolBar(int group, Component toolBar)	{		addToolBar(group, DEFAULT_LAYER, toolBar);	} //}}}	//{{{ addToolBar() method	/**	 * Adds a tool bar to this view.	 * @param group The tool bar group to add to	 * @param layer The layer of the group to add to	 * @param toolBar The tool bar	 * @see org.gjt.sp.jedit.gui.ToolBarManager	 * @since jEdit 4.0pre7	 */	public void addToolBar(int group, int layer, Component toolBar)	{		toolBarManager.addToolBar(group, layer, toolBar);		getRootPane().revalidate();	} //}}}	//{{{ removeToolBar() method	/**	 * Removes a tool bar from this view.	 * @param toolBar The tool bar	 */	public void removeToolBar(Component toolBar)	{		toolBarManager.removeToolBar(toolBar);		getRootPane().revalidate();	} //}}}	//{{{ showWaitCursor() method	/**	 * Shows the wait cursor. This method and	 * {@link #hideWaitCursor()} are implemented using a reference	 * count of requests for wait cursors, so that nested calls work	 * correctly; however, you should be careful to use these methods in	 * tandem.<p>	 *	 * To ensure that {@link #hideWaitCursor()} is always called	 * after a {@link #showWaitCursor()}, use a	 * <code>try</code>/<code>finally</code> block, like this:	 * <pre>try	 *{	 *    view.showWaitCursor();	 *    // ...	 *}	 *finally	 *{	 *    view.hideWaitCursor();	 *}</pre>	 */	public synchronized void showWaitCursor()	{		if(waitCount++ == 0)		{			Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);			setCursor(cursor);			EditPane[] editPanes = getEditPanes();			for(int i = 0; i < editPanes.length; i++)			{				EditPane editPane = editPanes[i];				editPane.getTextArea().getPainter()					.setCursor(cursor);			}		}	} //}}}	//{{{ hideWaitCursor() method	/**	 * Hides the wait cursor.	 */	public synchronized void hideWaitCursor()	{		if(waitCount > 0)			waitCount--;		if(waitCount == 0)		{			// still needed even though glass pane			// has a wait cursor			Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);			setCursor(cursor);			cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);			EditPane[] editPanes = getEditPanes();			for(int i = 0; i < editPanes.length; i++)			{				EditPane editPane = editPanes[i];				editPane.getTextArea().getPainter()					.setCursor(cursor);			}		}	} //}}}	//{{{ getSearchBar() method	/**	 * Returns the search bar.	 * @since jEdit 2.4pre4	 */	public final SearchBar getSearchBar()	{		return searchBar;	} //}}}	//{{{ getActionBar() method	/**	 * Returns the action bar.	 * @since jEdit 4.2pre3	 */	public final ActionBar getActionBar()	{		return actionBar;	} //}}}	//{{{ getStatus() method	/**	 * Returns the status bar. The	 * {@link org.gjt.sp.jedit.gui.StatusBar#setMessage(String)} and	 * {@link org.gjt.sp.jedit.gui.StatusBar#setMessageAndClear(String)} methods can	 * be called on the return value of this method to display status	 * information to the user.	 * @since jEdit 3.2pre2	 */	public StatusBar getStatus()	{		return status;	} //}}}	//{{{ quickIncrementalSearch() method	/**	 * Quick search.	 * @since jEdit 4.0pre3	 */	public void quickIncrementalSearch(boolean word)	{		if(searchBar == null)			searchBar = new SearchBar(this,true);		if(searchBar.getParent() == null)			addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);		searchBar.setHyperSearch(false);		JEditTextArea textArea = getTextArea();		if(word)		{			String text = textArea.getSelectedText();			if(text == null)			{				textArea.selectWord();				text = textArea.getSelectedText();			}			else if(text.indexOf('\n') != -1)				text = null;			searchBar.getField().setText(text);		}		searchBar.getField().requestFocus();		searchBar.getField().selectAll();	} //}}}	//{{{ quickHyperSearch() method	/**	 * Quick HyperSearch.	 * @since jEdit 4.0pre3	 */	public void quickHyperSearch(boolean word)	{		JEditTextArea textArea = getTextArea();		if(word)		{			String text = textArea.getSelectedText();			if(text == null)			{				textArea.selectWord();				text = textArea.getSelectedText();			}			if(text != null && text.indexOf('\n') == -1)			{				HistoryModel.getModel("find").addItem(text);				SearchAndReplace.setSearchString(text);				SearchAndReplace.setSearchFileSet(new CurrentBufferSet());				SearchAndReplace.hyperSearch(this);				return;			}		}		if(searchBar == null)			searchBar = new SearchBar(this,true);		if(searchBar.getParent() == null)			addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);		searchBar.setHyperSearch(true);		searchBar.getField().setText(null);		searchBar.getField().requestFocus();		searchBar.getField().selectAll();	} //}}}	//{{{ actionBar() method	/**	 * Shows the action bar if needed, and sends keyboard focus there.	 * @since jEdit 4.2pre1	 */	public void actionBar()	{		if(actionBar == null)			actionBar = new ActionBar(this,true);		if(actionBar.getParent() == null)			addToolBar(BOTTOM_GROUP,ACTION_BAR_LAYER,actionBar);		actionBar.goToActionBar();	} //}}}	//}}}	//{{{ Input handling	//{{{ getKeyEventInterceptor() method	/**	 * Returns the listener that will handle all key events in this	 * view, if any.	 */	public KeyListener getKeyEventInterceptor()	{		return keyEventInterceptor;	} //}}}	//{{{ setKeyEventInterceptor() method	/**	 * 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;	} //}}}	//{{{ getInputHandler() method	/**	 * Returns the input handler.	 */	public InputHandler getInputHandler()	{		return inputHandler;	} //}}}	//{{{ setInputHandler() method	/**	 * Sets the input handler.	 * @param inputHandler The new input handler	 */	public void setInputHandler(InputHandler inputHandler)	{		this.inputHandler = inputHandler;	} //}}}	//{{{ getMacroRecorder() method	/**	 * Returns the macro recorder.	 */	public Macros.Recorder getMacroRecorder()	{		return recorder;	} //}}}	//{{{ setMacroRecorder() method	/**	 * Sets the macro recorder.	 * @param recorder The macro recorder	 */	public void setMacroRecorder(Macros.Recorder recorder)	{		this.recorder = recorder;	} //}}}	//{{{ processKeyEvent() method	/**	 * Forwards key events directly to the input handler.	 * This is slightly faster than using a KeyListener	 * because some Swing overhead is avoided.	 */	public void processKeyEvent(KeyEvent evt)	{		processKeyEvent(evt,VIEW);	} //}}}	//{{{ processKeyEvent() method	/**	 * Forwards key events directly to the input handler.	 * This is slightly faster than using a KeyListener	 * because some Swing overhead is avoided.	 */	public void processKeyEvent(KeyEvent evt, boolean calledFromTextArea)	{		processKeyEvent(evt,calledFromTextArea			? TEXT_AREA			: VIEW);	} //}}}	//{{{ processKeyEvent() method	public static final int VIEW = 0;	public static final int TEXT_AREA = 1;	public static final int ACTION_BAR = 2;	/**	 * Forwards key events directly to the input handler.	 * This is slightly faster than using a KeyListener	 * because some Swing overhead is avoided.	 */	public void processKeyEvent(KeyEvent evt, int from)	{		if(Debug.DUMP_KEY_EVENTS && from != VIEW)		{			Log.log(Log.DEBUG,this,"Key event: "				+ GrabKeyDialog.toString(evt));		}		if(getTextArea().hasFocus() && from == VIEW)			return;		evt = _preprocessKeyEvent(evt);		if(evt == null)			return;		if(Debug.DUMP_KEY_EVENTS && from != VIEW)		{			Log.log(Log.DEBUG,this,"Key event after workaround: "				+ GrabKeyDialog.toString(evt));		}		switch(evt.getID())		{		case KeyEvent.KEY_TYPED:			boolean focusOnTextArea = false;			// if the user pressed eg C+e n n in the			// search bar we want focus to go back there			// after the prefix is done			if(prefixFocusOwner != null)			{				if(prefixFocusOwner.isShowing())				{					prefixFocusOwner.requestFocus();					focusOnTextArea = true;				}			}			if(keyEventInterceptor != null)				keyEventInterceptor.keyTyped(evt);			else if(from == ACTION_BAR

⌨️ 快捷键说明

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