CompositionTextPainter

processing.app.syntax.im

## Class CompositionTextPainter

- Object
- - CompositionTextPainter

-     public class CompositionTextPainter
      extends Object

  Paint texts from input method. Text via input method are transmitted by AttributedCaharacterIterator. This class helps the PDE's TextAreaPainter to handle AttributedCaharacterIterator. For practical purposes, paint to textarea is done by TextLayout class. Because TextLayout class is easy to draw composing texts. (For example, draw underline composing texts, focus when select from candidates text.)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompositionTextPainter(JEditTextArea textArea)` Constructor for painter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `draw(Graphics gfx, Color fillBackGroundColor)` Draw text via input method with composed text information.
    `boolean` | `hasComposedTextLayout()` Check the painter has TextLayout.
    `void` | `invalidateComposedTextLayout(int composedEndCaretPosition)` Invalidate this TextLayout to set null.
    `void` | `setComposedTextLayout(TextLayout composedTextLayout, int composedStartCaretPosition)` Set TextLayout to the painter.

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CompositionTextPainter

          public CompositionTextPainter(JEditTextArea textArea)

      Constructor for painter.
      Parameters:
        `textArea` - textarea used by PDE.

  - ### Method Detail

    - #### hasComposedTextLayout

          public boolean hasComposedTextLayout()

      Check the painter has TextLayout. If a user input via InputMethod, this result will return true.
      Parameters:
        `textarea` - textarea used by PDE.

    - #### setComposedTextLayout

          public void setComposedTextLayout(TextLayout composedTextLayout,
                                   int composedStartCaretPosition)

      Set TextLayout to the painter. TextLayout will be created and set by CompositionTextManager.
      Parameters:
        `textarea` - textarea used by PDE.
      See Also:
        `CompositionTextManager`

    - #### invalidateComposedTextLayout

          public void invalidateComposedTextLayout(int composedEndCaretPosition)

      Invalidate this TextLayout to set null. If a user end input via InputMethod, this method will called from CompositionTextManager.endCompositionText

    - #### draw

          public void draw(Graphics gfx,
                  Color fillBackGroundColor)

      Draw text via input method with composed text information. This method can draw texts with some underlines to illustrate converting characters. This method is workaround for TextAreaPainter. Because, TextAreaPainter can't treat AttributedCharacterIterator directly. AttributedCharacterIterator has very important information when composing text. It has a map where are converted characters and committed characters. Ideally, changing TextAreaPainter method can treat AttributedCharacterIterator is better. But it's very tough!! So I choose to write some code as a workaround. This draw method is proceeded with the following steps. 1. Original TextAreaPainter draws characters. 2. This refillComposedArea method erase previous paint characters by textarea's background color. The refill area is only square that width and height defined by characters with input method. 3. CompositionTextPainter.draw method paints composed text. It was actually drawn by TextLayout.
      Parameters:
        `gfx` - set TextAreaPainter's Graphics object.
        `fillBackGroundColor` - set textarea's background.