Example #1
0
  private ModuleInfo createInfo(final String key, final URL url) {
    // set menu path
    final String[] subPaths = key.split("/");
    final MenuPath menuPath = new MenuPath();
    menuPath.add(new MenuEntry(MenuConstants.IMAGE_LABEL));
    menuPath.add(new MenuEntry("Lookup Tables"));
    for (int i = 0; i < subPaths.length - 1; i++) {
      menuPath.add(new MenuEntry(subPaths[i]));
    }
    final MenuEntry leaf = new MenuEntry(tableName(subPaths[subPaths.length - 1]));
    leaf.setWeight(50); // set menu position: TODO - do this properly
    menuPath.add(leaf);

    // hard code path to open as a preset
    final HashMap<String, Object> presets = new HashMap<String, Object>();
    presets.put("tableURL", url);
    // and create the command info
    // CTR FIXME: Avoid circular dependency between ij-data and ij-commands.
    final CommandInfo info = new CommandInfo("imagej.plugins.commands.misc.ApplyLookupTable");
    info.setPresets(presets);
    info.setMenuPath(menuPath);
    // use the default icon
    // info.setIconPath(iconPath);

    return info;
  }
Example #2
0
  private void parseMenu(
      final MenuItem menuItem,
      final double weight,
      final MenuPath path,
      final Map<String, MenuPath> menuTable) {
    // build menu entry
    final String name = menuItem.getLabel();
    final MenuEntry entry = new MenuEntry(name, weight);
    final MenuShortcut shortcut = menuItem.getShortcut();
    if (shortcut != null) {
      // convert AWT MenuShortcut to ImageJ Accelerator
      final int code = shortcut.getKey();
      final boolean meta = Accelerator.isCtrlReplacedWithMeta();
      final boolean ctrl = !meta;
      final boolean shift = shortcut.usesShiftModifier();
      final KeyCode keyCode = KeyCode.get(code);
      final InputModifiers modifiers =
          new InputModifiers(false, false, ctrl, meta, shift, false, false, false);
      final Accelerator acc = new Accelerator(keyCode, modifiers);
      entry.setAccelerator(acc);
    }
    path.add(entry);

    if (menuItem instanceof Menu) { // non-leaf
      // recursively process child menu items
      final Menu menu = (Menu) menuItem;
      final int itemCount = menu.getItemCount();
      double w = -1;
      for (int i = 0; i < itemCount; i++) {
        final MenuItem item = menu.getItem(i);
        final boolean isSeparator = item.getLabel().equals("-");
        if (isSeparator) w += 10;
        else w += 1;
        parseMenu(item, w, new MenuPath(path), menuTable);
      }
    } else { // leaf item
      // add menu item to table
      menuTable.put(menuItem.getLabel(), path);
    }
  }