📄 view.java
字号:
/* * 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.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.*;//}}}/** * 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 calls * the {@link EditPlugin#createMenuItems(Vector)} method of * each plugin core 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.56 2003/02/20 22:17:14 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_STATUS_BAR_LAYER = -50; /** * @deprecated Status bar no longer added as a tool bar. */ public static final int STATUS_BAR_LAYER = -100; /** * @deprecated Status bar no longer added as a tool bar. */ 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 3.2.1 */ public JToolBar 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) { if(toolBar instanceof SearchBar) searchBar = (SearchBar)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) { if(toolBar == searchBar) searchBar = null; 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. */ 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; } //}}} //{{{ 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; } //}}} //}}} //{{{ 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) { if(isClosed()) return; if(getFocusOwner() instanceof JComponent) { JComponent comp = (JComponent)getFocusOwner(); InputMap map = comp.getInputMap(); ActionMap am = comp.getActionMap(); if(map != null && am != null && comp.isEnabled()) { Object binding = map.get(KeyStroke.getKeyStrokeForEvent(evt)); if(binding != null && am.get(binding) != null) { return; } } } if(getFocusOwner() instanceof JTextComponent) { // fix for the bug where key events in JTextComponents // inside views are also handled by the input handler if(evt.getID() == KeyEvent.KEY_PRESSED) { switch(evt.getKeyCode()) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_TAB: case KeyEvent.VK_ENTER: return; } } } if(evt.isConsumed()) return; evt = KeyEventWorkaround.processKeyEvent(evt); if(evt == null) return; switch(evt.getID()) { case KeyEvent.KEY_TYPED: // Handled in text area if(keyEventInterceptor != null) /* keyEventInterceptor.keyTyped(evt) */; else if(inputHandler.isPrefixActive() && !getTextArea().hasFocus()) inputHandler.keyTyped(evt); break; case KeyEvent.KEY_PRESSED: if(keyEventInterceptor != null) keyEventInterceptor.keyPressed(evt); else inputHandler.keyPressed(evt); break; case KeyEvent.KEY_RELEASED: if(keyEventInterceptor != null) keyEventInterceptor.keyReleased(evt); else inputHandler.keyReleased(evt); break; } if(!evt.isConsumed()) super.processKeyEvent(evt); } //}}} //}}} //{{{ Buffers, edit panes, split panes //{{{ splitHorizontally() method /** * Splits the view horizontally. * @since jEdit 4.1pre2 */ public EditPane splitHorizontally() { return split(JSplitPane.VERTICAL_SPLIT); } //}}} //{{{ splitVertically() method /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -