Exemple #1
1
  public String getTextForGesture(long parId, Point topLeft, Point bottomRight) {

    try {
      Paragraph p = lockManager.getParFromId(parId);

      int parY = documentPanel.textPane.modelToView(p.getOffset()).y;

      topLeft.y = topLeft.y + parY;
      bottomRight.y = bottomRight.y + parY;

      int startOffset = documentPanel.textPane.viewToModel(topLeft);
      int endOffset = documentPanel.textPane.viewToModel(bottomRight);

      while (startOffset > 0
          && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0))))
        startOffset--;

      while (endOffset < document.getLength()
          && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++;

      String text = document.getText(startOffset, endOffset - startOffset);
      return text;
    } catch (Exception e) {
      System.out.println("EditorClient: addGestureAction. error identifying text");
      e.printStackTrace();
      return "";
    }

    // return "PLACEBO";
  }
Exemple #2
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();
    }
  }
Exemple #3
0
 public boolean isBullet(Cell cell) {
   char c = get(cell);
   return (c == 'o' || c == '*')
       && isBlank(cell.getEast())
       && isBlank(cell.getWest())
       && Character.isLetterOrDigit(get(cell.getEast().getEast()));
 }
Exemple #4
0
 /**
  * ** Returns true if the specified character should be hex-encoded in a URL ** @param ch The
  * character to test ** @return True if the specified character should be hex-encoded in a URL
  */
 private static boolean shouldEncodeArgChar(char ch) {
   if (Character.isLetterOrDigit(ch)) {
     return false;
   } else if ((ch == '_') || (ch == '-') || (ch == '.')) {
     return false;
   } else {
     return true;
   }
 }
 private static void printResultGrid(char[][] grid) {
   if (DEBUG) {
     String res = "Results: ";
     for (char[] text : grid) {
       res += "\n";
       for (char ch : text)
         if (Character.isLetterOrDigit(ch)) res += ch + "|";
         else res += USELES_XOR_CHAR + "|";
     }
     System.out.println(res);
   }
 }
Exemple #6
0
 public static String cleanString(String in) {
   StringBuffer out = new StringBuffer();
   char c;
   for (int i = 0; i < in.length(); i++) {
     c = in.charAt(i);
     if (c == ' ' || c == '-') out.append('_');
     else if (Character.isLetterOrDigit(c)) {
       out.append(c);
     }
   }
   return out.toString().toLowerCase();
 }
Exemple #7
0
  /**
   * Handles info messages resulting from a query execution.
   *
   * @param msg info message
   * @return true if error was found
   */
  private boolean error(final String msg) {
    final String line = msg.replaceAll("[\\r\\n].*", "");
    Matcher m = XQERROR.matcher(line);
    int el, ec = 2;
    if (!m.matches()) {
      m = XMLERROR.matcher(line);
      if (!m.matches()) return true;
      el = Integer.parseInt(m.group(1));
      errFile = getEditor().file.path();
    } else {
      el = Integer.parseInt(m.group(1));
      ec = Integer.parseInt(m.group(2));
      errFile = m.group(3);
    }

    final EditorArea edit = find(IO.get(errFile), false);
    if (edit == null) return true;

    // find approximate error position
    final int ll = edit.last.length;
    int ep = ll;
    for (int e = 1, l = 1, c = 1; e < ll; ++c, e += cl(edit.last, e)) {
      if (l > el || l == el && c == ec) {
        ep = e;
        break;
      }
      if (edit.last[e] == '\n') {
        ++l;
        c = 0;
      }
    }
    if (ep < ll && Character.isLetterOrDigit(cp(edit.last, ep))) {
      while (ep > 0 && Character.isLetterOrDigit(cp(edit.last, ep - 1))) ep--;
    }
    edit.error(ep);
    errPos = ep;
    return true;
  }
Exemple #8
0
 /**
  * ** Returns true if the URL starts with a protocol definition (ie. "http://...") ** @param url
  * The URL to test ** @return True if the URL starts with a protocol definition
  */
 public static boolean isAbsoluteURL(String url) {
   if (url == null) {
     return false;
   } else {
     // per "http://en.wikipedia.org/wiki/URI_scheme" all URL "schemes" contain only
     // alphanumeric or "." characters, and appears to be < 16 characters in length.
     for (int i = 0; (i < 16) && (i < url.length()); i++) {
       char ch = url.charAt(i);
       if (ch == ':') {
         return true; // A colon is the first non-alphanumeric we ran in to
       } else if (!Character.isLetterOrDigit(ch) && (ch != '.')) {
         return false;
       }
     }
     return false;
   }
 }
  private void processKeyEvent(KeyEvent e) {
    if (e.isAltDown()) return;
    if (mySearchPopup != null) {
      mySearchPopup.processKeyEvent(e);
      return;
    }
    if (!isSpeedSearchEnabled()) return;
    if (e.getID() == KeyEvent.KEY_TYPED) {
      if (!UIUtil.isReallyTypedEvent(e)) return;

      char c = e.getKeyChar();
      if (Character.isLetterOrDigit(c) || c == '_' || c == '*' || c == '/' || c == ':') {
        manageSearchPopup(new SearchPopup(String.valueOf(c)));
        e.consume();
      }
    }
  }
    /**
     * Handles the mnemonics for the menu items. Will also handle duplicate mnemonics. Perhaps this
     * should be moved into BasicPopupMenuUI. See 4670831
     */
    public void menuKeyPressed(MenuKeyEvent e) {
      // Handle the case for Escape or Enter...
      char keyChar = e.getKeyChar();
      if (!Character.isLetterOrDigit(keyChar)) return;

      MenuSelectionManager manager = e.getMenuSelectionManager();
      MenuElement selectedPath[] = manager.getSelectedPath();

      for (int i = selectedPath.length - 1; i >= 0; i--) {
        if (selectedPath[i] == menuItem) {
          JPopupMenu popupMenu = ((JMenu) menuItem).getPopupMenu();
          MenuElement items[] = popupMenu.getSubElements();

          int index = -1;

          for (int j = 0; j < items.length; j++) {
            int key = ((JMenuItem) items[j]).getMnemonic();
            if (Character.toLowerCase((char) key) == Character.toLowerCase(keyChar)) {
              index = j;
              break;
            }
          }

          if (index != -1) {
            // Invoke the menu action
            JMenuItem item = (JMenuItem) items[index];
            if (!(item instanceof JMenu)) {
              // Let Submenus be handled by menuKeyTyped
              manager.clearSelectedPath();
              item.doClick();
            }
          }

          e.consume();
          return;
        }
      }
    }
Exemple #11
0
 /**
  * Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate
  * character that will make the line continuous (| for vertical and - for horizontal lines)
  */
 public void replaceTypeOnLine() {
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       char c = get(xi, yi);
       if (Character.isLetterOrDigit(c)) {
         boolean isOnHorizontalLine = isOnHorizontalLine(xi, yi);
         boolean isOnVerticalLine = isOnVerticalLine(xi, yi);
         if (isOnHorizontalLine && isOnVerticalLine) {
           set(xi, yi, '+');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with +");
         } else if (isOnHorizontalLine) {
           set(xi, yi, '-');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with -");
         } else if (isOnVerticalLine) {
           set(xi, yi, '|');
           if (DEBUG) System.out.println("replaced type on line '" + c + "' with |");
         }
       }
     }
   }
 }
 /**
  * Checks to see if the specified character is a delimiter. We consider a character a delimiter if
  * it is anything but a letter or digit.
  *
  * @param c the character to test
  * @return true if it is a delimiter
  */
 private boolean isDelimiter(char c) {
   return !Character.isLetterOrDigit(c);
 }
Exemple #13
0
 private static boolean isWordCharacter(char character) {
   return Character.isLetterOrDigit(character);
 }
  @NotNull
  private Pattern getPattern(String pattern) {
    if (!Comparing.strEqual(pattern, myPattern)) {
      myCompiledPattern = null;
      myPattern = pattern;
    }
    if (myCompiledPattern == null) {
      boolean allowToLower = true;
      final int eol = pattern.indexOf('\n');
      if (eol != -1) {
        pattern = pattern.substring(0, eol);
      }
      if (pattern.length() >= 80) {
        pattern = pattern.substring(0, 80);
      }

      final @NonNls StringBuffer buffer = new StringBuffer();

      if (containsOnlyUppercaseLetters(pattern)) {
        allowToLower = false;
      }

      if (allowToLower) {
        buffer.append(".*");
      }

      boolean firstIdentifierLetter = true;
      for (int i = 0; i < pattern.length(); i++) {
        final char c = pattern.charAt(i);
        if (Character.isLetterOrDigit(c)) {
          // This logic allows to use uppercase letters only to catch the name like PDM for
          // PsiDocumentManager
          if (Character.isUpperCase(c) || Character.isDigit(c)) {

            if (!firstIdentifierLetter) {
              buffer.append("[^A-Z]*");
            }

            buffer.append("[");
            buffer.append(c);
            if (allowToLower || i == 0) {
              buffer.append('|');
              buffer.append(Character.toLowerCase(c));
            }
            buffer.append("]");
          } else if (Character.isLowerCase(c)) {
            buffer.append('[');
            buffer.append(c);
            buffer.append('|');
            buffer.append(Character.toUpperCase(c));
            buffer.append(']');
          } else {
            buffer.append(c);
          }

          firstIdentifierLetter = false;
        } else if (c == '*') {
          buffer.append(".*");
          firstIdentifierLetter = true;
        } else if (c == '.') {
          buffer.append("\\.");
          firstIdentifierLetter = true;
        } else if (c == ' ') {
          buffer.append("[^A-Z]*\\ ");
          firstIdentifierLetter = true;
        } else {
          firstIdentifierLetter = true;
          // for standard RegExp engine
          // buffer.append("\\u");
          // buffer.append(Integer.toHexString(c + 0x20000).substring(1));

          // for OROMATCHER RegExp engine
          buffer.append("\\x");
          buffer.append(Integer.toHexString(c + 0x20000).substring(3));
        }
      }

      buffer.append(".*");

      try {
        myCompiledPattern = new Perl5Compiler().compile(buffer.toString());
      } catch (MalformedPatternException e) {
        // do nothing
      }
    }

    return myCompiledPattern;
  }
Exemple #15
0
    private void doDoubleClick(MouseEvent evt, int line, int offset, int dot)
        throws BadLocationException {
      // Ignore empty lines
      if (getLineLength(line) == 0) return;

      try {
        int bracket = TextUtilities.findMatchingBracket(document, Math.max(0, dot - 1));
        if (bracket != -1) {
          int mark = getMarkPosition();
          // Hack
          if (bracket > mark) {
            bracket++;
            mark--;
          }
          select(mark, bracket);
          return;
        }
      } catch (BadLocationException bl) {
        bl.printStackTrace();
      }

      // Ok, it's not a bracket... select the word
      String lineText = getLineText(line);
      char ch = lineText.charAt(Math.max(0, offset - 1));

      String noWordSep = (String) document.getProperty("noWordSep");
      if (noWordSep == null) noWordSep = "";

      // If the user clicked on a non-letter char,
      // we select the surrounding non-letters
      boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1);

      int wordStart = 0;

      for (int i = offset - 1; i >= 0; i--) {
        ch = lineText.charAt(i);
        if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
          wordStart = i + 1;
          break;
        }
      }

      int wordEnd = lineText.length();
      for (int i = offset; i < lineText.length(); i++) {
        ch = lineText.charAt(i);
        if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
          wordEnd = i;
          break;
        }
      }

      int lineStart = getLineStartOffset(line);
      select(lineStart + wordStart, lineStart + wordEnd);

      /*
      String lineText = getLineText(line);
      String noWordSep = (String)document.getProperty("noWordSep");
      int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep);
      int wordEnd = TextUtilities.findWordEnd(lineText,offset,noWordSep);

      int lineStart = getLineStartOffset(line);
      select(lineStart + wordStart,lineStart + wordEnd);
      */
    }
    public void setPattern(String globPattern) {
      char[] gPat = globPattern.toCharArray();
      char[] rPat = new char[gPat.length * 2];
      boolean isWin32 = (File.separatorChar == '\\');
      boolean inBrackets = false;
      int j = 0;

      this.globPattern = globPattern;

      if (isWin32) {
        // On windows, a pattern ending with *.* is equal to ending with *
        int len = gPat.length;
        if (globPattern.endsWith("*.*")) {
          len -= 2;
        }
        for (int i = 0; i < len; i++) {
          switch (gPat[i]) {
            case '*':
              rPat[j++] = '.';
              rPat[j++] = '*';
              break;

            case '?':
              rPat[j++] = '.';
              break;

            case '\\':
              rPat[j++] = '\\';
              rPat[j++] = '\\';
              break;

            default:
              if ("+()^$.{}[]".indexOf(gPat[i]) >= 0) {
                rPat[j++] = '\\';
              }
              rPat[j++] = gPat[i];
              break;
          }
        }
      } else {
        for (int i = 0; i < gPat.length; i++) {
          switch (gPat[i]) {
            case '*':
              if (!inBrackets) {
                rPat[j++] = '.';
              }
              rPat[j++] = '*';
              break;

            case '?':
              rPat[j++] = inBrackets ? '?' : '.';
              break;

            case '[':
              inBrackets = true;
              rPat[j++] = gPat[i];

              if (i < gPat.length - 1) {
                switch (gPat[i + 1]) {
                  case '!':
                  case '^':
                    rPat[j++] = '^';
                    i++;
                    break;

                  case ']':
                    rPat[j++] = gPat[++i];
                    break;
                }
              }
              break;

            case ']':
              rPat[j++] = gPat[i];
              inBrackets = false;
              break;

            case '\\':
              if (i == 0 && gPat.length > 1 && gPat[1] == '~') {
                rPat[j++] = gPat[++i];
              } else {
                rPat[j++] = '\\';
                if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i + 1]) >= 0) {
                  rPat[j++] = gPat[++i];
                } else {
                  rPat[j++] = '\\';
                }
              }
              break;

            default:
              // if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
              if (!Character.isLetterOrDigit(gPat[i])) {
                rPat[j++] = '\\';
              }
              rPat[j++] = gPat[i];
              break;
          }
        }
      }
      this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE);
    }
 public boolean isWordChar(char c) {
   return Character.isLetterOrDigit(c) || c == '_' || c == '.';
 }