Exemplo n.º 1
0
 @NotNull
 private static KeyStroke getTypedOrPressedKeyStroke(char c, int modifiers) {
   if (modifiers == 0) {
     return getKeyStroke(c);
   } else if (modifiers == SHIFT_MASK) {
     return getKeyStroke(Character.toUpperCase(c));
   } else {
     return getKeyStroke(Character.toUpperCase(c), modifiers);
   }
 }
Exemplo n.º 2
0
 /** Set the text of an XML element, safely encode it if needed. */
 @NotNull
 public static Element setSafeXmlText(@NotNull Element element, @NotNull String text) {
   final Character first = firstCharacter(text);
   final Character last = lastCharacter(text);
   if (!StringHelper.isXmlCharacterData(text)
       || first != null && Character.isWhitespace(first)
       || last != null && Character.isWhitespace(last)) {
     element.setAttribute("encoding", "base64");
     final String encoded = new String(Base64.encodeBase64(text.getBytes()));
     element.setText(encoded);
   } else {
     element.setText(text);
   }
   return element;
 }
Exemplo n.º 3
0
  public static boolean containsUpperCase(@NotNull String text) {
    for (int i = 0; i < text.length(); i++) {
      if (Character.isUpperCase(text.charAt(i)) && (i == 0 || text.charAt(i - 1) == '\\')) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 4
0
  @NotNull
  public static String toKeyNotation(@NotNull KeyStroke key) {
    final char c = key.getKeyChar();
    final int keyCode = key.getKeyCode();
    final int modifiers = key.getModifiers();

    if (c != CHAR_UNDEFINED && !isControlCharacter(c)) {
      return String.valueOf(c);
    }

    String prefix = "";
    if ((modifiers & META_MASK) != 0) {
      prefix += "M-";
    }
    if ((modifiers & ALT_MASK) != 0) {
      prefix += "A-";
    }
    if ((modifiers & CTRL_MASK) != 0) {
      prefix += "C-";
    }
    if ((modifiers & SHIFT_MASK) != 0) {
      prefix += "S-";
    }

    String name = VIM_KEY_VALUES.get(keyCode);
    if (name != null) {
      if (UPPERCASE_DISPLAY_KEY_NAMES.contains(name)) {
        name = name.toUpperCase();
      } else {
        name = StringUtil.capitalize(name);
      }
    }
    if (name == null) {
      final String escape = toEscapeNotation(key);
      if (escape != null) {
        return escape;
      }

      try {
        name = String.valueOf(Character.toChars(keyCode));
      } catch (IllegalArgumentException ignored) {
      }
    }

    return name != null ? "<" + prefix + name + ">" : "<<" + key.toString() + ">>";
  }