<

Class ActiveClient

java.lang.Object
  |
  +--java.awt.Component
        |
        +--LWTextComponent
              |
              +--ActiveClient

public class ActiveClient
extends LWTextComponent
implements InputMethodListener, InputMethodRequests

Implements an integrated text input user interface. This class is an active client of the input method framework, that is, actively uses its APIs to accomplish integration.

This class directly implements the two client interfaces of the input method framework, InputMethodListener and InputMethodRequests. This is not required. Especially in cases where the public interface matters (such as in a class library), it may be more appropriate to hide the implementations of these two interfaces in separate classes.

See Also:
Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
ActiveClient(String name)
          Constructs an ActiveClient.
 
Method Summary
 AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes)
          Returns null to indicate that the "Undo Commit" feature is not supported by this simple text component.
 void caretPositionChanged(InputMethodEvent event)
          Handles changes to the caret within composed text.
 TextHitInfo getCaret()
          Returns a text hit info indicating the current caret (insertion point).
 AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex, AttributedCharacterIterator.Attribute[] attributes)
          Gets an iterator providing access to the entire text and attributes contained in the text editing component except for uncommitted text.
 AttributedCharacterIterator getDisplayText()
          Returns the text that the user has entered.
 InputMethodRequests getInputMethodRequests()
          Implements getInputMethodRequests for ActiveClient by returning "this".
 int getInsertPositionOffset()
          Gets the offset of the insert position in the committed text contained in the text editing component.
 TextHitInfo getLocationOffset(int x, int y)
          Gets the offset within the composed text for the specified absolute x and y coordinates on the screen.
 AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] attributes)
          Gets the currently selected text from the text editing component.
 Rectangle getTextLocation(TextHitInfo offset)
          Gets the location of a specified offset in the current composed text, or of the selection in committed text.
 void inputMethodTextChanged(InputMethodEvent event)
          Handles changes to the text entered through an input method.
 void setFontSize(int size)
          Adjusts composed text for new font size.
 
Methods inherited from class LWTextComponent
focusGained, focusLost, getCaretRectangle, getCaretRectangle, getCommittedText, getCommittedText, getCommittedTextLength, getTextLayout, getTextOrigin, insertCharacter, invalidateTextLayout, keyPressed, keyReleased, keyTyped, paint
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActiveClient

public ActiveClient(String name)
Constructs an ActiveClient. Input methods are always enabled for ActiveClient instances.
Parameters:
name - the component name to be displayed above the text
Method Detail

getInputMethodRequests

public InputMethodRequests getInputMethodRequests()
Implements getInputMethodRequests for ActiveClient by returning "this".
Returns:
"this"
Overrides:
getInputMethodRequests in class Component

setFontSize

public void setFontSize(int size)
Adjusts composed text for new font size.
Overrides:
setFontSize in class LWTextComponent

getDisplayText

public AttributedCharacterIterator getDisplayText()
Returns the text that the user has entered. This override returns the concatenation of committed text and composed text.
Overrides:
getDisplayText in class LWTextComponent

getCaret

public TextHitInfo getCaret()
Returns a text hit info indicating the current caret (insertion point). This override returns the caret provided by the input method while there is composed text; otherwise it returns a caret at the end of the committed text. The caret provided by the input method may be null.
Overrides:
getCaret in class LWTextComponent

inputMethodTextChanged

public void inputMethodTextChanged(InputMethodEvent event)
Handles changes to the text entered through an input method. Committed text contained in the event is appended to the committed text of the text component. Composed text contained in the event replaces any existing composed text in the text component. The caret defined in the event is saved and will be returned by getCaret if there is composed text. The component is redrawn.

In this simple component, we only keep input method highlight attributes. Smarter components may want to keep language, reading, input method segment, and other attributes as well.

Specified by:
inputMethodTextChanged in interface InputMethodListener

caretPositionChanged

public void caretPositionChanged(InputMethodEvent event)
Handles changes to the caret within composed text. The caret defined in the event is saved and will be returned by getCaret if there is composed text. The component is redrawn.
Specified by:
caretPositionChanged in interface InputMethodListener

getTextLocation

public Rectangle getTextLocation(TextHitInfo offset)
Gets the location of a specified offset in the current composed text, or of the selection in committed text.
Specified by:
getTextLocation in interface InputMethodRequests

getLocationOffset

public TextHitInfo getLocationOffset(int x,
                                     int y)
Gets the offset within the composed text for the specified absolute x and y coordinates on the screen.
Specified by:
getLocationOffset in interface InputMethodRequests

getInsertPositionOffset

public int getInsertPositionOffset()
Gets the offset of the insert position in the committed text contained in the text editing component. In this simple component, that's always at the end of the committed text.
Specified by:
getInsertPositionOffset in interface InputMethodRequests

getCommittedText

public AttributedCharacterIterator getCommittedText(int beginIndex,
                                                    int endIndex,
                                                    AttributedCharacterIterator.Attribute[] attributes)
Gets an iterator providing access to the entire text and attributes contained in the text editing component except for uncommitted text.
Specified by:
getCommittedText in interface InputMethodRequests

cancelLatestCommittedText

public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes)
Returns null to indicate that the "Undo Commit" feature is not supported by this simple text component.
Specified by:
cancelLatestCommittedText in interface InputMethodRequests

getSelectedText

public AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] attributes)
Gets the currently selected text from the text editing component. Since this simple text component doesn't support selections, this is always an iterator over empty text.
Specified by:
getSelectedText in interface InputMethodRequests


Oracle and/or its affiliates
Java Technology

Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.

Contact Us