View Javadoc

1   package net.wotonomy.test;
2   
3   import java.awt.BorderLayout;
4   import java.awt.event.ActionEvent;
5   import java.awt.event.ActionListener;
6   import java.awt.event.KeyEvent;
7   import java.awt.event.WindowAdapter;
8   import java.awt.event.WindowEvent;
9   
10  import javax.swing.JFrame;
11  import javax.swing.JMenu;
12  import javax.swing.JMenuBar;
13  import javax.swing.JMenuItem;
14  import javax.swing.KeyStroke;
15  import javax.swing.UIManager;
16  
17  import net.wotonomy.control.EOEditingContext;
18  import net.wotonomy.control.EOObjectStore;
19  
20  /***
21  * A simple test-bed for wotonomy.
22  * Shows a JFrame containing the TestPanel
23  * which is controlled by the TestController.
24  */
25  public class Test 
26  {
27      static EOObjectStore objectStore;
28      static EOEditingContext editingContext;
29      static public void main( String[] argv )
30      {
31  //        NSRunLoop.currentRunLoop();
32          
33          // system l&f
34          try
35          {
36  //           UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
37             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
38  //           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
39  //            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
40          }
41          catch (Exception e)
42          {
43  			// no system l&f - fail silently
44          }
45          
46          // launch notification monitor if desired
47          for ( int i = 0; i < argv.length; i++ )
48          {
49              if ( argv[i].indexOf( "monitor" ) != -1 )
50              {
51                  new net.wotonomy.ui.swing.NotificationInspector();                
52             }
53          }
54                  new net.wotonomy.ui.swing.NotificationInspector();                
55          
56          // set up editing context hierarchy
57          objectStore = new DataObjectStore( "data" );
58          editingContext = new EOEditingContext( objectStore );
59  
60  		// connect panel to controller
61          TestPanel testPanel = new TestPanel();
62  		final TestController controller = new TestController( testPanel );
63  	
64  		// create frame and show
65          JFrame frame = new JFrame();
66          frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
67  		
68  		// setup menus
69  		JMenu menu;
70          JMenuItem menuItem;
71  		JMenuBar menuBar = new JMenuBar();
72  		menu = new JMenu( "File" );
73  		menu.add( "New" );
74          menuItem = new JMenuItem( "Save" );
75          menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, KeyEvent.CTRL_MASK ) );
76          menuItem.addActionListener( new ActionListener()
77          {
78  			public void actionPerformed( ActionEvent evt )
79  			{
80                  controller.displayGroup.dataSource().editingContext().saveChanges();	
81              }
82          });
83  
84  		menu.add( menuItem );
85  		menu.add( "Close" );
86  		menuBar.add( menu );
87  		menu = new JMenu( "Edit" );
88  		menu.add( "Cut" );
89  		menu.add( "Copy" );
90  		menu.add( "Paste" );
91  		menuBar.add( menu );
92  		frame.setJMenuBar( menuBar );
93  	
94  		frame.getContentPane().add( testPanel, BorderLayout.CENTER );
95  		frame.setTitle( "Test Frame" );
96          frame.setBounds( 50, 50, 750, 500 );
97  		frame.show(); // comment out this to avoid memory leak from jdk1.2.2 bug
98  
99  		// add WindowListener for frame
100 		frame.addWindowListener( new WindowAdapter()
101 		{
102 			// exit on close
103 			public void windowClosing(WindowEvent e)
104 			{	
105 				System.exit( 0 );
106 			}
107 		});
108 
109         /* uncomment this to avoid memory leak from jdk1.2.2 bug
110         frame.getContentPane().removeAll();
111         */
112 /*        
113         NSNotificationCenter.defaultCenter().addObserver(
114             frame, 
115             new NSSelector( "hitMe", new Class[] { NSNotification.class } ),
116             null, null );
117 */        
118     }
119     
120 }