blob: 5b4533db3eafe4608547e44eadd59cfe8e30f1ee (
plain)
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
|
package net.wotonomy.test;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import net.wotonomy.control.EOEditingContext;
import net.wotonomy.control.EOObjectStore;
/**
* A simple test-bed for wotonomy. Shows a JFrame containing the TestPanel which
* is controlled by the TestController.
*/
public class Test {
static EOObjectStore objectStore;
static EOEditingContext editingContext;
static public void main(String[] argv) {
// NSRunLoop.currentRunLoop();
// system l&f
try {
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
// no system l&f - fail silently
}
// launch notification monitor if desired
for (int i = 0; i < argv.length; i++) {
if (argv[i].indexOf("monitor") != -1) {
new net.wotonomy.ui.swing.NotificationInspector();
}
}
new net.wotonomy.ui.swing.NotificationInspector();
// set up editing context hierarchy
objectStore = new DataObjectStore("data");
editingContext = new EOEditingContext(objectStore);
// connect panel to controller
TestPanel testPanel = new TestPanel();
final TestController controller = new TestController(testPanel);
// create frame and show
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// setup menus
JMenu menu;
JMenuItem menuItem;
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("File");
menu.add("New");
menuItem = new JMenuItem("Save");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
controller.displayGroup.dataSource().editingContext().saveChanges();
}
});
menu.add(menuItem);
menu.add("Close");
menuBar.add(menu);
menu = new JMenu("Edit");
menu.add("Cut");
menu.add("Copy");
menu.add("Paste");
menuBar.add(menu);
frame.setJMenuBar(menuBar);
frame.getContentPane().add(testPanel, BorderLayout.CENTER);
frame.setTitle("Test Frame");
frame.setBounds(50, 50, 750, 500);
frame.show(); // comment out this to avoid memory leak from jdk1.2.2 bug
// add WindowListener for frame
frame.addWindowListener(new WindowAdapter() {
// exit on close
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
/*
* uncomment this to avoid memory leak from jdk1.2.2 bug
* frame.getContentPane().removeAll();
*/
/*
* NSNotificationCenter.defaultCenter().addObserver( frame, new NSSelector(
* "hitMe", new Class[] { NSNotification.class } ), null, null );
*/
}
}
|