PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 147 lines | 125 code | 22 blank | 0 comment | 0 complexity | f0e19e9e0ec339557a7d96ee511044e1 MD5 | raw file
  1/**
  2	Start the BeanShell GUI desktop.
  3
  4	@method void desktop()
  5*/
  6import javax.swing.*;
  7import bsh.util.JConsole;
  8import bsh.util.Util;
  9import bsh.Interpreter;
 10import java.awt.Component;
 11import bsh.Capabilities;
 12
 13desktop() {
 14	// need a way to set things to void again
 15	if ( bsh.system.desktop != void ) {
 16		print("There is	already	a desktop running...");
 17		return;
 18	} else
 19		bsh.system.desktop = this;   // race condition (hah!)
 20
 21	// Ignore unhandled method invocations from listeners.
 22	invoke( method, args ) { }
 23
 24	makeFontMenu( Component	component ) {
 25		menu = new JMenu("Font");
 26		mi = new JMenuItem("Normal");
 27		mi.addActionListener(this);
 28		menu.add(mi);
 29		mi = new JMenuItem("Big");
 30		mi.addActionListener(this);
 31		menu.add(mi);
 32		mi = new JMenuItem("Bigger");
 33		mi.addActionListener(this);
 34		menu.add(mi);
 35
 36		actionPerformed(e) {
 37			com = e.getActionCommand();
 38			if ( com.equals("Normal") )
 39				setFont( component, 12 );
 40			else if	( com.equals("Big") )
 41				setFont( component, 16 );
 42			else if	( com.equals("Bigger") )
 43				setFont( component, 20 );
 44		}
 45
 46		return menu;
 47	}
 48
 49	makeInternalFrame( String name ) {
 50		// Closable by default
 51		frame = new JInternalFrame(	name, true, true, true, true);
 52		frame.setVisible( true );
 53		return frame;
 54	}
 55
 56	addInternalFrame( frame ) {
 57		bsh.system.desktop.pane.add( frame	);
 58		/*
 59		frame.pack();
 60		frame.show();
 61		frame.toFront();
 62		*/
 63	}
 64
 65	windowCount=0;
 66
 67	mousePressed( e	) {
 68		popup.show( pane, e.getX(), e.getY() );
 69	}
 70
 71	shutdown() {
 72		/*
 73		ret = JOptionPane.showInternalConfirmDialog( pane,
 74			"This workspace	has not	been saved. Do you really want to exit?" );
 75		if ( ret == JOptionPane.YES_OPTION )
 76				exit();
 77		*/
 78		frame.dispose();
 79		exit();
 80	}
 81
 82	actionPerformed( e ) {
 83		com = e.getActionCommand();
 84		if ( com.equals("New Bsh Workspace") )
 85			makeWorkspace( ""+ super.windowCount++);
 86		if ( com.equals("New Class Browser") )
 87			classBrowser();
 88		else if	( com.equals("Save Workspace") )
 89			JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
 90		else if	( com.equals("Exit") )
 91			shutdown();
 92	}
 93
 94	pane=new JDesktopPane();
 95
 96	popup=new JPopupMenu("Root Menu");
 97	mi=new JMenuItem("New Bsh Workspace");
 98	mi.addActionListener(this);
 99	popup.add( mi );
100	mi=new JMenuItem("New Class Browser");
101	mi.addActionListener(this);
102	popup.add( mi );
103	mi=new JMenuItem("Save Workspace");
104	mi.addActionListener(this);
105	popup.add( mi );
106	mi=new JMenuItem("Exit");
107	mi.addActionListener(this);
108	popup.add( mi );
109
110	pane.addMouseListener( this );
111
112	frame=new JFrame("BeanShell Desktop 1.0");
113	frame.getContentPane().add("Center", pane);
114
115	windowClosing( e ) {
116		bsh.system.desktop = null;
117		shutdown();
118	}
119
120	frame.addWindowListener( this );
121
122	/*
123		If available, add a listener for classpath mapping
124		I'm planning to implement a GUI progress indicator here
125
126	if ( Capabilities.canGenerateInterfaces() ) 
127	{
128		import bsh.classpath.BshClassPath;
129		classFeedbackListener = new BshClassPath.MappingFeedback() 
130		{
131			startClassMapping() { }
132			classMapping( msg ) { }
133			errorWhileMapping( msg ) { }
134			endClassMapping() { }
135		};
136		BshClassPath.addMappingFeedback( classFeedbackListener );
137	}
138	*/
139
140	// start one terminal
141	makeWorkspace( ""+windowCount++	);
142
143	frame.setSize(800,600);
144	frame.show();
145	frame.toFront();
146	Util.endSplashScreen();
147}