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

📄 view.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		toolBarManager = new ToolBarManager(topToolBars, bottomToolBars);		status = new StatusBar(this);		inputHandler = new DefaultInputHandler(this,(DefaultInputHandler)			jEdit.getInputHandler());		try		{			Component comp = restoreSplitConfig(buffer,config.splitConfig);			dockableWindowManager.add(comp,0);		}		catch(IOException e)		{			// this should never throw an exception.			throw new InternalError();		}		getContentPane().add(BorderLayout.CENTER,dockableWindowManager);		dockableWindowManager.init();		// tool bar and status bar gets added in propertiesChanged()		// depending in the 'tool bar alternate layout' setting.		propertiesChanged();		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);		addWindowListener(new WindowHandler());		EditBus.addToBus(this);		SearchDialog.preloadSearchDialog(this);	} //}}}	//{{{ close() method	void close()	{		GUIUtilities.saveGeometry(this,plainView ? "plain-view" : "view");		closed = true;		// save dockable window geometry, and close 'em		dockableWindowManager.close();		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.		toolBarManager = null;		toolBar = null;		searchBar = null;		splitPane = null;		inputHandler = null;		recorder = null;		getContentPane().removeAll();		// notify clients with -wait		if(waitSocket != null)		{			try			{				waitSocket.getOutputStream().write('\0');				waitSocket.getOutputStream().flush();				waitSocket.getInputStream().close();				waitSocket.getOutputStream().close();				waitSocket.close();			}			catch(IOException io)			{				//Log.log(Log.ERROR,this,io);			}		}	} //}}}	//{{{ updateTitle() method	/**	 * 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());			if(buffer.isDirty())				title.append(jEdit.getProperty("view.title.dirty"));		}		setTitle(title.toString());	} //}}}	//}}}	//{{{ Private members	//{{{ Instance variables	private boolean closed;	private DockableWindowManager dockableWindowManager;	private JPanel topToolBars;	private JPanel bottomToolBars;	private ToolBarManager toolBarManager;	private Box toolBar;	private SearchBar searchBar;	private ActionBar actionBar;	private EditPane editPane;	private JSplitPane splitPane;	private StatusBar status;	private KeyListener keyEventInterceptor;	private InputHandler inputHandler;	private Macros.Recorder recorder;	private Component prefixFocusOwner;	private int waitCount;	private boolean showFullPath;	private boolean plainView;	private Socket waitSocket;	//}}}	//{{{ getEditPanes() method	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());		}	} //}}}	//{{{ getSplitConfig() method	/*	 * The split config is recorded in a simple RPN "language".	 */	private void getSplitConfig(JSplitPane splitPane,		StringBuffer splitConfig)	{		Component right = splitPane.getRightComponent();		if(right instanceof JSplitPane)			getSplitConfig((JSplitPane)right,splitConfig);		else		{			splitConfig.append('"');			splitConfig.append(MiscUtilities.charsToEscapes(				((EditPane)right).getBuffer().getPath()));			splitConfig.append("\" buffer");		}		splitConfig.append(' ');		Component left = splitPane.getLeftComponent();		if(left instanceof JSplitPane)			getSplitConfig((JSplitPane)left,splitConfig);		else		{			splitConfig.append('"');			splitConfig.append(MiscUtilities.charsToEscapes(				((EditPane)left).getBuffer().getPath()));			splitConfig.append("\" buffer");		}		splitConfig.append(' ');		splitConfig.append(splitPane.getDividerLocation());		splitConfig.append(' ');		splitConfig.append(splitPane.getOrientation()			== JSplitPane.VERTICAL_SPLIT ? "vertical" : "horizontal");	} //}}}	//{{{ restoreSplitConfig() method	private Component restoreSplitConfig(Buffer buffer, String splitConfig)		throws IOException	// this is where checked exceptions piss me off. this method only uses	// a StringReader which can never throw an exception...	{		if(buffer != null)			return (editPane = createEditPane(buffer));		else if(splitConfig == null)			return (editPane = createEditPane(jEdit.getFirstBuffer()));		Buffer[] buffers = jEdit.getBuffers();		Stack stack = new Stack();		// we create a stream tokenizer for parsing a simple		// stack-based language		StreamTokenizer st = new StreamTokenizer(new StringReader(			splitConfig));		st.whitespaceChars(0,' ');		/* all printable ASCII characters */		st.wordChars('#','~');		st.commentChar('!');		st.quoteChar('"');		st.eolIsSignificant(false);loop:		for(;;)		{			switch(st.nextToken())			{			case StreamTokenizer.TT_EOF:				break loop;			case StreamTokenizer.TT_WORD:				if(st.sval.equals("vertical") ||					st.sval.equals("horizontal"))				{					int orientation						= (st.sval.equals("vertical")						? JSplitPane.VERTICAL_SPLIT						: JSplitPane.HORIZONTAL_SPLIT);					int divider = ((Integer)stack.pop())						.intValue();					stack.push(splitPane = new JSplitPane(						orientation,						(Component)stack.pop(),						(Component)stack.pop()));					splitPane.setOneTouchExpandable(true);					splitPane.setBorder(null);					splitPane.setMinimumSize(						new Dimension(0,0));					splitPane.setDividerLocation(divider);				}				else if(st.sval.equals("buffer"))				{					Object obj = stack.pop();					if(obj instanceof Integer)					{						int index = ((Integer)obj).intValue();						if(index >= 0 && index < buffers.length)							buffer = buffers[index];					}					else if(obj instanceof String)					{						String path = (String)obj;						buffer = jEdit.getBuffer(path);					}					if(buffer == null)						buffer = jEdit.getFirstBuffer();					stack.push(editPane = createEditPane(						buffer));				}				break;			case StreamTokenizer.TT_NUMBER:				stack.push(new Integer((int)st.nval));				break;			case '"':				stack.push(st.sval);				break;			}		}		updateGutterBorders();		return (Component)stack.peek();	} //}}}	//{{{ propertiesChanged() method	/**	 * Reloads various settings from the properties.	 */	private void propertiesChanged()	{		setJMenuBar(GUIUtilities.loadMenuBar("view.mbar"));		loadToolBars();		showFullPath = jEdit.getBooleanProperty("view.showFullPath");		updateTitle();		status.propertiesChanged();		removeToolBar(status);		getContentPane().remove(status);		if(jEdit.getBooleanProperty("view.toolbar.alternateLayout"))		{			getContentPane().add(BorderLayout.NORTH,topToolBars);			getContentPane().add(BorderLayout.SOUTH,bottomToolBars);			if(!plainView && jEdit.getBooleanProperty("view.status.visible"))				addToolBar(BOTTOM_GROUP,STATUS_BAR_LAYER,status);		}		else		{			dockableWindowManager.add(topToolBars,				DockableWindowManager.DockableLayout				.TOP_TOOLBARS,0);			dockableWindowManager.add(bottomToolBars,				DockableWindowManager.DockableLayout				.BOTTOM_TOOLBARS,0);			if(!plainView && jEdit.getBooleanProperty("view.status.visible"))				getContentPane().add(BorderLayout.SOUTH,status);		}		getRootPane().revalidate();		//SwingUtilities.updateComponentTreeUI(getRootPane());	} //}}}	//{{{ loadToolBars() method	private void loadToolBars()	{		if(jEdit.getBooleanProperty("view.showToolbar") && !plainView)		{			if(toolBar != null)				toolBarManager.removeToolBar(toolBar);			toolBar = GUIUtilities.loadToolBar("view.toolbar");			addToolBar(TOP_GROUP, SYSTEM_BAR_LAYER, toolBar);		}		else if(toolBar != null)		{			removeToolBar(toolBar);			toolBar = null;		}		if(searchBar != null)			removeToolBar(searchBar);		if(jEdit.getBooleanProperty("view.showSearchbar") && !plainView)		{			if(searchBar == null)				searchBar = new SearchBar(this,false);			searchBar.propertiesChanged();			addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);		}	} //}}}	//{{{ createEditPane() method	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;	} //}}}	//{{{ setEditPane() method	private void setEditPane(EditPane editPane)	{		this.editPane = editPane;		status.updateCaretStatus();		status.updateBufferStatus();		status.updateMiscStatus();		// repaint the gutter so that the border color		// reflects the focus state		updateGutterBorders();		EditBus.send(new ViewUpdate(this,ViewUpdate.EDIT_PANE_CHANGED));	} //}}}	//{{{ handleBufferUpdate() method	private void handleBufferUpdate(BufferUpdate msg)	{		Buffer buffer = msg.getBuffer();		if(msg.getWhat() == BufferUpdate.DIRTY_CHANGED			|| msg.getWhat() == BufferUpdate.LOADED)		{			EditPane[] editPanes = getEditPanes();			for(int i = 0; i < editPanes.length; i++)			{				if(editPanes[i].getBuffer() == buffer)				{					updateTitle();					break;				}			}		}	} //}}}	//{{{ handleEditPaneUpdate() method	private void handleEditPaneUpdate(EditPaneUpdate msg)	{		EditPane editPane = msg.getEditPane();		if(editPane.getView() == this			&& msg.getWhat() == EditPaneUpdate.BUFFER_CHANGED			&& editPane.getBuffer().isLoaded())		{			status.updateCaretStatus();			status.updateBufferStatus();			status.updateMiscStatus();		}	} //}}}	//{{{ updateGutterBorders() method	/**	 * Updates the borders of all gutters in this view to reflect the	 * currently focused text area.	 * @since jEdit 2.6final	 */	private void updateGutterBorders()	{		EditPane[] editPanes = getEditPanes();		for(int i = 0; i < editPanes.length; i++)			editPanes[i].getTextArea().getGutter().updateBorder();	} //}}}	//{{{ _preprocessKeyEvent() method	private KeyEvent _preprocessKeyEvent(KeyEvent evt)	{		if(isClosed())			return null;		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 null;				}			}		}		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_ENTER:				case KeyEvent.VK_TAB:				case KeyEvent.VK_BACK_SPACE:				case KeyEvent.VK_SPACE:					return null;				}			}		}		if(evt.isConsumed())			return null;		return KeyEventWorkaround.processKeyEvent(evt);	} //}}}	//}}}	//{{{ Inner classes	//{{{ CaretHandler class	class CaretHandler implements CaretListener	{		public void caretUpdate(CaretEvent evt)		{			if(evt.getSource() == getTextArea())				status.updateCaretStatus();		}	} //}}}	//{{{ FocusHandler class	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();			}			if(comp != editPane)				setEditPane((EditPane)comp);			else				updateGutterBorders();		}	} //}}}	//{{{ ScrollHandler class	class ScrollHandler implements ScrollListener	{		public void scrolledVertically(JEditTextArea textArea)		{			if(getTextArea() == textArea)				status.updateCaretStatus();		}		public void scrolledHorizontally(JEditTextArea textArea) {}	} //}}}	//{{{ WindowHandler class	class WindowHandler extends WindowAdapter	{		public void windowActivated(WindowEvent evt)		{			jEdit.setActiveView(View.this);			// 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()				{					jEdit.checkBufferStatus(View.this);				}			});		}		public void windowClosing(WindowEvent evt)		{			jEdit.closeView(View.this);		}	} //}}}	//{{{ ViewConfig class	public static class ViewConfig	{		public boolean plainView;		public String splitConfig;		public int x, y, width, height, extState;		// dockables		public String top, left, bottom, right;		public int topPos, leftPos, bottomPos, rightPos;		public ViewConfig()		{		}		public ViewConfig(boolean plainView)		{			this.plainView = plainView;			String prefix = (plainView ? "plain-view" : "view");			x = jEdit.getIntegerProperty(prefix + ".x",0);			y = jEdit.getIntegerProperty(prefix + ".y",0);			width = jEdit.getIntegerProperty(prefix + ".width",0);			height = jEdit.getIntegerProperty(prefix + ".height",0);		}		public ViewConfig(boolean plainView, String splitConfig,			int x, int y, int width, int height, int extState)		{			this.plainView = plainView;			this.splitConfig = splitConfig;			this.x = x;			this.y = y;			this.width = width;			this.height = height;			this.extState = extState;		}	} //}}}	//}}}}

⌨️ 快捷键说明

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