コード例 #1
0
ファイル: PreferencesDialog.java プロジェクト: kdunzin/ipscan
    boolean validateChar(char c, String text, int caretPos) {
      // previous
      char pc = 0;
      for (int i = caretPos - 1; i >= 0; i--) {
        pc = text.charAt(i);
        if (!Character.isWhitespace(pc)) break;
      }

      boolean isCurDigit = c >= '0' && c <= '9';
      boolean isPrevDigit = pc >= '0' && pc <= '9';
      return isPrevDigit && (isCurDigit || c == '-' || c == ',')
          || isCurDigit && (pc == '-' || pc == ',' || pc == 0)
          || Character.isWhitespace(c) && pc == ',';
    }
コード例 #2
0
 public boolean isDigit(int keyCode) {
   if (Character.isDigit(keyCode)
       || keyCode == SWT.DEL
       || keyCode == 8 // ascii of back space
       || keyCode == SWT.ARROW_LEFT
       || keyCode == SWT.ARROW_RIGHT) {
     return true;
   }
   return false;
 }
コード例 #3
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';
 }
コード例 #4
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();
   }
 }
コード例 #5
0
ファイル: PreferencesDialog.java プロジェクト: kdunzin/ipscan
    public void keyPressed(KeyEvent e) {
      Text portsText = (Text) e.getSource();

      if (e.keyCode == SWT.TAB) {
        portsText.getShell().traverse(SWT.TRAVERSE_TAB_NEXT);
        e.doit = false;
        return;
      } else if (e.keyCode == SWT.CR) {
        if ((e.stateMask & SWT.MOD1) > 0) {
          // allow ctrl+enter to insert newlines
          e.stateMask = 0;
        } else {
          // single-enter will traverse
          portsText.getShell().traverse(SWT.TRAVERSE_RETURN);
          e.doit = false;
          return;
        }
      } else if (Character.isISOControl(e.character)) {
        return;
      }

      e.doit = validateChar(e.character, portsText.getText(), portsText.getCaretPosition());
    }
コード例 #6
0
ファイル: JavaLineStyler.java プロジェクト: abego/java2script
    /** Returns the next lexical token in the document. */
    public int nextToken() {
      int c;
      fStartToken = fPos;
      while (true) {
        switch (c = read()) {
          case EOF:
            return EOF;
          case '/': // comment
            c = read();
            if (c == '/') {
              while (true) {
                c = read();
                if ((c == EOF) || (c == EOL)) {
                  unread(c);
                  return COMMENT;
                }
              }
            } else {
              unread(c);
            }
            return OTHER;
          case '\'': // char const
            character:
            for (; ; ) {
              c = read();
              switch (c) {
                case '\'':
                  return STRING;
                case EOF:
                  unread(c);
                  return STRING;
                case '\\':
                  c = read();
                  break;
              }
            }

          case '"': // string
            string:
            for (; ; ) {
              c = read();
              switch (c) {
                case '"':
                  return STRING;
                case EOF:
                  unread(c);
                  return STRING;
                case '\\':
                  c = read();
                  break;
              }
            }

          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            do {
              c = read();
            } while (Character.isDigit((char) c));
            unread(c);
            return NUMBER;
          default:
            if (Character.isWhitespace((char) c)) {
              do {
                c = read();
              } while (Character.isWhitespace((char) c));
              unread(c);
              return WHITE;
            }
            if (Character.isJavaIdentifierStart((char) c)) {
              fBuffer.setLength(0);
              do {
                fBuffer.append((char) c);
                c = read();
              } while (Character.isJavaIdentifierPart((char) c));
              unread(c);
              Integer i = (Integer) fgKeys.get(fBuffer.toString());
              if (i != null) return i.intValue();
              return WORD;
            }
            return OTHER;
        }
      }
    }
コード例 #7
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);
  }