📄 view.java
字号:
{ return next; } //}}} //{{{ getPrev() method /** * Returns the previous view in the list. */ public View getPrev() { return prev; } //}}} //{{{ handleMessage() method 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); } //}}} //{{{ getMinimumSize() method public Dimension getMinimumSize() { return new Dimension(0,0); } //}}} //{{{ Package-private members View prev; View next; //{{{ View constructor View(Buffer buffer, String splitConfig, boolean plainView) { this.plainView = plainView; enableEvents(AWTEvent.KEY_EVENT_MASK); setIconImage(GUIUtilities.getEditorIcon()); dockableWindowManager = new DockableWindowManager(this); topToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1)); bottomToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1)); toolBarManager = new ToolBarManager(topToolBars, bottomToolBars); status = new StatusBar(this); setJMenuBar(GUIUtilities.loadMenuBar("view.mbar")); inputHandler = new DefaultInputHandler(this,(DefaultInputHandler) jEdit.getInputHandler()); Component comp = restoreSplitConfig(buffer,splitConfig); dockableWindowManager.add(comp); EditBus.addToBus(this); getContentPane().add(BorderLayout.CENTER,dockableWindowManager); // 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()); dockableWindowManager.init(); } //}}} //{{{ close() method void close() { closed = true; // save dockable window geometry, and close 'em dockableWindowManager.close(); GUIUtilities.saveGeometry(this,(plainView ? "plain-view" : "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. toolBarManager = null; toolBar = null; searchBar = null; splitPane = null; inputHandler = null; recorder = null; getContentPane().removeAll(); } //}}} //{{{ 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()); } setTitle(title.toString()); } //}}} //}}} //{{{ Private members //{{{ Instance variables private boolean closed; private DockableWindowManager dockableWindowManager; private JPanel topToolBars; private JPanel bottomToolBars; private ToolBarManager toolBarManager; 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 boolean plainView; //}}} //{{{ 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": * "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"); } //}}} //{{{ restoreSplitConfig() method 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(); } //}}} //{{{ propertiesChanged() method /** * Reloads various settings from the properties. */ private void propertiesChanged() { loadToolBars(); showFullPath = jEdit.getBooleanProperty("view.showFullPath"); updateTitle(); dockableWindowManager.propertiesChanged(); 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(DockableWindowManager.DockableLayout .TOP_TOOLBARS,topToolBars); dockableWindowManager.add(DockableWindowManager.DockableLayout .BOTTOM_TOOLBARS,bottomToolBars); 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(jEdit.getBooleanProperty("view.showSearchbar") && !plainView) { if(searchBar != null) removeToolBar(searchBar); addToolBar(TOP_GROUP,SEARCH_BAR_LAYER, new SearchBar(this,false)); } else if(searchBar != null) { removeToolBar(searchBar); searchBar = null; } } //}}} //{{{ 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(); 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) { 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; } } } } } //}}} //{{{ 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(); } } //}}} //}}} //{{{ 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); } } //}}} //{{{ 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); 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(editPane); } } }); } public void windowClosing(WindowEvent evt) { jEdit.closeView(View.this); } } //}}} //}}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -