JMenu menu;
JMenuItem menuItem;
// File menu
menu = new JMenu("File");
menu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
updateOpenHistoryMenuItems();
}
public void menuDeselected(MenuEvent e) {
}
public void menuCanceled(MenuEvent e) {
}
});
menu.setMnemonic(KeyEvent.VK_F);
menuBar.add(menu);
menuItem = new JMenuItem("New simulation");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("new sim");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
menuItem = new JMenuItem("Reload simulation");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reloadCurrentSimulation();
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Close simulation");
menuItem.setMnemonic(KeyEvent.VK_C);
menuItem.setActionCommand("close sim");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
menuOpenSimulation = new JMenu("Open simulation");
menuOpenSimulation.setMnemonic(KeyEvent.VK_O);
menu.add(menuOpenSimulation);
menuConfOpenSimulation = new JMenu("Open & Reconfigure simulation");
menuConfOpenSimulation.setMnemonic(KeyEvent.VK_R);
menu.add(menuConfOpenSimulation);
menuItem = new JMenuItem("Save simulation");
menuItem.setMnemonic(KeyEvent.VK_S);
menuItem.setActionCommand("save sim");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Close all plugins");
menuItem.setActionCommand("close plugins");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Exit");
menuItem.setMnemonic(KeyEvent.VK_X);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
// Simulation menu
menu = new JMenu("Simulation");
menu.setMnemonic(KeyEvent.VK_S);
menuBar.add(menu);
menuItem = new JMenuItem("Open Control");
menuItem.setMnemonic(KeyEvent.VK_C);
menuItem.setActionCommand("start plugin");
menuItem.putClientProperty("class", SimControl.class);
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
menuItem = new JMenuItem("Information");
menuItem.setMnemonic(KeyEvent.VK_I);
menuItem.setActionCommand("start plugin");
menuItem.putClientProperty("class", SimInformation.class);
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
// Mote type menu
menu = new JMenu("Mote Types");
menu.setMnemonic(KeyEvent.VK_T);
menuBar.add(menu);
// Mote type classes sub menu
menuMoteTypeClasses = new JMenu("Create mote type");
menuMoteTypeClasses.setMnemonic(KeyEvent.VK_C);
menuMoteTypeClasses.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
// Clear menu
menuMoteTypeClasses.removeAll();
// Recreate menu items
JMenuItem menuItem;
for (Class<? extends MoteType> moteTypeClass : moteTypeClasses) {
String description = GUI.getDescriptionOf(moteTypeClass);
menuItem = new JMenuItem(description);
menuItem.setActionCommand("create mote type");
menuItem.putClientProperty("class", moteTypeClass);
menuItem.addActionListener(guiEventHandler);
menuMoteTypeClasses.add(menuItem);
}
}
public void menuDeselected(MenuEvent e) {
}
public void menuCanceled(MenuEvent e) {
}
});
menu.add(menuMoteTypeClasses);
menuItem = new JMenuItem("Information");
menuItem.setActionCommand("start plugin");
menuItem.putClientProperty("class", MoteTypeInformation.class);
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
// Mote menu
menu = new JMenu("Motes");
menu.setMnemonic(KeyEvent.VK_M);
menuBar.add(menu);
// Mote types sub menu
menuMoteTypes = new JMenu("Add motes of type");
menuMoteTypes.setMnemonic(KeyEvent.VK_A);
menuMoteTypes.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
// Clear menu
menuMoteTypes.removeAll();
if (mySimulation == null) {