/**
   * Formats an individual key into a human readable format. This uses an internationalization
   * resource bundle to look up the key. This does the platform-specific formatting for Carbon.
   *
   * @param key The key to format.
   * @return The key formatted as a string; should not be <code>null</code>.
   */
  public final String format(final int key) {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    final String name = lookup.formalNameLookup(key);

    // TODO consider platform-specific resource bundles
    if (Util.isMac()) {
      String formattedName = (String) CARBON_KEY_LOOK_UP.get(name);
      if (formattedName != null) {
        return formattedName;
      }
    }

    return super.format(key);
  }
  static {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    ALT = new ModifierKey(lookup.getAlt());
    COMMAND = new ModifierKey(lookup.getCommand());
    CTRL = new ModifierKey(lookup.getCtrl());
    SHIFT = new ModifierKey(lookup.getShift());

    modifierKeysByName.put(ModifierKey.ALT.toString(), ModifierKey.ALT);
    modifierKeysByName.put(ModifierKey.COMMAND.toString(), ModifierKey.COMMAND);
    modifierKeysByName.put(ModifierKey.CTRL.toString(), ModifierKey.CTRL);
    modifierKeysByName.put(ModifierKey.SHIFT.toString(), ModifierKey.SHIFT);
    modifierKeysByName.put(M1_NAME, Util.isMac() ? ModifierKey.COMMAND : ModifierKey.CTRL);
    modifierKeysByName.put(M2_NAME, ModifierKey.SHIFT);
    modifierKeysByName.put(M3_NAME, ModifierKey.ALT);
    modifierKeysByName.put(M4_NAME, Util.isMac() ? ModifierKey.CTRL : ModifierKey.COMMAND);
  }
示例#3
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.bindings.keys.AbstractKeyFormatter#sortModifierKeys(int)
   */
  protected int[] sortModifierKeys(final int modifierKeys) {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    final int[] sortedKeys = new int[4];
    int index = 0;

    if ((modifierKeys & lookup.getAlt()) != 0) {
      sortedKeys[index++] = lookup.getAlt();
    }
    if ((modifierKeys & lookup.getCommand()) != 0) {
      sortedKeys[index++] = lookup.getCommand();
    }
    if ((modifierKeys & lookup.getCtrl()) != 0) {
      sortedKeys[index++] = lookup.getCtrl();
    }
    if ((modifierKeys & lookup.getShift()) != 0) {
      sortedKeys[index++] = lookup.getShift();
    }

    return sortedKeys;
  }
示例#4
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.bindings.keys.KeyFormatter#format(org.eclipse.ui.keys.KeySequence)
  */
 public String format(final int key) {
   final IKeyLookup lookup = KeyLookupFactory.getDefault();
   return lookup.formalNameLookup(key);
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.bindings.keys.AbstractKeyFormatter#sortModifierKeys(int)
   */
  protected int[] sortModifierKeys(final int modifierKeys) {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    final int[] sortedKeys = new int[4];
    int index = 0;

    if (Util.isWindows()) {
      if ((modifierKeys & lookup.getCtrl()) != 0) {
        sortedKeys[index++] = lookup.getCtrl();
      }
      if ((modifierKeys & lookup.getAlt()) != 0) {
        sortedKeys[index++] = lookup.getAlt();
      }
      if ((modifierKeys & lookup.getShift()) != 0) {
        sortedKeys[index++] = lookup.getShift();
      }

    } else if (Util.isGtk() || Util.isMotif()) {
      if ((modifierKeys & lookup.getShift()) != 0) {
        sortedKeys[index++] = lookup.getShift();
      }
      if ((modifierKeys & lookup.getCtrl()) != 0) {
        sortedKeys[index++] = lookup.getCtrl();
      }
      if ((modifierKeys & lookup.getAlt()) != 0) {
        sortedKeys[index++] = lookup.getAlt();
      }

    } else if (Util.isMac()) {
      if ((modifierKeys & lookup.getShift()) != 0) {
        sortedKeys[index++] = lookup.getShift();
      }
      if ((modifierKeys & lookup.getCtrl()) != 0) {
        sortedKeys[index++] = lookup.getCtrl();
      }
      if ((modifierKeys & lookup.getAlt()) != 0) {
        sortedKeys[index++] = lookup.getAlt();
      }
      if ((modifierKeys & lookup.getCommand()) != 0) {
        sortedKeys[index++] = lookup.getCommand();
      }
    }

    return sortedKeys;
  }