Ejemplo n.º 1
0
  private InputModifiers forceDefaultModifier(final InputModifiers modifiers) {
    final boolean forceMeta = Accelerator.isCtrlReplacedWithMeta();
    final boolean forceCtrl = !forceMeta;

    final boolean alt = modifiers.isAltDown();
    final boolean altGr = modifiers.isAltGrDown();
    final boolean ctrl = forceCtrl || modifiers.isCtrlDown();
    final boolean meta = forceMeta || modifiers.isMetaDown();
    final boolean shift = modifiers.isShiftDown();

    return new InputModifiers(alt, altGr, ctrl, meta, shift, false, false, false);
  }
Ejemplo n.º 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);
    }
  }