コード例 #1
0
 /*
  * Return the lowercase of the first non-'&' character following
  * an '&' character in the given string. If there are no '&'
  * characters in the given string, return '\0'.
  */
 char _findMnemonic(String string) {
   if (string == null) return '\0';
   int index = 0;
   int length = string.length();
   do {
     while (index < length && string.charAt(index) != '&') index++;
     if (++index >= length) return '\0';
     if (string.charAt(index) != '&') return Character.toLowerCase(string.charAt(index));
     index++;
   } while (index < length);
   return '\0';
 }
コード例 #2
0
 void onMnemonic(TraverseEvent event) {
   char mnemonic = _findMnemonic(text);
   if (mnemonic == '\0') return;
   if (Character.toLowerCase(event.character) != mnemonic) return;
   Composite control = this.getParent();
   while (control != null) {
     Control[] children = control.getChildren();
     int index = 0;
     while (index < children.length) {
       if (children[index] == this) break;
       index++;
     }
     index++;
     if (index < children.length) {
       if (children[index].setFocus()) {
         event.doit = true;
         event.detail = SWT.TRAVERSE_NONE;
       }
     }
     control = control.getParent();
   }
 }
コード例 #3
0
  private static long decodeDisplayLong(String val) throws Exception {

    char[] chars = val.trim().toCharArray();

    String digits = "";
    String units = "";

    for (char c : chars) {

      if (Character.isDigit(c)) {

        if (units.length() > 0) {

          throw (new Exception("Invalid unit"));
        }

        digits += c;

      } else {

        if (digits.length() == 0) {

          throw (new Exception("Missing digits"));

        } else if (units.length() == 0 && Character.isWhitespace(c)) {

        } else {

          units += c;
        }
      }
    }

    long value = Long.parseLong(digits);

    if (units.length() == 0) {

      units = "m";
    }

    if (units.length() > 0) {

      char c = Character.toLowerCase(units.charAt(0));

      if (c == 'k') {

        value = value * 1024;

      } else if (c == 'm') {

        value = value * 1024 * 1024;

      } else if (c == 'g') {

        value = value * 1024 * 1024 * 1024;

      } else {

        throw (new Exception("Invalid size unit '" + units + "'"));
      }
    }

    return (value);
  }