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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
package com.c2kernel.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.gui.data.Node;
import com.c2kernel.gui.data.NodeContext;
import com.c2kernel.gui.tabs.execution.DefaultExecutor;
import com.c2kernel.gui.tabs.execution.Executor;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;
/**
* @version $Revision: 1.83 $ $Date: 2005/09/12 14:56:19 $
* @author $Author: abranson $
*/
public class MainFrame extends javax.swing.JFrame {
public static TreeBrowser treeBrowser;
public static EntityTabManager myDesktopManager;
public static EntityFinder itemFinder;
protected static Node userNode = null;
protected MenuBuilder menuBuilder;
protected org.omg.CORBA.ORB orb;
public static Properties prefs = new Properties();
public static JLabel status = new JLabel();
public String logoURL;
public static AgentProxy userAgent;
protected JSplitPane splitPane;
public static boolean isAdmin;
int splitPanePos;
public static final JFileChooser xmlChooser;
static {
xmlChooser = new JFileChooser();
xmlChooser.addChoosableFileFilter(
new javax.swing.filechooser.FileFilter() {
@Override
public String getDescription() {
return "XML Files";
}
@Override
public boolean accept(File f) {
if (f.isDirectory() || (f.isFile() && f.getName().endsWith(".xml"))) {
return true;
}
return false;
}
});
}
/** Creates new gui client for Cristal2 */
public MainFrame() {
// Load gui preferences
try {
FileInputStream prefsfile =
new FileInputStream("cristal.preferences");
prefs.load(prefsfile);
prefsfile.close();
} catch (IOException e) {
Logger.msg(2, "Creating new preference file");
}
// set look & feel from pref
try {
String lf = getPref("Style", null);
if (lf == null)
lf = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
}
public void showLogin() {
// Log in
logoURL = Gateway.getProperty("Logo");
URL pictureUrl;
String bottomMessage =
Language.translate("Please enter username & password");
ImageIcon imageHolder = new ImageIcon("");
try {
pictureUrl = new URL(logoURL);
imageHolder = new ImageIcon(pictureUrl);
} catch (java.net.MalformedURLException m) {
imageHolder = Resource.getImageResource(logoURL);
}
LoginBox login =
new LoginBox(
5,
Gateway.getProperty("Name"),
getPref("lastUser."+Gateway.getCentreId(), null),
bottomMessage,
imageHolder, this);
login.setVisible(true);
}
public void mainFrameShow() {
prefs.setProperty("lastUser."+Gateway.getCentreId(), userAgent.getName());
isAdmin = userAgent.getPath().hasRole("Admin");
GridBagLayout gridbag = new GridBagLayout();
getContentPane().setLayout(gridbag);
this.setTitle(
userAgent.getName()+"@"+Gateway.getProperty("Name") + " - " + Language.translate("Cristal 2"));
String iconFile = Gateway.getProperty("AppIcon");
if (iconFile != null)
this.setIconImage(Resource.getImageResource(iconFile).getImage());
//preload loading image
Resource.getImageResource("loading.gif");
// close listener
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm();
}
});
// initialise the desktop manager
myDesktopManager = new EntityTabManager();
//get the menu bar and add it to the frame
menuBuilder = new MenuBuilder(this);
setJMenuBar(menuBuilder);
// set the menu builder in the window manager
myDesktopManager.setMenuBuilder(menuBuilder);
userNode = new NodeContext(new DomainPath(""), myDesktopManager);
treeBrowser = new TreeBrowser(myDesktopManager, userNode);
treeBrowser.setVisible(getPref("ShowTree", "true").equals("true"));
// add search box
itemFinder = new EntityFinder();
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.weighty = 0.0;
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(itemFinder, c);
getContentPane().add(itemFinder);
// register the browser as the key consumer
itemFinder.setDefaultConsumer(treeBrowser);
c.gridy++;
c.weightx = 1.0;
c.weighty = 1.0;
c.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(getSplitPanel(), c);
getContentPane().add(getSplitPanel());
// setup status bar
status.setText("Cristal 2");
status.setFont(
new Font("SansSerif", Font.PLAIN, status.getFont().getSize()));
JPanel statusPanel = new JPanel();
statusPanel.setLayout(new BorderLayout());
statusPanel.setBorder(BorderFactory.createLoweredBevelBorder());
status.setForeground(Color.black);
statusPanel.add(status);
c.gridy++;
c.weighty = 0.0;
gridbag.setConstraints(statusPanel, c);
getContentPane().add(statusPanel);
pack();
String paneSize = getPref("WindowSize", null);
if (paneSize != null) {
StringTokenizer tok = new StringTokenizer(paneSize, ",");
Dimension window = new Dimension();
window.setSize(
Integer.parseInt(tok.nextToken()),
Integer.parseInt(tok.nextToken()));
this.setSize(window);
}
String panePos = getPref("WindowPosition", null);
if (panePos != null) {
StringTokenizer tok = new StringTokenizer(panePos, ",");
Point window =
new Point(
Integer.parseInt(tok.nextToken()),
Integer.parseInt(tok.nextToken()));
this.setLocation(window);
}
super.toFront();
this.validate();
this.setVisible(true);
}
public static String getPref(String name, String defaultValue) {
return prefs.getProperty(name, defaultValue);
}
public static void setPref(String name, String value) {
prefs.setProperty(name, value);
}
// things to do on exit
public void exitForm() {
// close connections
Gateway.close();
// save window sizing
setPref(
"WindowSize",
(int) (this.getSize().getWidth())
+ ","
+ (int) (this.getSize().getHeight()));
setPref(
"WindowPosition",
(int) (this.getLocation().getX())
+ ","
+ (int) (this.getLocation().getY()));
setPref(
"Style",
UIManager.getLookAndFeel().getClass().getName());
setPref(
"SplitPanePosition",
String.valueOf(splitPane.getDividerLocation()));
// save preferences file
try {
FileOutputStream prefsfile =
new FileOutputStream("cristal.preferences", false);
prefs.store(prefsfile, "Cristal 2");
prefsfile.close();
} catch (Exception e) {
Logger.warning(
"Could not write to preferences file. Preferences have not been updated.");
}
this.setVisible(false);
// allow waiting threads time to quit
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
System.exit(0);
}
public void toggleTree() {
boolean showTree = getPref("ShowTree", "true").equals("false");
setPref("ShowTree", String.valueOf(showTree));
if (!showTree) splitPanePos = splitPane.getDividerLocation();
getSplitPanel().getLeftComponent().setVisible(showTree);
if (showTree) getSplitPanel().setDividerLocation(splitPanePos);
getSplitPanel().validate();
}
public static JComboBox getExecutionPlugins() {
JComboBox plugins = new JComboBox();
// create execution selector
Executor defaultExecutor = new DefaultExecutor();
plugins.addItem(defaultExecutor);
plugins.setSelectedIndex(0);
// load execution plugins
String pluginList = Gateway.getProperty("Executors");
if (pluginList != null) {
StringTokenizer tok = new StringTokenizer(pluginList, ",");
while (tok.hasMoreTokens()) {
String pluginName = tok.nextToken();
try {
Class<?> pluginClass = Class.forName(pluginName);
Executor domainExecutor = (Executor)pluginClass.newInstance();
plugins.addItem(domainExecutor);
} catch (Exception ex) {
Logger.error("Could not load the executor plugin "+pluginName);
}
}
}
return plugins;
}
protected JSplitPane getSplitPanel()
{
// create the split pane, and add the Tree to it.
if (splitPane == null)
{
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, treeBrowser, myDesktopManager);
splitPane.setDividerSize(5);
splitPanePos = Integer.parseInt(getPref("SplitPanePosition", "200"));
getSplitPanel().setDividerLocation(splitPanePos);
}
return splitPane;
}
}
|