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