PageRenderTime 39ms CodeModel.GetById 34ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/bsh/commands/makeWorkspace.bsh

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