📄 dockablewindowmanager.java
字号:
actionSet.addAction(new ToggleAction(name)); actionSet.addAction(new FloatAction(name)); String label = jEdit.getProperty(name + ".label"); if(label == null) label = "NO LABEL PROPERTY: " + name; String[] args = { label }; jEdit.setTemporaryProperty(name + ".label", label); jEdit.setTemporaryProperty(name + "-toggle.label", jEdit.getProperty( "view.docking.toggle.label",args)); jEdit.setTemporaryProperty(name + "-toggle.toggle","true"); jEdit.setTemporaryProperty(name + "-float.label", jEdit.getProperty( "view.docking.float.label",args)); } } //}}} //{{{ load() method void load() { if(loaded) return; loadDockableWindows(plugin,plugin.getDockablesURI(),null); } //}}} //{{{ createDockableWindow() method JComponent createDockableWindow(View view, String position) { load(); if(!loaded) { Log.log(Log.WARNING,this,"Outdated cache"); return null; } NameSpace nameSpace = new NameSpace( BeanShell.getNameSpace(), "DockableWindowManager.Factory" + ".createDockableWindow()"); try { nameSpace.setVariable( "position",position); } catch(UtilEvalError e) { Log.log(Log.ERROR,this,e); } JComponent win = (JComponent)BeanShell.eval(view, nameSpace,code); return win; } //}}} //{{{ OpenAction class static class OpenAction extends EditAction { private String dockable; //{{{ OpenAction constructor OpenAction(String name) { super(name); this.dockable = name; } //}}} //{{{ invoke() method public void invoke(View view) { view.getDockableWindowManager() .showDockableWindow(dockable); } //}}} //{{{ getCode() method public String getCode() { return "view.getDockableWindowManager()" + ".showDockableWindow(\"" + dockable + "\");"; } //}}} } //}}} //{{{ ToggleAction class static class ToggleAction extends EditAction { private String dockable; //{{{ ToggleAction constructor ToggleAction(String name) { super(name + "-toggle"); this.dockable = name; } //}}} //{{{ invoke() method public void invoke(View view) { view.getDockableWindowManager() .toggleDockableWindow(dockable); } //}}} //{{{ isSelected() method public boolean isSelected(View view) { return view.getDockableWindowManager() .isDockableWindowVisible(dockable); } //}}} //{{{ getCode() method public String getCode() { return "view.getDockableWindowManager()" + ".toggleDockableWindow(\"" + dockable + "\");"; } //}}} } //}}} //{{{ FloatAction class static class FloatAction extends EditAction { private String dockable; //{{{ FloatAction constructor FloatAction(String name) { super(name + "-float"); this.dockable = name; } //}}} //{{{ invoke() method public void invoke(View view) { view.getDockableWindowManager() .floatDockableWindow(dockable); } //}}} //{{{ getCode() method public String getCode() { return "view.getDockableWindowManager()" + ".floatDockableWindow(\"" + dockable + "\");"; } //}}} } //}}} } //}}} private static HashMap dockableWindowFactories; //{{{ Static initializer static { dockableWindowFactories = new HashMap(); } //}}} //}}} //{{{ Instance part of class //{{{ DockableWindowManager constructor /** * Creates a new dockable window manager. * @param view The view * @since jEdit 2.6pre3 */ public DockableWindowManager(View view, View.ViewConfig config) { setLayout(new DockableLayout()); this.view = view; windows = new Hashtable(); clones = new ArrayList(); top = new PanelWindowContainer(this,TOP,config.topPos); left = new PanelWindowContainer(this,LEFT,config.leftPos); bottom = new PanelWindowContainer(this,BOTTOM,config.bottomPos); right = new PanelWindowContainer(this,RIGHT,config.rightPos); add(DockableLayout.TOP_BUTTONS,top.buttonPanel); add(DockableLayout.LEFT_BUTTONS,left.buttonPanel); add(DockableLayout.BOTTOM_BUTTONS,bottom.buttonPanel); add(DockableLayout.RIGHT_BUTTONS,right.buttonPanel); add(TOP,top.dockablePanel); add(LEFT,left.dockablePanel); add(BOTTOM,bottom.dockablePanel); add(RIGHT,right.dockablePanel); } //}}} //{{{ init() method /** * Initialises dockable window manager. Do not call this method directly. */ public void init() { EditBus.addToBus(this); Iterator entries = dockableWindowFactories.values().iterator(); while(entries.hasNext()) addEntry((Factory)entries.next()); propertiesChanged(); } //}}} //{{{ getView() method /** * Returns this dockable window manager's view. * @since jEdit 4.0pre2 */ public View getView() { return view; } //}}} //{{{ floatDockableWindow() method /** * Opens a new instance of the specified dockable window in a floating * container. * @param name The dockable window name * @return The new dockable window instance * @since jEdit 4.1pre2 */ public JComponent floatDockableWindow(String name) { Entry entry = (Entry)windows.get(name); if(entry == null) { Log.log(Log.ERROR,this,"Unknown dockable window: " + name); return null; } // create a copy of this dockable window and float it Entry newEntry = new Entry(entry.factory,FLOATING); newEntry.win = newEntry.factory.createDockableWindow(view,FLOATING); if(newEntry.win != null) { newEntry.container = new FloatingWindowContainer(this,true); newEntry.container.register(newEntry); newEntry.container.show(newEntry); } clones.add(newEntry); return newEntry.win; } //}}} //{{{ showDockableWindow() method /** * Opens the specified dockable window. * @param name The dockable window name * @since jEdit 2.6pre3 */ public void showDockableWindow(String name) { Entry entry = (Entry)windows.get(name); if(entry == null) { Log.log(Log.ERROR,this,"Unknown dockable window: " + name); return; } if(entry.win == null) { entry.win = entry.factory.createDockableWindow( view,entry.position); } if(entry.win != null) { if(entry.position.equals(FLOATING) && entry.container == null) { entry.container = new FloatingWindowContainer( this,view.isPlainView()); entry.container.register(entry); } entry.container.show(entry); } else /* an error occurred */; } //}}} //{{{ addDockableWindow() method /** * Opens the specified dockable window. As of jEdit 4.0pre1, has the * same effect as calling showDockableWindow(). * @param name The dockable window name * @since jEdit 2.6pre3 */ public void addDockableWindow(String name) { showDockableWindow(name); } //}}} //{{{ hideDockableWindow() method /** * Hides the specified dockable window. * @param name The dockable window name * @since jEdit 2.6pre3 */ public void hideDockableWindow(String name) { Entry entry = (Entry)windows.get(name); if(entry == null) { Log.log(Log.ERROR,this,"Unknown dockable window: " + name); return; } if(entry.win == null) return; entry.container.show(null); } //}}} //{{{ removeDockableWindow() method /** * Hides the specified dockable window. As of jEdit 4.2pre1, has the * same effect as calling hideDockableWindow(). * @param name The dockable window name * @since jEdit 4.2pre1 */ public void removeDockableWindow(String name) { hideDockableWindow(name); } //}}} //{{{ toggleDockableWindow() method /** * Toggles the visibility of the specified dockable window. * @param name The dockable window name */ public void toggleDockableWindow(String name) { if(isDockableWindowVisible(name)) removeDockableWindow(name); else addDockableWindow(name); } //}}} //{{{ getDockableWindow() method /** * Returns the specified dockable window. * * Note that this method * will return null if the dockable has not been added yet. * Make sure you call {@link #addDockableWindow(String)} first. * * @param name The name of the dockable window * @since jEdit 4.1pre2 */ public JComponent getDockableWindow(String name) { return getDockable(name); } //}}} //{{{ getDockable() method /** * Returns the specified dockable window. * * Note that this method * will return null if the dockable has not been added yet. * Make sure you call {@link #addDockableWindow(String)} first. * * For historical reasons, this * does the same thing as {@link #getDockableWindow(String)}. * * @param name The name of the dockable window * @since jEdit 4.0pre1 */ public JComponent getDockable(String name) { Entry entry = (Entry)windows.get(name); if(entry == null || entry.win == null) return null; else return entry.win; } //}}} //{{{ getDockableTitle() method /** * Returns the title of the specified dockable window. * @param name The name of the dockable window. * @since jEdit 4.1pre5 */ public String getDockableTitle(String name) { String title = jEdit.getProperty(name + ".title"); if(title == null) return "NO TITLE PROPERTY: " + name; else return title; } //}}} //{{{ isDockableWindowVisible() method /** * Returns if the specified dockable window is visible. * @param name The dockable window name */ public boolean isDockableWindowVisible(String name) { Entry entry = (Entry)windows.get(name); if(entry == null || entry.win == null) return false; else return entry.container.isVisible(entry); } //}}} //{{{ isDockableWindowDocked() method /** * Returns if the specified dockable window is docked into the * view. * @param name The dockable's name * @since jEdit 4.0pre2 */ public boolean isDockableWindowDocked(String name) { Entry entry = (Entry)windows.get(name); if(entry == null) return false; else return !entry.position.equals(FLOATING); } //}}} //{{{ closeCurrentArea() method /** * Closes the currently focused docking area. * @since jEdit 4.1pre3 */ public void closeCurrentArea() { // I don't know of any other way to fix this, since invoking this // command from a menu results in the focus owner being the menu // until the menu goes away. SwingUtilities.invokeLater(new Runnable() { public void run() { Component comp = view.getFocusOwner(); while(comp != null) { //System.err.println(comp.getClass()); if(comp instanceof PanelWindowContainer .DockablePanel) { PanelWindowContainer container = ((PanelWindowContainer.DockablePanel) comp).getWindowContainer(); container.show(null); return; } comp = comp.getParent(); } getToolkit().beep(); } }); } //}}} //{{{ close() method /** * Called when the view is being closed. * @since jEdit 2.6pre3 */ public void close() { EditBus.removeFromBus(this); Iterator iter = windows.values().iterator(); while(iter.hasNext())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -