PageRenderTime 138ms CodeModel.GetById 136ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

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