PageRenderTime 41ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

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

#
Unknown | 140 lines | 118 code | 22 blank | 0 comment | 0 complexity | c243c0b20c205eb7a380338baaa13e5b 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	frame.setDefaultCloseOperation( frame.DO_NOTHING_ON_CLOSE );
 52	
 53	internalFrameClosing( e ) {
 54		close();
 55	}
 56	frame.addInternalFrameListener(this);
 57
 58	actionPerformed( e ) 
 59	{
 60		this.com = e.getActionCommand();
 61		if ( com.equals("Workspace Editor") )
 62			workspaceEditor( interpreter, name );
 63		else if ( com.equals("Capture System in/out/err") )
 64			captureSysIO();
 65		else if	( com.equals("Close") )	{
 66			close();
 67		}
 68	}
 69	
 70	internalFrameActivated(ife) {}
 71	internalFrameDeactivated(ife) {}
 72	internalFrameClosed(ife) {}
 73	internalFrameOpened(ife) {}
 74	internalFrameIconified(ife) {}
 75	internalFrameDeiconified(ife) {}
 76	
 77	/*
 78		Notes: Careful not to print anything before returning sys io...
 79		console is now gone.
 80	*/
 81	close() {
 82		frame.dispose();
 83		if ( haveSysIO )
 84			returnSysIO();
 85	}
 86
 87	this.menubar = new JMenuBar();
 88	this.menu=new JMenu("File");
 89	this.mi=new JMenuItem("Workspace Editor");
 90	mi.addActionListener(this);
 91	menu.add(mi);
 92	mi=new JMenuItem("Capture System in/out/err");
 93	mi.addActionListener(this);
 94	menu.add(mi);
 95	mi=new JMenuItem("Close");
 96	mi.addActionListener(this);
 97	menu.add(mi);
 98	menubar.add(menu);
 99
100	menu = fontMenu(console);
101	menubar.add(menu);
102
103	frame.setMenuBar(menubar);
104
105	frame.getContentPane().add("Center", console);
106	//frame.pack();
107	this.thread = new Thread( interpreter );
108	thread.start();
109
110	frame.setBounds(5,5,600,300);
111	// cascade windows?
112	//off=bsh.system.desktop.windowCount*10;
113	//frame.setLocation( off, off );
114	//frame.validate();
115	bsh.system.desktop.addInternalFrame( frame	);
116	frame.toFront();
117	frame.setSelected(true);
118
119	this.haveSysIO=false;
120	this.sysIn = System.in;
121	this.sysOut = System.out;
122	this.sysErr = System.err;
123
124	captureSysIO() {
125		super.haveSysIO = true; // old scoping rules
126		System.setIn( console.getInputStream() );
127		System.setOut( console.getOut() );
128		System.setErr( console.getErr() );
129	}
130
131	returnSysIO() {
132		super.haveSysIO = false; // old scoping rules
133		System.setIn( sysIn );
134		System.setOut( sysOut );
135		System.setErr( sysErr );
136	}
137
138	return this;
139}
140