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

📄 view.java

📁 Java写的文本编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * View.java - jEdit view * 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 javax.swing.border.EmptyBorder;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.search.SearchBar;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;/** * A window that edits buffers. There is no public constructor in the * View class. Views are created and destroyed by the <code>jEdit</code> * class. * * @author Slava Pestov * @version $Id: View.java,v 1.1.1.1 2001/09/02 05:37:27 spestov Exp $ */public class View extends JFrame implements EBComponent{	/**	 * Returns the dockable window manager associated with this view.	 * @since jEdit 2.6pre3	 */	public DockableWindowManager getDockableWindowManager()	{		return dockableWindowManager;	}	/**	 * Returns the view's tool bar.	 * @since jEdit 3.2.1	 */	public JToolBar getToolBar()	{		return toolBar;	}	/**	 * Quick search.	 * @since jEdit 2.7pre2	 */	public void quickIncrementalSearch()	{		if(searchBar == null)		{			getToolkit().beep();			return;		}		String text = getTextArea().getSelectedText();		if(text != null && text.indexOf('\n') != -1)			text = null;		searchBar.setHyperSearch(false);		searchBar.getField().setText(text);		searchBar.getField().selectAll();		searchBar.getField().requestFocus();	}	/**	 * Quick HyperSearch.	 * @since jEdit 2.7pre2	 */	public void quickHyperSearch()	{		if(searchBar == null)		{			getToolkit().beep();			return;		}		String text = getTextArea().getSelectedText();		if(text != null && text.indexOf('\n') != -1)			text = null;		searchBar.setHyperSearch(true);		searchBar.getField().setText(text);		searchBar.getField().selectAll();		searchBar.getField().requestFocus();	}	/**	 * Returns the search bar.	 * @since jEdit 2.4pre4	 */	public final SearchBar getSearchBar()	{		return searchBar;	}	/**	 * Returns the listener that will handle all key events in this	 * view, if any.	 */	public 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;	}	/**	 * Returns the input handler.	 */	public InputHandler getInputHandler()	{		return inputHandler;	}	/**	 * Sets the input handler.	 * @param inputHandler The new input handler	 */	public void setInputHandler(InputHandler inputHandler)	{		this.inputHandler = inputHandler;	}	/**	 * Returns the macro recorder.	 */	public Macros.Recorder getMacroRecorder()	{		return recorder;	}	/**	 * Sets the macro recorder.	 * @param recorder The macro recorder	 */	public void setMacroRecorder(Macros.Recorder recorder)	{		this.recorder = recorder;	}	/**	 * Returns the status bar.	 * @since jEdit 3.2pre2	 */	public StatusBar getStatus()	{		return status;	}	/**	 * Splits the view horizontally.	 * @since jEdit 2.7pre2	 */	public void splitHorizontally()	{		split(JSplitPane.VERTICAL_SPLIT);	}	/**	 * Splits the view vertically.	 * @since jEdit 2.7pre2	 */	public void splitVertically()	{		split(JSplitPane.HORIZONTAL_SPLIT);	}	/**	 * Splits the view.	 * @since jEdit 2.3pre2	 */	public void split(int orientation)	{		editPane.saveCaretInfo();		EditPane oldEditPane = editPane;		setEditPane(createEditPane(oldEditPane.getBuffer()));		editPane.loadCaretInfo();		JComponent oldParent = (JComponent)oldEditPane.getParent();		if(oldParent instanceof JSplitPane)		{			JSplitPane oldSplitPane = (JSplitPane)oldParent;			int dividerPos = oldSplitPane.getDividerLocation();			Component left = oldSplitPane.getLeftComponent();			final JSplitPane newSplitPane = new JSplitPane(orientation,				oldEditPane,editPane);			newSplitPane.setBorder(null);			if(left == oldEditPane)				oldSplitPane.setLeftComponent(newSplitPane);			else				oldSplitPane.setRightComponent(newSplitPane);			oldSplitPane.setDividerLocation(dividerPos);			SwingUtilities.invokeLater(new Runnable()			{				public void run()				{					newSplitPane.setDividerLocation(0.5);					editPane.focusOnTextArea();				}			});		}		else		{			JSplitPane newSplitPane = splitPane = new JSplitPane(orientation,				oldEditPane,editPane);			newSplitPane.setBorder(null);			oldParent.add(splitPane);			oldParent.revalidate();			Dimension size;			if(oldParent instanceof JSplitPane)				size = oldParent.getSize();			else				size = oldEditPane.getSize();			newSplitPane.setDividerLocation(((orientation				== JSplitPane.VERTICAL_SPLIT) ? size.height				: size.width) / 2);			SwingUtilities.invokeLater(new Runnable()			{				public void run()				{					editPane.focusOnTextArea();				}			});		}	}	/**	 * Unsplits the view.	 * @since jEdit 2.3pre2	 */	public void unsplit()	{		if(splitPane != null)		{			EditPane[] editPanes = getEditPanes();			for(int i = 0; i < editPanes.length; i++)			{				EditPane _editPane = editPanes[i];				if(editPane != _editPane)					_editPane.close();			}			JComponent parent = (JComponent)splitPane.getParent();			parent.remove(splitPane);			parent.add(editPane);			parent.revalidate();			splitPane = null;			updateTitle();		}		SwingUtilities.invokeLater(new Runnable()		{			public void run()			{				editPane.focusOnTextArea();			}		});	}	/**	 * Moves keyboard focus to the next text area.	 * @since jEdit 2.7pre4	 */	public void nextTextArea()	{		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)		{			if(editPane == editPanes[i])			{				if(i == editPanes.length - 1)					editPanes[0].focusOnTextArea();				else					editPanes[i+1].focusOnTextArea();				break;			}		}	}	/**	 * Moves keyboard focus to the previous text area.	 * @since jEdit 2.7pre4	 */	public void prevTextArea()	{		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)		{			if(editPane == editPanes[i])			{				if(i == 0)					editPanes[editPanes.length - 1].focusOnTextArea();				else					editPanes[i-1].focusOnTextArea();				break;			}		}	}	/**	 * Returns the top-level split pane, if any.	 * @since jEdit 2.3pre2	 */	public JSplitPane getSplitPane()	{		return splitPane;	}	/**	 * Returns the current edit pane's buffer.	 */	public Buffer getBuffer()	{		return editPane.getBuffer();	}	/**	 * Sets the current edit pane's buffer.	 */	public void setBuffer(Buffer buffer)	{		editPane.setBuffer(buffer);	}	/**	 * Returns the current edit pane's text area.	 */	public JEditTextArea getTextArea()	{		return editPane.getTextArea();	}	/**	 * Returns the current edit pane.	 * @since jEdit 2.5pre2	 */	public EditPane getEditPane()	{		return editPane;	}	/**	 * Returns all edit panes.	 * @since jEdit 2.5pre2	 */	public EditPane[] getEditPanes()	{		if(splitPane == null)		{			EditPane[] ep = { editPane };			return ep;		}		else		{			Vector vec = new Vector();			getEditPanes(vec,splitPane);			EditPane[] ep = new EditPane[vec.size()];			vec.copyInto(ep);			return ep;		}	}	/**	 * Returns a string that can be passed to the view constructor to	 * recreate the current split configuration in a new view.	 * @since jEdit 3.2pre2	 */	public String getSplitConfig()	{		// this code isn't finished yet		StringBuffer splitConfig = new StringBuffer();		//if(splitPane != null)		//	getSplitConfig(splitPane,splitConfig);		//else			splitConfig.append(getBuffer().getPath());		return splitConfig.toString();	}	/**	 * Updates the borders of all gutters in this view to reflect the	 * currently focused text area.	 * @since jEdit 2.6final	 */	public void updateGutterBorders()	{		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)			editPanes[i].getTextArea().getGutter().updateBorder();	}	/**	 * Adds a tool bar to this view.	 * @param toolBar The tool bar	 */	public void addToolBar(Component toolBar)	{		toolBars.add(toolBar);		getRootPane().revalidate();	}	/**	 * Removes a tool bar from this view.	 * @param toolBar The tool bar	 */	public void removeToolBar(Component toolBar)	{		toolBars.remove(toolBar);		getRootPane().revalidate();	}	/**	 * Returns true if this view has been closed with	 * <code>jEdit.closeView()</code>.	 */	public boolean isClosed()	{		return closed;	}	/**	 * Shows the wait cursor and glass pane.	 */	public synchronized void showWaitCursor()	{		if(waitCount++ == 0)		{			// still needed even though glass pane			// has a wait cursor			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);			}		}	}	/**	 * Hides the wait cursor and glass pane.	 */	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);			}		}	}	/**	 * Returns if synchronized scrolling is enabled.	 * @since jEdit 2.7pre1	 */	public boolean isSynchroScrollEnabled()	{		return synchroScroll;	}	/**	 * Toggles synchronized scrolling.	 * @since jEdit 2.7pre2	 */	public void toggleSynchroScrollEnabled()	{		setSynchroScrollEnabled(!synchroScroll);	}	/**	 * Sets synchronized scrolling.	 * @since jEdit 2.7pre1	 */	public void setSynchroScrollEnabled(boolean synchroScroll)	{		this.synchroScroll = synchroScroll;		JEditTextArea textArea = getTextArea();

⌨️ 快捷键说明

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