From aedc34d55462a75e329bbf342251ff6504cd117e Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sun, 19 May 2024 17:56:33 -0400 Subject: Initial import from SVN --- .../src/main/java/net/wotonomy/test/Test.java | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 projects/net.wotonomy.test/src/main/java/net/wotonomy/test/Test.java (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/Test.java') diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/Test.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/Test.java new file mode 100644 index 0000000..ba6a1dc --- /dev/null +++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/Test.java @@ -0,0 +1,120 @@ +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 ); +*/ + } + +} -- cgit v1.2.3