/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/commands/makeWorkspace.bsh
Unknown | 138 lines | 117 code | 21 blank | 0 comment | 0 complexity | b66b9bddac54737ee63906d7aec5b1aa MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /**
- * Creates a JConsole in a JInternalFrame and adds it to the desktop
- *
- * @return this (the workspace scripted object for allowing access to the
- * frame, interpreter, etc.)
- *
- * @author Pat Niemeyer
- * @author Daniel Leuck (bug fixes)
- */
- import javax.swing.*;
- import org.gjt.sp.jedit.bsh.Interpreter;
- import org.gjt.sp.jedit.bsh.BshClassManager;
- import org.gjt.sp.jedit.bsh.ClassPathException;
- import org.gjt.sp.jedit.bsh.util.JConsole;
- import org.gjt.sp.jedit.bsh.util.NameCompletionTable;
- makeWorkspace( String name )
- {
- if ( bsh.system.desktop == void ) {
- print("No desktop...");
- return;
- }
- this.console = new JConsole();
- this.name="Bsh Workspace: "+name;
- this.interpreter = new Interpreter( console );
- // provide name completion for console, name source is global namespace
- // move this into JConsole?
- // Access to read classpath is protected
- try {
- this.nct = new NameCompletionTable();
- nct.add( interpreter.getNameSpace() );
- try {
- this.bcm = this.caller.namespace.getClassManager();
- if ( bcm != null ) {
- classNamesSource = bcm.getClassPath();
- nct.add( classNamesSource );
- }
- } catch ( ClassPathException e ) {
- error("classpath exception in name compl:"+e);
- }
- console.setNameCompletion( nct );
- // end setup name completion
- } catch ( SecurityException e ) { }
- // for convenience and backwards compatability
- interpreter.set( "bsh.desktop", bsh.system.desktop );
- this.frame = bsh.system.desktop.makeInternalFrame( name );
- frame.frameIcon=bsh.system.icons.workspace;
-
- /*
- Notes: Careful not to print anything before returning sys io...
- console is now gone.
- */
- internalFrameClosing( e ) {
- if ( haveSysIO )
- returnSysIO();
- }
- internalFrameActivated(ife) {}
- internalFrameDeactivated(ife) {}
- internalFrameClosed(ife) {}
- internalFrameOpened(ife) {}
- internalFrameIconified(ife) {}
- internalFrameDeiconified(ife) {}
-
- frame.addInternalFrameListener(this);
- actionPerformed( e )
- {
- this.com = e.getActionCommand();
- if ( com.equals("Workspace Editor") )
- workspaceEditor( interpreter, name );
- else if ( com.equals("Capture System in/out/err") )
- captureSysIO();
- else if ( com.equals("Close") ) {
- frame.setClosed(true);
- }
- }
- this.menubar = new JMenuBar();
- this.menu=new JMenu("File");
- this.mi=new JMenuItem("Workspace Editor");
- mi.addActionListener(this);
- menu.add(mi);
- mi=new JMenuItem("Capture System in/out/err");
- mi.addActionListener(this);
- menu.add(mi);
- mi=new JMenuItem("Close");
- mi.addActionListener(this);
- menu.add(mi);
- menubar.add(menu);
- menu = fontMenu(console);
- menubar.add(menu);
- frame.setMenuBar(menubar);
- frame.getContentPane().add("Center", console);
- //frame.pack();
- this.thread = new Thread( interpreter );
- thread.start();
- frame.setBounds(5,5,600,300);
- // cascade windows?
- //off=bsh.system.desktop.windowCount*10;
- //frame.setLocation( off, off );
- //frame.validate();
- bsh.system.desktop.addInternalFrame( frame );
- frame.toFront();
- frame.setSelected(true);
- this.haveSysIO=false;
- this.sysIn = System.in;
- this.sysOut = System.out;
- this.sysErr = System.err;
- captureSysIO() {
- super.haveSysIO = true; // old scoping rules
- System.setIn( console.getInputStream() );
- System.setOut( console.getOut() );
- System.setErr( console.getErr() );
- }
- returnSysIO() {
- super.haveSysIO = false; // old scoping rules
- System.setIn( sysIn );
- System.setOut( sysOut );
- System.setErr( sysErr );
- }
- return this;
- }