package awa.imu; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class IMUViewer extends JFrame { private static final String TITLE = "IMU Visualizer"; private JMenuBar menuBar = new JMenuBar(); private JMenu fileMenu = new JMenu(); private JMenuItem exitItem = new JMenuItem(); private JMenu helpMenu = new JMenu(); private JMenuItem aboutItem = new JMenuItem(); private Main3dScreen mainScreen; private IMUControlPanel controlPanel; public IMUViewer() { mainScreen = new Main3dScreen(this); controlPanel = new IMUControlPanel(mainScreen); setJMenuBar(menuBar); setTitle(TITLE); getContentPane().setLayout(new GridBagLayout()); setSize(800, 600); setResizable(false); setVisible(false); fileMenu.setText("File"); fileMenu.setActionCommand("File"); fileMenu.setMnemonic((int)'F'); menuBar.add(fileMenu); exitItem.setText("Exit"); exitItem.setActionCommand("Exit"); exitItem.setMnemonic((int)'X'); fileMenu.add(exitItem); helpMenu.setText("Help"); helpMenu.setActionCommand("Help"); helpMenu.setMnemonic((int)'H'); menuBar.add(helpMenu); aboutItem.setText("About..."); aboutItem.setActionCommand("About..."); aboutItem.setMnemonic((int)'A'); helpMenu.add(aboutItem); getContentPane().add(mainScreen, new GridBagConstraints(0,0,1,1,0.6,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(3,3,3,3),600,600)); getContentPane().add(controlPanel, new GridBagConstraints(1,0,1,1,0.4,1.0,GridBagConstraints.EAST,GridBagConstraints.BOTH,new Insets(3,3,3,3),80,80)); MyWindowAdapter winadapt = new MyWindowAdapter(); this.addWindowListener(winadapt); MyActionListener actionlis = new MyActionListener(); exitItem.addActionListener(actionlis); } /** * @param args */ public static void main(String[] args) { try { (new IMUViewer()).setVisible(true); } catch (Throwable t) { t.printStackTrace(); //Ensure the application exits with an error condition. System.exit(1); } } void exitApplication() { try { /* // Beep Toolkit.getDefaultToolkit().beep(); // Show a confirmation dialog int reply = JOptionPane.showConfirmDialog(this, "Do you really want to exit?", "JFC Application - Exit" , JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); // If the confirmation was affirmative, handle exiting. if (reply == JOptionPane.YES_OPTION) */ { this.setVisible(false); // hide the Frame this.dispose(); // free the system resources System.exit(0); // close the application } } catch (Exception e) { /* do nothing */ } } class MyWindowAdapter extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == IMUViewer.this) Frame_windowClosing(); } } void Frame_windowClosing() { try { this.exitApplication(); } catch (Exception e) { /* do nothing */ } } class MyActionListener implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == exitItem) exitItem_actionPerformed(); else if (object == aboutItem) aboutItem_actionPerformed(); } } void exitItem_actionPerformed() { try { this.exitApplication(); } catch (Exception e) { /* do nothing */ } } void aboutItem_actionPerformed() { try { // AboutDialog: Create with owner and show as modal /* AboutDialog about = new AboutDialog(this); about.setModal(true); about.setVisible(true); */ } catch (Exception e) { /* do nothing */ } } public void displayRotation(double phi, double theta, double psi) { controlPanel.displayRotation(phi, theta, psi); } }