PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/bsh/commands/makeWorkspace.bsh

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