Пример #1
0
 public void mouseMoved(MouseEvent e) {
   int k = html.viewToModel(e.getPoint());
   if (html.hasFocus() && html.getSelectionStart() <= k && k < html.getSelectionEnd()) {
     setMessage("(on selection)", MOVE);
     return;
   }
   String s = text.getText(); // "";
   int m = s.length(); // html.getDocument().getLength();
   /*try {
          s = html.getText(0, m);
      } catch (BadLocationException x) {
   setMessage("BadLocation "+m, TEXT); return;
      } */
   if (!Character.isLetter(s.charAt(k))) {
     setMessage("(not a letter)", TEXT);
     return;
   }
   selB = k;
   selE = k + 1;
   while (!Character.isWhitespace(s.charAt(selB - 1))) selB--;
   while (!Character.isWhitespace(s.charAt(selE))) selE++;
   setMessage(selB + "-" + selE, HAND);
   word = "";
   for (int i = selB; i < selE; i++) if (Character.isLetter(s.charAt(i))) word += s.charAt(i);
   html.setToolTipText(word);
 }
  @Override
  public void keyPressed(final KeyEvent e) {
    if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) {
      if (!Character.isLetter(e.getKeyChar())) {
        return;
      }

      final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject());
      final ActionCallback firstCharTyped = new ActionCallback();
      focusManager.typeAheadUntil(firstCharTyped);
      myPanel.moveDown();
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                final Robot robot = new Robot();
                final boolean shiftOn = e.isShiftDown();
                final int code = e.getKeyCode();
                if (shiftOn) {
                  robot.keyPress(KeyEvent.VK_SHIFT);
                }
                robot.keyPress(code);
                robot.keyRelease(code);

                // don't release Shift
                firstCharTyped.setDone();
              } catch (AWTException ignored) {
              }
            }
          });
    }
  }
Пример #3
0
 /** Returns the contents of the next text field. */
 public String getNextString() {
   String theText;
   if (stringField == null) return "";
   TextField tf = (TextField) (stringField.elementAt(sfIndex));
   theText = tf.getText();
   if (macro) {
     String label = (String) labels.get((Object) tf);
     theText = Macro.getValue(macroOptions, label, theText);
     if (theText != null
         && (theText.startsWith("&") || label.toLowerCase(Locale.US).startsWith(theText))) {
       // Is the value a macro variable?
       if (theText.startsWith("&")) theText = theText.substring(1);
       Interpreter interp = Interpreter.getInstance();
       String s = interp != null ? interp.getVariableAsString(theText) : null;
       if (s != null) theText = s;
     }
   }
   if (recorderOn) {
     String s = theText;
     if (s != null
         && s.length() >= 3
         && Character.isLetter(s.charAt(0))
         && s.charAt(1) == ':'
         && s.charAt(2) == '\\')
       s = s.replaceAll("\\\\", "\\\\\\\\"); // replace "\" with "\\" in Windows file paths
     if (!smartRecording || !s.equals((String) defaultStrings.elementAt(sfIndex)))
       recordOption(tf, s);
     else if (Recorder.getCommandOptions() == null) Recorder.recordOption(" ");
   }
   sfIndex++;
   return theText;
 }
Пример #4
0
 private String readString(JTextComponent textComponent) throws IncorrectInputException {
   String text = textComponent.getText();
   if (Character.isLetter(text.charAt(0)) || Character.isDigit(text.charAt(0))) {
     return text;
   } else {
     throw new IncorrectInputException("wrong input");
   }
 }
Пример #5
0
 /**
  * Checks if a string contains anything but spaces - needed for text field validation
  *
  * @param inputSting
  * @return
  * @param inputString
  */
 private static boolean containsText(final String inputString) {
   boolean stringContainsText = false;
   if (!inputString.equals("")) {
     for (int i = 0; i < inputString.length(); i++) {
       char chr = inputString.charAt(i);
       if (Character.isDigit(chr) || Character.isLetter(chr)) stringContainsText = true;
     }
   }
   return stringContainsText;
 }
Пример #6
0
 public void processKeyEvent(KeyEvent ev) {
   char c = ev.getKeyChar();
   if ((Character.isLetter(c) && !ev.isAltDown()) || badchars.indexOf(c) > -1) {
     ev.consume();
     return;
   }
   if (c == '-' && getDocument().getLength() > 0) ev.consume();
   else {
     super.processKeyEvent(ev);
   }
 }
Пример #7
0
  /**
   * Retrieves the word on which the mouse pointer is present
   *
   * @param evt - the MouseEvent which triggered this method
   */
  private String fetchPhrase(MouseEvent evt) {
    Messages.log("--handle Mouse Right Click--");
    int off = xyToOffset(evt.getX(), evt.getY());
    if (off < 0) return null;
    int line = getLineOfOffset(off);
    if (line < 0) return null;
    String s = getLineText(line);
    if (s == null) return null;
    else if (s.length() == 0) return null;
    else {
      int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
      int xLS = off - getLineStartNonWhiteSpaceOffset(line);
      Messages.log("x=" + x);
      if (x < 0 || x >= s.length()) return null;
      String word = s.charAt(x) + "";
      if (s.charAt(x) == ' ') return null;
      if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s.charAt(x) == '$'))
        return null;
      int i = 0;
      while (true) {
        i++;
        if (x1 >= 0 && x1 < s.length()) {
          if (Character.isLetter(s.charAt(x1)) || s.charAt(x1) == '_') {
            word = s.charAt(x1--) + word;
            xLS--;
          } else x1 = -1;
        } else x1 = -1;

        if (x2 >= 0 && x2 < s.length()) {
          if (Character.isLetterOrDigit(s.charAt(x2)) || s.charAt(x2) == '_' || s.charAt(x2) == '$')
            word = word + s.charAt(x2++);
          else x2 = -1;
        } else x2 = -1;

        if (x1 < 0 && x2 < 0) break;
        if (i > 200) {
          // time out!
          break;
        }
      }
      if (Character.isDigit(word.charAt(0))) {
        return null;
      }
      Messages.log("Mouse click, word: " + word.trim());
      ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator();
      synchronized (astGenerator) {
        astGenerator.setLastClickedWord(line, word, xLS);
      }
      return word.trim();
    }
  }
Пример #8
0
  public void keyPressed(int key, char c) {
    if (textInput) {
      if (key == Input.KEY_BACK) {
        if (worldName.length() > 0) {
          worldName = worldName.substring(0, worldName.length() - 1);
        }
      } else {
        if (worldName.length() < 15) {

          if (Character.isDefined(c))
            if (Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c)) {
              worldName += c;
            }
        }
      }
    }
  }
Пример #9
0
  public static void convertCangjieHK() {
    try {
      Font font = new Font("Droid Sans Fallback", 16, Font.PLAIN);
      ArrayList<String> codeList = new ArrayList<String>();
      HashMap<String, ArrayList<CangjieChar>> codeMap =
          new HashMap<String, ArrayList<CangjieChar>>();
      int totalCangjieColumn = 7;
      FileInputStream fis = new FileInputStream("cangjie3.txt");
      InputStreamReader input = new InputStreamReader(fis, "UTF-8");
      BufferedReader reader = new BufferedReader(input);
      String str = null;
      int index = 0;
      int total = 0;
      char column[] = new char[5];
      boolean hkchar = false;

      System.out.println("#define CANGJIE_COLUMN " + totalCangjieColumn);
      System.out.println("const jchar cangjie[][CANGJIE_COLUMN] = {");
      do {
        str = reader.readLine();
        if (str == null) break;
        if (str.compareTo("#####") == 0) {
          hkchar = true;
          continue;
        }
        index = str.indexOf('\t');
        if (index < 0) index = str.indexOf(' ');
        if (index > 0 && font.canDisplay(str.charAt(index + 1))) {
          int type = Character.getType(str.charAt(index + 1));
          if (Character.isLetter(str.charAt(index + 1))
              || type == Character.START_PUNCTUATION
              || type == Character.END_PUNCTUATION
              || type == Character.OTHER_PUNCTUATION
              || type == Character.MATH_SYMBOL
              || type == Character.DASH_PUNCTUATION
              || type == Character.CONNECTOR_PUNCTUATION
              || type == Character.OTHER_SYMBOL
              || type == Character.INITIAL_QUOTE_PUNCTUATION
              || type == Character.FINAL_QUOTE_PUNCTUATION
              || type == Character.SPACE_SEPARATOR) {
            // System.out.print("\t { ");
            // for (int count = 0; count < 5; count++) {
            //     if (count < index) {
            // 	column[count] = str.charAt(count);
            // 	if (column[count] < 'a' || column[count] > 'z') column[count] = 0;
            // 	if (((int) column[count]) >= 10 || ((int) column[count]) <= 99) System.out.print('
            // ');
            // 	if (((int) column[count]) <= 9) System.out.print(' ');
            // 	System.out.print(((int)	column[count]));
            //     } else {
            // 	System.out.print("  0");
            //     }
            //     System.out.print(", ");
            // }
            // System.out.println((int) str.charAt(index + 1) + " }, ");

            String cangjie = str.substring(0, index).trim();
            char ch = str.charAt(index + 1);
            if (!codeList.contains(cangjie)) codeList.add(cangjie);
            ArrayList<CangjieChar> list = null;
            if (codeMap.containsKey(cangjie)) {
              list = codeMap.get(cangjie);
            } else {
              list = new ArrayList<CangjieChar>();
            }
            CangjieChar cc = new CangjieChar(ch, hkchar);
            list.add(cc);
            codeMap.put(cangjie, list);

            total++;
          } else {
            System.err.println(
                "Character Not Found : "
                    + str.charAt(index + 1)
                    + " "
                    + Character.getType(str.charAt(index + 1)));
          }
        }
      } while (str != null);

      Collections.sort(codeList);

      for (int count0 = 0; count0 < codeList.size(); count0++) {
        String _str = codeList.get(count0);
        ArrayList<CangjieChar> ca = codeMap.get(_str);
        for (int count1 = 0; count1 < ca.size(); count1++) {
          for (int count2 = 0; count2 < 5; count2++) {
            if (count2 < _str.length()) System.out.print("'" + _str.charAt(count2) + "', ");
            else System.out.print("  0, ");
          }
          System.out.println(((int) ca.get(count1).c) + ", " + (ca.get(count1).hk ? 1 : 0) + ", ");
        }
      }

      System.out.println("};");
      System.out.println("jint cangjie_index[" + total + "];");
      System.out.println("jint cangjie_frequency[" + total + "];");
      reader.close();
      input.close();
      fis.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
    public void actionPerformed(ActionEvent ae) {
      try {

        Integer num1 = Integer.parseInt(tfdid.getText());
        if (num1.equals(null)) {
          System.out.println("num");
          throw new BlankException();
        }

        String name1 = tfname.getText();
        int a;
        a = name1.charAt(0);
        if (name1.equals("") || a == 32) {
          throw new BlankException();
        } else {
          for (int i = 0; i < name1.length(); i++) {
            boolean check = Character.isLetter(name1.charAt(i));
            a = name1.charAt(i);
            System.out.print("  " + a);
            if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122) || (a == 32) || (a == 46))) {
              throw new NameEx();
            }
          }
        }

        String addr1 = taadd.getText();
        if (addr1.equals(null)) {
          System.out.println("addr");
          throw new BlankException();
        }

        String contact1 = tftel.getText();

        String spec1 = taspecial.getText();
        String workf1 = tfworkf.getText();
        String workt1 = tfworkt.getText();

        String str =
            "UPDATE DOC SET name=?,address=?,contact=?,specialization=?,workfrom=?,workto=? WHERE did=?";

        Statement st1 = cn.createStatement();

        PreparedStatement psmt = cn.prepareStatement(str);
        psmt.setString(1, name1);
        psmt.setString(2, addr1);
        psmt.setString(3, contact1);
        psmt.setString(4, spec1);
        psmt.setString(5, workf1);
        psmt.setString(6, workt1);
        psmt.setInt(7, num1);

        psmt.executeUpdate();

        JOptionPane.showMessageDialog(
            new JFrame(), "Data Modified successfully!", "Done!", JOptionPane.INFORMATION_MESSAGE);

      } catch (SQLException sq) {
        String message = "Enter Valid Doctor ID and Contact.";
        JOptionPane.showMessageDialog(new JFrame(), message, "ERROR!", JOptionPane.ERROR_MESSAGE);
        System.out.println(sq);
      } catch (BlankException be) {
        JOptionPane.showMessageDialog(
            new JFrame(), "Please Enter All The Fields", "ERROR!", JOptionPane.ERROR_MESSAGE);
      } catch (NumberFormatException nfe) {
        JOptionPane.showMessageDialog(
            new JFrame(),
            "Patient Number and Contact Number Must Contain Digits.",
            "ERROR!",
            JOptionPane.ERROR_MESSAGE);
      } catch (NameEx ne) {
        JOptionPane.showMessageDialog(
            new JFrame(), "Invalid Name", "ERROR!", JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(
            new JFrame(), "Enter Valid Date", "Error", JOptionPane.ERROR_MESSAGE);
      }
    }
Пример #11
0
  @Override
  protected int drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
      throws BadLocationException {
    Document doc = getDocument();
    Segment segment = new Segment();
    Segment token = getLineBuffer();

    doc.getText(p0, p1 - p0, segment);

    int count = p1 - p0;
    int left = 0;

    int state = TEXT;

    int elementIndex = doc.getDefaultRootElement().getElementIndex(p0);

    AttributeSet lineAttributes =
        doc.getDefaultRootElement().getElement(elementIndex).getAttributes();

    if (lineAttributes.isDefined("inComment")) {
      state = MULTILINECOMMENT;
    }

    for (int i = 0; i < count; i++) {
      // Starting in default text state.
      if (state == TEXT) {
        if (Character.isLetter(segment.array[i + segment.offset])
            && Character.isLowerCase(segment.array[i + segment.offset])) {
          // flush now
          g.setColor(textColor);
          doc.getText(p0 + left, i - left, token);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = KEYWORD;
        } // Do nothing
        else {
          if (segment.array[i + segment.offset] == '/') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = STRING;
          }
        }
      } else if (state == KEYWORD) {
        // Still
        if (Character.isLetter(
            segment
                .array[
                i
                    + segment
                        .offset])) { // && Character.isLowerCase(segment.array[i+segment.offset]))
        } else {
          // flush now
          doc.getText(p0 + left, i - left, token);
          if (Keywords.isKeyword(token)) {
            g.setColor(keywordColor);
          } else {
            g.setColor(textColor);
          }
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = TEXT;
          if (segment.array[i + segment.offset] == '/') {
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            state = STRING;
          }
        }
      } else if (state == COMMENT) {
        if (segment.array[i + segment.offset] == '/') {
          break;
        } else if (segment.array[i + segment.offset] == '*') {
          state = MULTILINECOMMENT;
        } else {
          state = TEXT;
        }
      } else if (state == MULTILINECOMMENT) {
        if (i > 0
            && segment.array[i + segment.offset] == '/'
            && segment.array[i + segment.offset - 1] == '*') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(commentColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      } else if (state == STRING) {
        if (segment.array[i + segment.offset] == '"') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(stringColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      }
      // Starting not in token
    } // end loop
    // Flush last
    doc.getText(p0 + left, p1 - p0 - left, token);
    if (state == KEYWORD) {
      if (Keywords.isKeyword(token)) {
        g.setColor(keywordColor);
      } else {
        g.setColor(textColor);
      }
    } else if (state == STRING) {
      g.setColor(stringColor);
    } else if (state == COMMENT && ((p1 - p0 - left) > 1)) {
      g.setColor(commentColor);
    } else if (state == MULTILINECOMMENT) {
      g.setColor(commentColor);
    } else {
      g.setColor(textColor);
    }
    x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);

    return x;
  }