Esempio n. 1
0
 /**
  * Called when a user processing input characters and select candidates from input method.
  *
  * @param text Text from InputMethodEvent.
  * @param commited_count Numbers of committed characters in text.
  */
 public void processCompositionText(AttributedCharacterIterator text, int committed_count) {
   int layoutCaretPosition = initialCaretPosition + committed_count;
   CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
   compositionPainter.setComposedTextLayout(
       getTextLayout(text, committed_count), layoutCaretPosition);
   int textLength = text.getEndIndex() - text.getBeginIndex() - committed_count;
   StringBuffer unCommitedStringBuf = new StringBuffer(textLength);
   char c;
   for (c = text.setIndex(committed_count);
       c != AttributedCharacterIterator.DONE && textLength > 0;
       c = text.next(), --textLength) {
     unCommitedStringBuf.append(c);
   }
   String unCommittedString = unCommitedStringBuf.toString();
   try {
     if (canRemovePreviousInput(committed_count)) {
       textArea.getDocument().remove(layoutCaretPosition, prevComposeString.length());
     }
     textArea.getDocument().insertString(layoutCaretPosition, unCommittedString, null);
     if (committed_count > 0) {
       initialCaretPosition = initialCaretPosition + committed_count;
     }
     prevComposeString = unCommittedString;
     prevCommittedCount = committed_count;
   } catch (BadLocationException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  protected void paintSyntaxLine(
      Graphics gfx,
      TokenMarker tokenMarker,
      int line,
      Font defaultFont,
      Color defaultColor,
      int x,
      int y) {
    textArea.getLineText(currentLineIndex, currentLine);
    currentLineTokens = tokenMarker.markTokens(currentLine, currentLineIndex);

    paintHighlight(gfx, line, y);

    gfx.setFont(defaultFont);
    gfx.setColor(defaultColor);
    y += fm.getHeight();
    x = SyntaxUtilities.paintSyntaxLine(currentLine, currentLineTokens, styles, this, gfx, x, y);
    /*
     * Draw characters via input method.
     */
    if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) {
      compositionTextPainter.draw(gfx, lineHighlightColor);
    }
    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }
Esempio n. 3
0
 /**
  * Called when a user fixed text from input method or delete all composition text. This method
  * resets CompositionTextPainter.
  *
  * @param text Text from InputMethodEvent.
  * @param commited_count Numbers of committed characters in text.
  */
 public void endCompositionText(AttributedCharacterIterator text, int committed_count) {
   /*
    * If there are no committed characters, remove it all from textarea.
    * This case will happen if a user delete all composing characters by backspace or delete key.
    * If it does, these previous characters are needed to be deleted.
    */
   if (committed_count == 0) {
     removeNotCommittedText(text);
   }
   CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
   compositionPainter.invalidateComposedTextLayout(initialCaretPosition + committed_count);
   prevComposeString = "";
   isInputProcess = false;
 }
Esempio n. 4
0
  protected void paintPlainLine(
      Graphics gfx, int line, Font defaultFont, Color defaultColor, int x, int y) {
    paintHighlight(gfx, line, y);
    textArea.getLineText(line, currentLine);

    gfx.setFont(defaultFont);
    gfx.setColor(defaultColor);

    y += fm.getHeight();
    x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0);
    // Draw characters via input method.
    if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) {
      compositionTextPainter.draw(gfx, lineHighlightColor);
    }
    if (eolMarkers) {
      gfx.setColor(eolMarkerColor);
      gfx.drawString(".", x, y);
    }
  }