PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 18ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/commands/desktop.bsh

#
Unknown | 207 lines | 172 code | 35 blank | 0 comment | 0 complexity | 584475dd7da27cf620d79b9eaff48413 MD5 | raw file
  1/**
  2 * Start the BeanShell GUI desktop in a JFrame.  A starter workspace is created
  3 * and added to the desktop.
  4 *
  5 * @method void desktop()
  6 *
  7 * @author Pat Niemeyer
  8 * @author Daniel Leuck
  9 */
 10 
 11import javax.swing.*;
 12import javax.swing.border.*;
 13import bsh.util.JConsole;
 14import bsh.util.Util;
 15import bsh.Interpreter;
 16import java.awt.Component;
 17import bsh.Capabilities;
 18
 19desktop() 
 20{
 21		
 22	// need a way to set things to void again
 23	if ( bsh.system.desktop != void ) {
 24		print("There is	already	a desktop running...");
 25		return;
 26	} else
 27		bsh.system.desktop = this;   // race condition (hah!)
 28
 29	bsh.system.icons=object();
 30	
 31	bsh.system.icons.bean=
 32		new ImageIcon(getResource("/bsh/util/lib/icon.gif"));
 33	bsh.system.icons.workspace=
 34		new ImageIcon(getResource("/bsh/util/lib/workspace.gif"));	
 35	bsh.system.icons.script=
 36		new ImageIcon(getResource("/bsh/util/lib/script.gif"));
 37	bsh.system.icons.eye=
 38		new ImageIcon(getResource("/bsh/util/lib/eye.jpg"));		
 39		
 40	bsh.system.fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().
 41		getAvailableFontFamilyNames();		
 42		
 43	JPanel stage=new JPanel(new BorderLayout());
 44	JPanel taskBar=new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1));
 45	taskBar.setBorder(new MatteBorder(1,0,0,0, taskBar.background.darker()));
 46	ButtonGroup taskBarButtonGroup = new ButtonGroup();
 47	
 48	// Ignore unhandled method invocations from listeners.
 49	invoke( method, args ) { }
 50
 51	makeInternalFrame( String name ) 
 52	{
 53		// Closable by default
 54		this.frame = new JInternalFrame( name, true, true, true, true );
 55		frame.frameIcon=bsh.system.icons.bean;
 56		frame.visible=true;
 57		return frame;
 58	}
 59
 60	this.frameMap=new Hashtable();
 61	taskBarButtonListener() {
 62		actionPerformed(ae) {
 63			this.iframe=frameMap.get(ae.source);
 64			if(iframe.icon)
 65				iframe.icon=false;
 66			if(iframe!=null && !iframe.selected)
 67				iframe.selected=true;
 68		}
 69		
 70		return this;
 71	}
 72	this.taskBarButtonListener=taskBarButtonListener();
 73	
 74	addInternalFrame( frame ) 
 75	{
 76		iframeListener=new InternalFrameListener() {
 77			
 78			internalFrameClosing(ife) {
 79				for(e:new Hashtable(frameMap).entrySet()) {
 80					if(e.value.equals(ife.source)) {
 81						taskBar.remove(e.key);
 82						taskBarButtonGroup.remove(e.key);
 83						frameMap.remove(e.key);
 84						taskBar.validate();
 85						taskBar.repaint();
 86					}
 87				}
 88			}
 89			
 90			internalFrameActivated(ife) {
 91				for(e:frameMap.entrySet()) if(e.value.equals(ife.source)) {
 92					if(!e.key.selected) e.key.selected=true;
 93				}
 94			}
 95			
 96			internalFrameDeactivated(ife) {}
 97			internalFrameClosed(ife) {}
 98			internalFrameOpened(ife) {}
 99			internalFrameIconified(ife) {}
100			internalFrameDeiconified(ife) {}
101		};
102		
103		bsh.system.desktop.pane.add( frame	);
104		frame.addInternalFrameListener(iframeListener);
105		JToggleButton button = new JToggleButton(frame.title, frame.frameIcon);
106		taskBarButtonGroup.add(button);
107		button.border=new CompoundBorder((Border)thinBorder(),
108			new EmptyBorder(2,2,2,3));
109		button.addActionListener(taskBarButtonListener);
110		taskBar.add(button);
111		taskBar.validate();
112		
113		frameMap.put(button,frame);
114	}
115
116	this.windowCount=0;
117
118	mousePressed( e	) {
119		popup.show( pane, e.getX(), e.getY() );
120	}
121
122	shutdown() {
123		/*
124		ret = JOptionPane.showInternalConfirmDialog( pane,
125			"This workspace	has not	been saved. Do you really want to exit?" );
126		if ( ret == JOptionPane.YES_OPTION )
127				exit();
128		*/
129		frame.dispose();
130		exit();
131	}
132
133	actionPerformed( e ) 
134	{
135		this.com = e.getActionCommand();
136		if ( com.equals("New Bsh Workspace") )
137			makeWorkspace( ""+ super.windowCount++);
138		if ( com.equals("New Class Browser") )
139			classBrowser();
140		else if	( com.equals("Save Workspace") )
141			JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
142		else if	( com.equals("Exit") )
143			shutdown();
144	}
145
146	this.pane=new JDesktopPane();
147
148	this.popup=new JPopupMenu("Root Menu");
149	this.mi=new JMenuItem("New Bsh Workspace");
150	mi.addActionListener(this);
151	popup.add( mi );
152	mi=new JMenuItem("New Class Browser");
153	mi.addActionListener(this);
154	popup.add( mi );
155	mi=new JMenuItem("Save Workspace");
156	mi.addActionListener(this);
157	popup.add( mi );
158	mi=new JMenuItem("Exit");
159	mi.addActionListener(this);
160	popup.add( mi );
161
162	pane.addMouseListener( this );
163
164	this.frame=new JFrame("BeanShell Desktop 1.1");
165	
166	stage.add(pane);
167	stage.add(taskBar, BorderLayout.SOUTH);
168	
169	frame.getContentPane().add(stage);
170
171	windowClosing( e ) {
172		bsh.system.desktop = null;
173		shutdown();
174	}
175
176	frame.iconImage=bsh.system.icons.bean.image;
177	frame.addWindowListener( this );
178
179	/*
180		If available, add a listener for classpath mapping
181		I'm planning to implement a GUI progress indicator here
182
183	if ( Capabilities.canGenerateInterfaces() ) 
184	{
185		import bsh.classpath.BshClassPath;
186		classFeedbackListener = new BshClassPath.MappingFeedback() 
187		{
188			startClassMapping() { }
189			classMapping( msg ) { }
190			errorWhileMapping( msg ) { }
191			endClassMapping() { }
192		};
193		BshClassPath.addMappingFeedback( classFeedbackListener );
194	}
195	*/
196
197	// start one terminal
198	workSpace=makeWorkspace( ""+windowCount++	);
199
200	frame.setSize(800,600);
201	frame.show();
202	
203	Util.endSplashScreen();
204	
205	frame.toFront();
206	workSpace.frame.selected=true;
207}