changed mote plugins menu to submenues instead of popups

(had to restructure mote menu system slightly)
This commit is contained in:
fros4943 2007-03-22 11:14:27 +00:00
parent d5ac105b8e
commit d65b820ca2
2 changed files with 27 additions and 45 deletions

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.21 2007/02/27 13:51:58 fros4943 Exp $ * $Id: GUI.java,v 1.22 2007/03/22 11:14:27 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -151,14 +151,12 @@ public class GUI {
private Simulation mySimulation; private Simulation mySimulation;
protected Mote selectedMote = null;
protected GUIEventHandler guiEventHandler = new GUIEventHandler(); protected GUIEventHandler guiEventHandler = new GUIEventHandler();
private JMenu menuPlugins, menuMoteTypeClasses, menuMoteTypes; private JMenu menuPlugins, menuMoteTypeClasses, menuMoteTypes;
private JPopupMenu menuMotePlugins; private Vector<Class<? extends Plugin>> menuMotePluginClasses;
private JDesktopPane myDesktopPane; private JDesktopPane myDesktopPane;
private Vector<Plugin> startedPlugins = new Vector<Plugin>(); private Vector<Plugin> startedPlugins = new Vector<Plugin>();
@ -412,10 +410,7 @@ public class GUI {
menu.add(menuItem); menu.add(menuItem);
// Mote plugins popup menu (not available via menu bar) // Mote plugins popup menu (not available via menu bar)
menuMotePlugins = new JPopupMenu(); menuMotePluginClasses = new Vector<Class<? extends Plugin>>();
menuMotePlugins.add(new JLabel("Open mote plugin:"));
menuMotePlugins.add(new JSeparator());
return menuBar; return menuBar;
} }
@ -1384,13 +1379,8 @@ public class GUI {
menuPlugins.remove(menuItem); menuPlugins.remove(menuItem);
} }
} }
for (MenuElement menuComponent : menuMotePlugins.getSubElements()) { if (menuMotePluginClasses.contains(pluginClass))
if (menuComponent.getClass().isAssignableFrom(JMenuItem.class)) { menuMotePluginClasses.remove(pluginClass);
JMenuItem menuItem = (JMenuItem) menuComponent;
if (menuItem.getClientProperty("class").equals(pluginClass))
menuPlugins.remove(menuItem);
}
}
// Remove from plugin vectors (including temporary) // Remove from plugin vectors (including temporary)
if (pluginClasses.contains(pluginClass)) if (pluginClasses.contains(pluginClass))
@ -1458,12 +1448,7 @@ public class GUI {
// Disable previous menu item and add new item to mote plugins menu // Disable previous menu item and add new item to mote plugins menu
menuItem.setEnabled(false); menuItem.setEnabled(false);
menuItem.setToolTipText("Mote plugin"); menuItem.setToolTipText("Mote plugin");
menuMotePluginClasses.add(newPluginClass);
menuItem = new JMenuItem(description);
menuItem.setActionCommand("start plugin");
menuItem.putClientProperty("class", newPluginClass);
menuItem.addActionListener(guiEventHandler);
menuMotePlugins.add(menuItem);
} }
} }
@ -1477,28 +1462,30 @@ public class GUI {
public void unregisterPlugins() { public void unregisterPlugins() {
if (menuPlugins != null) { if (menuPlugins != null) {
menuPlugins.removeAll(); menuPlugins.removeAll();
menuMotePlugins.removeAll(); menuMotePluginClasses.clear();
} }
pluginClasses.clear(); pluginClasses.clear();
pluginClassesTemporary.clear(); pluginClassesTemporary.clear();
} }
/** /**
* Show mote plugins menu for starting a mote plugin. All registered mote * Return a mote plugins submenu for given mote.
* plugins can be selected from.
* *
* @param invoker * @param mote Mote
* Component that wants to display the menu * @return Mote plugins menu
* @param mote
* Mote of plugin selected
* @param location
* Location of popup menu
*/ */
public void showMotePluginsMenu(Component invoker, Mote mote, Point location) { public JMenu createMotePluginsSubmenu(Mote mote) {
menuMotePlugins.setInvoker(invoker); JMenu menuMotePlugins = new JMenu("Open mote plugin for " + mote);
menuMotePlugins.setLocation(location);
menuMotePlugins.setVisible(true); for (Class<? extends Plugin> motePluginClass: menuMotePluginClasses) {
selectedMote = mote; JMenuItem menuItem = new JMenuItem(getDescriptionOf(motePluginClass));
menuItem.setActionCommand("start plugin");
menuItem.putClientProperty("class", motePluginClass);
menuItem.putClientProperty("mote", mote);
menuItem.addActionListener(guiEventHandler);
menuMotePlugins.add(menuItem);
}
return menuMotePlugins;
} }
// // GUI CONTROL METHODS //// // // GUI CONTROL METHODS ////
@ -1987,7 +1974,8 @@ public class GUI {
} else if (e.getActionCommand().equals("start plugin")) { } else if (e.getActionCommand().equals("start plugin")) {
Class<? extends VisPlugin> pluginClass = (Class<? extends VisPlugin>) ((JMenuItem) e Class<? extends VisPlugin> pluginClass = (Class<? extends VisPlugin>) ((JMenuItem) e
.getSource()).getClientProperty("class"); .getSource()).getClientProperty("class");
startPlugin(pluginClass, myGUI, mySimulation, selectedMote); Mote mote = (Mote) ((JMenuItem) e.getSource()).getClientProperty("mote");
startPlugin(pluginClass, myGUI, mySimulation, mote);
} else } else
logger.warn("Unhandled action: " + e.getActionCommand()); logger.warn("Unhandled action: " + e.getActionCommand());
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: Visualizer2D.java,v 1.6 2007/03/22 09:59:50 fros4943 Exp $ * $Id: Visualizer2D.java,v 1.7 2007/03/22 11:14:27 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -272,13 +272,7 @@ public abstract class Visualizer2D extends VisPlugin {
.getLocationOnScreen().y .getLocationOnScreen().y
+ y); + y);
JMenuItem menuItem = new JMenuItem("Open mote plugin for " + mote); pickMoteMenu.add(simulation.getGUI().createMotePluginsSubmenu(mote));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
simulation.getGUI().showMotePluginsMenu(canvas, mote, pos);
}
});
pickMoteMenu.add(menuItem);
} }
// Add the rest of the actions // Add the rest of the actions