PageRenderTime 85ms CodeModel.GetById 81ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/commands/makeWorkspace.bsh

#
Unknown | 134 lines | 113 code | 21 blank | 0 comment | 0 complexity | 924dc4868f201c7049a3e01d779e279d MD5 | raw file
  1/**
  2 * Creates a JConsole in a JInternalFrame and adds it to the desktop 
  3 *
  4 * @return this (the workspace scripted object for allowing access to the 
  5 *          frame, interpreter, etc.)
  6 *
  7 * @author Pat Niemeyer
  8 * @author Daniel Leuck (bug fixes)
  9 */
 10
 11import javax.swing.*;
 12import bsh.Interpreter;
 13import bsh.BshClassManager;
 14import bsh.util.JConsole;
 15import bsh.util.NameCompletionTable;
 16
 17makeWorkspace( String name ) 
 18{
 19	if ( bsh.system.desktop == void ) {
 20		print("No desktop...");
 21		return;
 22	}
 23
 24	this.console = new JConsole();
 25	this.name="Bsh Workspace: "+name;
 26
 27	this.interpreter = new Interpreter( console );
 28
 29	// provide name completion for console, name source is global namespace
 30	// move this into JConsole?
 31
 32	this.nct = new NameCompletionTable();
 33	nct.add( interpreter.getNameSpace() );
 34	try {
 35		this.bcm = this.caller.namespace.getClassManager();
 36		if ( bcm != null ) {
 37			classNamesSource = bcm.getClassPath();
 38			nct.add( classNamesSource );
 39		}
 40	} catch ( ClassPathException e ) {
 41		error("classpath exception in name compl:"+e);
 42	}
 43	console.setNameCompletion( nct );
 44	// end setup name completion
 45
 46	// for convenience and backwards compatability
 47	interpreter.set( "bsh.desktop",  bsh.system.desktop );
 48
 49	this.frame = bsh.system.desktop.makeInternalFrame( name );
 50	frame.frameIcon=bsh.system.icons.workspace;
 51	
 52	/*
 53		Notes: Careful not to print anything before returning sys io...
 54		console is now gone.
 55	*/
 56	internalFrameClosing( e ) {
 57		if ( haveSysIO )
 58			returnSysIO();
 59	}
 60	internalFrameActivated(ife) {}
 61	internalFrameDeactivated(ife) {}
 62	internalFrameClosed(ife) {}
 63	internalFrameOpened(ife) {}
 64	internalFrameIconified(ife) {}
 65	internalFrameDeiconified(ife) {}	
 66	
 67	frame.addInternalFrameListener(this);
 68
 69	actionPerformed( e ) 
 70	{
 71		this.com = e.getActionCommand();
 72		if ( com.equals("Workspace Editor") )
 73			workspaceEditor( interpreter, name );
 74		else if ( com.equals("Capture System in/out/err") )
 75			captureSysIO();
 76		else if	( com.equals("Close") )	{
 77			frame.setClosed(true);
 78		}
 79	}
 80
 81	this.menubar = new JMenuBar();
 82	this.menu=new JMenu("File");
 83	this.mi=new JMenuItem("Workspace Editor");
 84	mi.addActionListener(this);
 85	menu.add(mi);
 86	mi=new JMenuItem("Capture System in/out/err");
 87	mi.addActionListener(this);
 88	menu.add(mi);
 89	mi=new JMenuItem("Close");
 90	mi.addActionListener(this);
 91	menu.add(mi);
 92	menubar.add(menu);
 93
 94	menu = fontMenu(console);
 95	menubar.add(menu);
 96
 97	frame.setMenuBar(menubar);
 98
 99	frame.getContentPane().add("Center", console);
100	//frame.pack();
101	this.thread = new Thread( interpreter );
102	thread.start();
103
104	frame.setBounds(5,5,600,300);
105	// cascade windows?
106	//off=bsh.system.desktop.windowCount*10;
107	//frame.setLocation( off, off );
108	//frame.validate();
109	bsh.system.desktop.addInternalFrame( frame	);
110	frame.toFront();
111	frame.setSelected(true);
112
113	this.haveSysIO=false;
114	this.sysIn = System.in;
115	this.sysOut = System.out;
116	this.sysErr = System.err;
117
118	captureSysIO() {
119		super.haveSysIO = true; // old scoping rules
120		System.setIn( console.getInputStream() );
121		System.setOut( console.getOut() );
122		System.setErr( console.getErr() );
123	}
124
125	returnSysIO() {
126		super.haveSysIO = false; // old scoping rules
127		System.setIn( sysIn );
128		System.setOut( sysOut );
129		System.setErr( sysErr );
130	}
131
132	return this;
133}
134