View Javadoc

    1   /*
    2    * @(#) MenuBar.java 20-jul-2004
    3    *
    4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
    5    * Delft, the Netherlands. All rights reserved.
    6    *
    7    * This software is proprietary information of Delft University of Technology
    8    * The code is published under the Lesser General Public License
    9    */
    10  package nl.tudelft.simulation.dsol.gui.editor2D;
    11
    12  import java.awt.event.ActionEvent;
    13  import java.awt.event.KeyEvent;
    14
    15  import javax.swing.JCheckBoxMenuItem;
    16  import javax.swing.JMenu;
    17  import javax.swing.JMenuBar;
    18  import javax.swing.JMenuItem;
    19  import javax.swing.JSeparator;
    20  import javax.swing.KeyStroke;
    21
    22  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
    23  import nl.tudelft.simulation.dsol.gui.editor2D.actions.MenuBarActions;
    24
    25  /***
    26   * MenuBar.java <br>
    27   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
    28   * University of Technology </a>, the Netherlands. <br>
    29   * See for project information <a
    30   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
    31   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
    32   * General Public License (LGPL) </a>, no warranty.
    33   *
    34   * @version $Revision$ $Date$
    35   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
    36   *         </a>
    37   */
    38  public class MenuBar extends JMenuBar
    39  {
    40
    41  	/*** Parent frame */
    42  	private Editor2DFrame source = null;
    43
    44  	/*** The application */
    45  	private DSOLApplicationInterface application = null;
    46
    47  	/*** save editables */
    48  	private JMenuItem saveEditablesItem = null;
    49
    50  	/*** Exit this frame */
    51  	private JMenuItem exitItem = null;
    52
    53  	/*** Navigation toolbar menu item */
    54  	private JCheckBoxMenuItem navigationItem = null;
    55
    56  	/*** Editor toolbar menu item */
    57  	private JCheckBoxMenuItem editorItem = null;
    58
    59  	/*** Actions */
    60  	private MenuBarActions actions = null;
    61
    62  	/***
    63  	 * Constructor
    64  	 *
    65  	 * @param source Parent frame
    66  	 * @param application The application
    67  	 */
    68  	public MenuBar(final Editor2DFrame source,
    69  			final DSOLApplicationInterface application)
    70  	{
    71  		super();
    72  		this.source = source;
    73  		this.application = application;
    74  		this.initialize();
    75  	}
    76
    77  	/***
    78  	 * Initialize menubar
    79  	 */
    80  	private void initialize()
    81  	{
    82  		// Initialize actions
    83  		this.actions = new MenuBarActions(this, this.application);
    84
    85  		// File menu
    86  		JMenu fileMenu = new JMenu("File");
    87  		fileMenu.setMnemonic(KeyEvent.VK_F);
    88  		// Save
    89  		this.saveEditablesItem = new JMenuItem("Save editables", KeyEvent.VK_S);
    90  		this.saveEditablesItem.setAccelerator(KeyStroke.getKeyStroke(
    91  				KeyEvent.VK_S, ActionEvent.ALT_MASK));
    92  		this.saveEditablesItem.getAccessibleContext().setAccessibleDescription(
    93  				"Save editables");
    94  		this.saveEditablesItem.addActionListener(this.actions);
    95  		fileMenu.add(this.saveEditablesItem);
    96  		fileMenu.add(new JSeparator());
    97  		// Exit
    98  		this.exitItem = new JMenuItem("Exit", KeyEvent.VK_X);
    99  		this.exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
    100 				ActionEvent.ALT_MASK));
    101 		this.exitItem.getAccessibleContext().setAccessibleDescription(
    102 				"Exit this frame");
    103 		this.exitItem.addActionListener(this.actions);
    104 		fileMenu.add(this.exitItem);
    105 		this.add(fileMenu);
    106
    107 		// Add the edit menu from the editable animation panel
    108 		this.add(this.source.getEditableAnimationPanel().getEditMenu());
    109
    110 		// Toolbar menu
    111 		JMenu toolbarMenu = new JMenu("Toolbars");
    112 		toolbarMenu.setMnemonic(KeyEvent.VK_T);
    113
    114 		this.navigationItem = new JCheckBoxMenuItem("Navigation");
    115 		this.navigationItem.setMnemonic(KeyEvent.VK_N);
    116 		this.navigationItem.setAccelerator(KeyStroke.getKeyStroke(
    117 				KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    118 		this.navigationItem.getAccessibleContext().setAccessibleDescription(
    119 				"Show navigation toolbar");
    120 		this.navigationItem.addActionListener(this.actions);
    121 		this.navigationItem.setState(true);
    122 		toolbarMenu.add(this.navigationItem);
    123 		toolbarMenu.setVisible(false); // FALSE BECAUSE IT DOES NOT WORK YET!
    124
    125 		this.add(toolbarMenu);
    126 	}
    127
    128 	/***
    129 	 * @return Returns the exitItem.
    130 	 */
    131 	public JMenuItem getExitItem()
    132 	{
    133 		return this.exitItem;
    134 	}
    135
    136 	/***
    137 	 * @return Returns the source.
    138 	 */
    139 	public Editor2DFrame getParentFrame()
    140 	{
    141 		return this.source;
    142 	}
    143
    144 	/***
    145 	 * @return Returns the editorItem.
    146 	 */
    147 	public JCheckBoxMenuItem getEditorItem()
    148 	{
    149 		return this.editorItem;
    150 	}
    151
    152 	/***
    153 	 * @return Returns the navigationItem.
    154 	 */
    155 	public JCheckBoxMenuItem getNavigationItem()
    156 	{
    157 		return this.navigationItem;
    158 	}
    159
    160 	/***
    161 	 * @return Returns the saveEditablesItem.
    162 	 */
    163 	public JMenuItem getSaveEditablesItem()
    164 	{
    165 		return this.saveEditablesItem;
    166 	}
    167
    168 	/***
    169 	 * @return Returns the source.
    170 	 */
    171 	public Editor2DFrame getSource()
    172 	{
    173 		return this.source;
    174 	}
    175 }