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

📄 view.java

📁 Java写的文本编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		int firstLine = textArea.getFirstLine();		int horizontalOffset = textArea.getHorizontalOffset();		synchroScrollVertical(textArea,firstLine);		synchroScrollHorizontal(textArea,horizontalOffset);	}	/**	 * Sets the first line of all text areas.	 * @param textArea The text area that is propagating this change	 * @param firstLine The first line	 * @since jEdit 2.7pre1	 */	public void synchroScrollVertical(JEditTextArea textArea, int firstLine)	{		if(!synchroScroll)			return;		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)		{			if(editPanes[i].getTextArea() != textArea)				editPanes[i].getTextArea()._setFirstLine(firstLine);		}	}	/**	 * Sets the horizontal offset of all text areas.	 * @param textArea The text area that is propagating this change	 * @param horizontalOffset The horizontal offset	 * @since jEdit 2.7pre1	 */	public void synchroScrollHorizontal(JEditTextArea textArea, int horizontalOffset)	{		if(!synchroScroll)			return;		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)		{			if(editPanes[i].getTextArea() != textArea)				editPanes[i].getTextArea()._setHorizontalOffset(horizontalOffset);		}	}	/**	 * Returns the next view in the list.	 */	public View getNext()	{		return next;	}	/**	 * Returns the previous view in the list.	 */	public View getPrev()	{		return prev;	}	public void handleMessage(EBMessage msg)	{		if(msg instanceof PropertiesChanged)			propertiesChanged();		else if(msg instanceof SearchSettingsChanged)		{			if(searchBar != null)				searchBar.update();		}		else if(msg instanceof BufferUpdate)			handleBufferUpdate((BufferUpdate)msg);		else if(msg instanceof EditPaneUpdate)			handleEditPaneUpdate((EditPaneUpdate)msg);	}	/**	 * 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;		// JTextComponents don't consume events...		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;				}			}			Keymap keymap = ((JTextComponent)getFocusOwner())				.getKeymap();			if(keymap.getAction(KeyStroke.getKeyStrokeForEvent(evt)) != null)				return;		}		if(evt.isConsumed())			return;		evt = KeyEventWorkaround.processKeyEvent(evt);		if(evt == null)			return;		switch(evt.getID())		{		case KeyEvent.KEY_TYPED:			if(keyEventInterceptor != null)				keyEventInterceptor.keyTyped(evt);			else if(inputHandler.isPrefixActive())				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);	}	// package-private members	View prev;	View next;	View(Buffer buffer, String splitConfig)	{		setIconImage(GUIUtilities.getEditorIcon());		dockableWindowManager = new DockableWindowManager(this);		Component comp = restoreSplitConfig(buffer,splitConfig);		dockableWindowManager.add(comp);		EditBus.addToBus(this);		setJMenuBar(GUIUtilities.loadMenuBar("view.mbar"));		toolBars = new Box(BoxLayout.Y_AXIS);		inputHandler = new DefaultInputHandler(this,(DefaultInputHandler)			jEdit.getInputHandler());		propertiesChanged();		getContentPane().add(BorderLayout.NORTH,toolBars);		getContentPane().add(BorderLayout.CENTER,dockableWindowManager);		getContentPane().add(BorderLayout.SOUTH,status = new StatusBar(this));		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);		addWindowListener(new WindowHandler());		dockableWindowManager.init();	}	void close()	{		closed = true;		// save dockable window geometry, and close 'em		dockableWindowManager.close();		GUIUtilities.saveGeometry(this,"view");		EditBus.removeFromBus(this);		dispose();		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)			editPanes[i].close();		// null some variables so that retaining references		// to closed views won't hurt as much.		toolBars = null;		toolBar = null;		searchBar = null;		splitPane = null;		inputHandler = null;		recorder = null;		setContentPane(new JPanel());	}	/**	 * Updates the title bar.	 */	void updateTitle()	{		Vector buffers = new Vector();		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)		{			Buffer buffer = editPanes[i].getBuffer();			if(buffers.indexOf(buffer) == -1)				buffers.addElement(buffer);		}		StringBuffer title = new StringBuffer(jEdit.getProperty("view.title"));		for(int i = 0; i < buffers.size(); i++)		{			if(i != 0)				title.append(", ");			Buffer buffer = (Buffer)buffers.elementAt(i);			title.append((showFullPath && !buffer.isNewFile())				? buffer.getPath() : buffer.getName());		}		setTitle(title.toString());	}	// private members	private boolean closed;	private DockableWindowManager dockableWindowManager;	private Box toolBars;	private JToolBar toolBar;	private SearchBar searchBar;	private boolean synchroScroll;	private EditPane editPane;	private JSplitPane splitPane;	private StatusBar status;	private KeyListener keyEventInterceptor;	private InputHandler inputHandler;	private Macros.Recorder recorder;	private int waitCount;	private boolean showFullPath;	private void getEditPanes(Vector vec, Component comp)	{		if(comp instanceof EditPane)			vec.addElement(comp);		else if(comp instanceof JSplitPane)		{			JSplitPane split = (JSplitPane)comp;			getEditPanes(vec,split.getLeftComponent());			getEditPanes(vec,split.getRightComponent());		}	}	/*	 * The split config is recorded in a simple RPN "language":	 * "vertical" pops the two topmost elements off the stack, creates a	 * vertical split	 * "horizontal" pops the two topmost elements off the stack, creates a	 * horizontal split	 * A path name creates an edit pane editing that buffer	 */	private void getSplitConfig(JSplitPane splitPane,		StringBuffer splitConfig)	{		Component left = splitPane.getLeftComponent();		if(left instanceof JSplitPane)			getSplitConfig((JSplitPane)left,splitConfig);		else		{			splitConfig.append('\t');			splitConfig.append(((EditPane)left).getBuffer().getPath());		}		Component right = splitPane.getRightComponent();		if(right instanceof JSplitPane)			getSplitConfig((JSplitPane)right,splitConfig);		else		{			splitConfig.append('\t');			splitConfig.append(((EditPane)right).getBuffer().getPath());		}		splitConfig.append(splitPane.getOrientation()			== JSplitPane.VERTICAL_SPLIT ? "\tvertical" : "\thorizontal");	}	private Component restoreSplitConfig(Buffer buffer, String splitConfig)	{		if(buffer != null)			return (editPane = createEditPane(buffer));		else if(splitConfig == null)			return (editPane = createEditPane(jEdit.getFirstBuffer()));		Stack stack = new Stack();		StringTokenizer st = new StringTokenizer(splitConfig,"\t");		while(st.hasMoreTokens())		{			String token = st.nextToken();			if(token.equals("vertical"))			{				stack.push(splitPane = new JSplitPane(					JSplitPane.VERTICAL_SPLIT,					(Component)stack.pop(),					(Component)stack.pop()));				splitPane.setBorder(null);				splitPane.setDividerLocation(0.5);			}			else if(token.equals("horizontal"))			{				stack.push(splitPane = new JSplitPane(					JSplitPane.HORIZONTAL_SPLIT,					(Component)stack.pop(),					(Component)stack.pop()));				splitPane.setBorder(null);				splitPane.setDividerLocation(0.5);			}			else			{				buffer = jEdit.getBuffer(token);				if(buffer == null)					buffer = jEdit.getFirstBuffer();				stack.push(editPane = createEditPane(buffer));			}		}		return (Component)stack.peek();	}	/**	 * Reloads various settings from the properties.	 */	private void propertiesChanged()	{		loadToolBars();		showFullPath = jEdit.getBooleanProperty("view.showFullPath");		updateTitle();		dockableWindowManager.propertiesChanged();		SwingUtilities.updateComponentTreeUI(getRootPane());	}	private void loadToolBars()	{		if(jEdit.getBooleanProperty("view.showToolbar"))		{			if(toolBar != null)				toolBars.remove(toolBar);			toolBar = GUIUtilities.loadToolBar("view.toolbar");			toolBar.add(Box.createGlue());			toolBars.add(toolBar,0);			getRootPane().revalidate();		}		else if(toolBar != null)		{			removeToolBar(toolBar);			toolBar = null;		}		if(jEdit.getBooleanProperty("view.showSearchbar"))		{			if(searchBar == null)			{				searchBar = new SearchBar(this);				addToolBar(searchBar);			}		}		else if(searchBar != null)		{			removeToolBar(searchBar);			searchBar = null;		}	}	private EditPane createEditPane(Buffer buffer)	{		EditPane editPane = new EditPane(this,buffer);		JEditTextArea textArea = editPane.getTextArea();		textArea.addFocusListener(new FocusHandler());		textArea.addCaretListener(new CaretHandler());		textArea.addScrollListener(new ScrollHandler());		EditBus.send(new EditPaneUpdate(editPane,EditPaneUpdate.CREATED));		return editPane;	}	private void setEditPane(EditPane editPane)	{		this.editPane = editPane;		status.repaintCaretStatus();		status.updateBufferStatus();		status.updateMiscStatus();	}	private void handleBufferUpdate(BufferUpdate msg)	{		Buffer buffer = msg.getBuffer();		if(msg.getWhat() == BufferUpdate.DIRTY_CHANGED)		{			if(!buffer.isDirty())			{				// have to update title after each save				// in case it was a 'save as'				EditPane[] editPanes = getEditPanes();				for(int i = 0; i < editPanes.length; i++)				{					if(editPanes[i].getBuffer() == buffer)					{						updateTitle();						break;					}				}			}		}	}	private void handleEditPaneUpdate(EditPaneUpdate msg)	{		if(msg.getEditPane().getView() == this			&& msg.getWhat() == EditPaneUpdate.BUFFER_CHANGED)		{			status.repaintCaretStatus();			status.updateBufferStatus();			status.updateMiscStatus();			status.updateFoldStatus();		}	}	class CaretHandler implements CaretListener	{		public void caretUpdate(CaretEvent evt)		{			status.repaintCaretStatus();			status.updateMiscStatus();		}	}	class FocusHandler extends FocusAdapter	{		public void focusGained(FocusEvent evt)		{			// walk up hierarchy, looking for an EditPane			Component comp = (Component)evt.getSource();			while(!(comp instanceof EditPane))			{				if(comp == null)					return;				comp = comp.getParent();			}			setEditPane((EditPane)comp);		}	}	class ScrollHandler implements ScrollListener	{		public void scrolledVertically(JEditTextArea textArea)		{			if(getTextArea() == textArea)				status.repaintCaretStatus();		}		public void scrolledHorizontally(JEditTextArea textArea) {}	}	class WindowHandler extends WindowAdapter	{		boolean gotFocus;		public void windowActivated(WindowEvent evt)		{			if(!gotFocus)			{				editPane.focusOnTextArea();				gotFocus = true;			}			final Vector buffers = new Vector();			EditPane[] editPanes = getEditPanes();			for(int i = 0; i < editPanes.length; i++)			{				Buffer buffer = ((EditPane)editPanes[i])					.getBuffer();				if(buffers.contains(buffer))					continue;				else					buffers.addElement(buffer);			}			// People have reported hangs with JDK 1.4; might be			// caused by modal dialogs being displayed from			// windowActivated()			SwingUtilities.invokeLater(new Runnable()			{				public void run()				{					for(int i = 0; i < buffers.size(); i++)					{						((Buffer)buffers.elementAt(i))							.checkModTime(View.this);					}				}			});		}		public void windowClosing(WindowEvent evt)		{			jEdit.closeView(View.this);		}	}}

⌨️ 快捷键说明

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