List<Integer> toPositions(MenuItem i) { List<Integer> positions = new LinkedList<>(); while (i != null) { position.addFirst(i.getPosition()); i = i.getParent(); } return positions; }
public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem)e.getSource(); String cmd = e.getActionCommand(); PopupMenu popup = (PopupMenu)item.getParent(); int tool = -1; for (int i=CUSTOM1; i<getNumTools(); i++) { if (popup==menus[i]) { tool = i; break; } } if (tool==-1) return; if (tools[tool]!=null) tools[tool].runMenuTool(names[tool], cmd); }
public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem)e.getSource(); String cmd = e.getActionCommand(); PopupMenu popup = (PopupMenu)item.getParent(); int tool = -1; for (int i=CUSTOM1; i<getNumTools(); i++) { if (popup==menus[i]) { tool = i; break; } } if (tool==-1) return; if (tools[tool]!=null) tools[tool].runMenuTool(names[tool], cmd); }
/** Handles CheckboxMenuItem state changes. */ public void itemStateChanged(ItemEvent e) { MenuItem item = (MenuItem)e.getSource(); MenuComponent parent = (MenuComponent)item.getParent(); String cmd = e.getItem().toString(); if ("Autorun Examples".equals(cmd)) // Examples>Autorun Examples Prefs.autoRunExamples = e.getStateChange()==1; else if ((Menu)parent==Menus.window) WindowManager.activateWindow(cmd, item); else doCommand(cmd); }
public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); ImageJ.setCommandName(cmd); MenuItem item = (MenuItem)evt.getSource(); MenuContainer parent = item.getParent(); if (parent instanceof PopupMenu) { for (int i=0; i<nMacros; i++) { if (macroNames[i].equals("Popup Menu")) { new MacroRunner(pgm, macroStarts[i], "Popup Menu", cmd); return; } } } runMacro(cmd); }
public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); ImageJ.setCommandName(cmd); MenuItem item = (MenuItem)evt.getSource(); MenuContainer parent = item.getParent(); if (parent instanceof PopupMenu) { for (int i=0; i<nMacros; i++) { if (macroNames[i].equals("Popup Menu")) { new MacroRunner(pgm, macroStarts[i], "Popup Menu", cmd); return; } } } runMacro(cmd); }
/** Handles CheckboxMenuItem state changes. */ public void itemStateChanged(ItemEvent e) { MenuItem item = (MenuItem)e.getSource(); MenuComponent parent = (MenuComponent)item.getParent(); String cmd = e.getItem().toString(); if ("Autorun Examples".equals(cmd)) // Examples>Autorun Examples Prefs.autoRunExamples = e.getStateChange()==1; else if ((Menu)parent==Menus.window) WindowManager.activateWindow(cmd, item); else doCommand(cmd); }
if (invoker == null) { top = item.getParent(); while (top instanceof Menu && !(((Menu)top).getParent() instanceof MenuBar)) { top = item.getParent(); while (top instanceof Menu && !(((Menu)top).getParent() instanceof Component)) { while (mi.getParent() != top) { mi = (MenuItem)mi.getParent(); path = mi.getLabel() + "|" + path;
private void setMenu(final Table table) { Listener popUpListener = new Listener() { @Override public void handleEvent(Event event) { MenuItem item = (MenuItem)event.widget; Menu pare = item.getParent(); Decorations fdf = pare.getParent(); // Now you can access the table from within the Listener System.out.println(table); } }; Menu menu = new Menu(table); // where table1 is your table MenuItem item1 = new MenuItem(menu, SWT.PUSH); item1.setText("Copy cell"); item1.addListener(SWT.Selection, popUpListener); MenuItem item2 = new MenuItem(menu, SWT.PUSH); item2.setText("Copy row"); item2.addListener(SWT.Selection, popUpListener); MenuItem item3 = new MenuItem(menu, SWT.PUSH); item3.setText("Copy column"); item3.addListener(SWT.Selection, popUpListener); MenuItem item4 = new MenuItem(menu, SWT.PUSH); item4.setText("Copy all"); item4.addListener(SWT.Selection, popUpListener); table.setMenu(menu); }