com.threerings.opengl.gui
Class EditableTextComponent

java.lang.Object
  extended by com.threerings.opengl.gui.Component
      extended by com.threerings.opengl.gui.TextComponent
          extended by com.threerings.opengl.gui.EditableTextComponent
All Implemented Interfaces:
ConfigUpdateListener<ManagedConfig>, Document.Listener, EditCommands
Direct Known Subclasses:
TextEditor, TextField

public abstract class EditableTextComponent
extends TextComponent
implements EditCommands, Document.Listener

Extends TextComponent with mechanisms shared by editable text Components.


Nested Class Summary
protected static class EditableTextComponent.CompoundType
          Edits that can be compounded together.
 
Field Summary
protected  int _cursp
           
protected  KeyMap _keymap
           
protected  EditableTextComponent.CompoundType _lastCompoundType
           
protected  int _lastUndoId
           
protected  String _placeholder
          Placeholder text, shown when our regular document is empty.
protected  int _prefWidth
           
protected  Background[] _selectionBackgrounds
           
protected  int _selp
           
protected  boolean _showCursor
           
protected  Rectangle _srect
           
protected  Document _text
           
protected  UndoManager _undomgr
           
 
Fields inherited from class com.threerings.opengl.gui.TextComponent
_effcols, _effsizes, _haligns, _lineSpacings, _teffects, _textfacts, _valigns
 
Fields inherited from class com.threerings.opengl.gui.Component
_alpha, _backgrounds, _borders, _colors, _ctx, _cursor, _enabled, _height, _hover, _hoverable, _insets, _listeners, _parent, _preferredSize, _properties, _rect, _styleConfigs, _tipmouse, _tiptext, _tooltipStyle, _transferHandler, _valid, _visible, _width, _x, _y, DEFAULT, DISABLED, HOVER, STATE_COUNT, STATE_PCLASSES
 
Fields inherited from interface com.threerings.opengl.gui.text.EditCommands
ACTION, BACKSPACE, CLEAR, COPY, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, CURSOR_UP, CUT, DELETE, END_OF_LINE, PASTE, REDO, RELEASE_FOCUS, START_OF_LINE, UNDO, WORD_LEFT, WORD_RIGHT
 
Constructor Summary
protected EditableTextComponent(GlContext ctx)
          For subclasses.
protected EditableTextComponent(GlContext ctx, String text, int maxLength)
          For subclasses.
 
Method Summary
 boolean acceptsFocus()
          Returns whether or not this component accepts the keyboard focus.
protected abstract  void clearGlyphs()
          Clears out our text textures and other related bits.
protected abstract  void createGlyphs()
          Create the entity that we use to render our text.
protected  String deleteSelectedText()
          Deletes the currently selected text.
 boolean dispatchEvent(Event event)
          Instructs this component to process the supplied event.
protected  void gainedFocus()
          Called when this text field has gained the focus.
protected  String getDisplayText()
          This method allows a derived class (specifically PasswordField) to display something other than the actual contents of the text field.
 Document getDocument()
          Returns the underlying document used by this text field to maintain its state.
protected abstract  int getPosition(int mouseX, int mouseY)
          Get the position in our document, given the mouse local mouse coordinates that have already had the insets taken into account.
protected  String getSelectedText()
          Returns the currently selected text.
 Background getSelectionBackground()
          Returns the selection background configured for this component.
 String getText()
          Returns the text currently being displayed by this component.
protected abstract  boolean hasGlyphs()
          Do we have glyphs computed?
protected  char insertChar(char c)
          Given the provided character, return the character to insert, or 0 to nix the insertion.
protected  void layout()
          Instructs this component to lay itself out.
protected  void lostFocus()
          Called when this text field has lost the focus.
protected  int nextUndoId(EditableTextComponent.CompoundType compoundType)
          Returns an undo operation id.
protected  boolean processCommand(int cmd)
          Process the specified edit command, returning true if it was handled.
protected  void recreateGlyphs()
          Recreates the entity that we use to render our text.
protected  void renderCursor(Renderer renderer, int x, int y, int height)
          Helper method to render the cursor.
protected  void replaceSelectedText(String text, EditableTextComponent.CompoundType compoundType)
          Replaces the currently selected text with the supplied text.
protected  boolean selectionContains(int pos)
          Determines whether the selection contains the specified position.
protected  boolean selectionIsEmpty()
          Checks whether the selection is empty.
protected abstract  void selectionWasSet()
          Update any internal positions after the selection is set.
protected  void setCursorPos(int cursorPos)
          Updates the cursor position, moving the visible representation as well as the insertion and deletion point.
 void setDocument(Document document)
          Configures this text field with a custom document.
 void setMaxLength(int maxLength)
          Configures the maximum length of this text field.
 void setPlaceholder(String placeholder)
          Set the placeholder text; shown when the field is unfocused and empty.
 void setPreferredWidth(int width)
          Configures the preferred width of this text field (the preferred height will be calculated from the font).
protected  void setSelection(int cursorPos, int selectPos)
          Updates the selection.
 void setText(String text)
          Configures this text field with the specified text for display and editing.
protected  boolean showCursor()
          Should we show the cursor?
protected  void stateDidChange()
          Called when the component's state has changed.
 void textInserted(Document document, int offset, int length)
          Called when text is inserted into a document.
 void textRemoved(Document document, int offset, int length)
          Called when text is removed from a document.
protected  void updateFromStyleConfig(int state, StyleConfig.Original config)
          Updates from the resolved style config.
protected  boolean usePlaceholder()
          Would we want to use our placeholder text if we did not have focus?
protected  String validatePaste(String pasted)
          Validate the pasted text.
protected  void wasAdded()
          This method is called when we are added to a hierarchy that is connected to a top-level window (at which point we can rely on having a look and feel and can set ourselves up).
protected  void wasRemoved()
          This method is called when we are removed from a hierarchy that is connected to a top-level window.
 
Methods inherited from class com.threerings.opengl.gui.TextComponent
getEffectColor, getEffectSize, getHorizontalAlignment, getLabelRendererConfig, getLineSpacing, getTextEffect, getTextFactory, getTextFactory, getVerticalAlignment
 
Methods inherited from class com.threerings.opengl.gui.Component
addListener, boundsToString, changeCursor, computePreferredSize, configUpdated, contains, createDefaultTooltipComponent, createDefaultTooltipComponent, createTooltipComponent, emitEvent, getAbsoluteX, getAbsoluteY, getAlpha, getBackground, getBorder, getBounds, getColor, getContext, getCursor, getDefaultStyleConfig, getFallbackState, getFirstDescendantFocus, getFocusTarget, getHeight, getHitComponent, getInsets, getLastDescendantFocus, getNextFocus, getParent, getPreferredSize, getPreviousFocus, getProperty, getState, getStateCount, getStatePseudoClass, getStyleConfigs, getTooltipText, getTooltipTimeout, getTooltipWindowStyle, getTransferHandler, getWidth, getWindow, getX, getY, hasFocus, intersectScissor, invalidate, isAdded, isEnabled, isHoverable, isShowing, isTooltipRelativeToMouse, isValid, isVisible, removeAllListeners, removeAllListeners, removeListener, render, renderBackground, renderBorder, renderComponent, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlpha, setBackground, setBounds, setCursor, setEnabled, setHoverable, setLocation, setParent, setPreferredSize, setPreferredSize, setProperty, setSize, setStyleConfig, setStyleConfig, setStyleConfig, setStyleConfigs, setTooltipRelativeToMouse, setTooltipText, setTransferHandler, setVisible, updateCursor, updateFromStyleConfig, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_text

protected Document _text

_keymap

protected KeyMap _keymap

_placeholder

protected String _placeholder
Placeholder text, shown when our regular document is empty.


_prefWidth

protected int _prefWidth

_showCursor

protected boolean _showCursor

_cursp

protected int _cursp

_selp

protected int _selp

_selectionBackgrounds

protected Background[] _selectionBackgrounds

_srect

protected Rectangle _srect

_undomgr

protected UndoManager _undomgr

_lastUndoId

protected int _lastUndoId

_lastCompoundType

protected EditableTextComponent.CompoundType _lastCompoundType
Constructor Detail

EditableTextComponent

protected EditableTextComponent(GlContext ctx)
For subclasses.


EditableTextComponent

protected EditableTextComponent(GlContext ctx,
                                String text,
                                int maxLength)
For subclasses.

Method Detail

setPlaceholder

public void setPlaceholder(String placeholder)
Set the placeholder text; shown when the field is unfocused and empty.


setText

public void setText(String text)
Configures this text field with the specified text for display and editing. The cursor will be adjusted if this text is shorter than its previous position.

Specified by:
setText in class TextComponent

getText

public String getText()
Description copied from class: TextComponent
Returns the text currently being displayed by this component.

Specified by:
getText in class TextComponent

setMaxLength

public void setMaxLength(int maxLength)
Configures the maximum length of this text field. This will replace any currently set document with a LengthLimitedDocument (or no document at all if maxLength is <= 0).


setDocument

public void setDocument(Document document)
Configures this text field with a custom document.


getDocument

public Document getDocument()
Returns the underlying document used by this text field to maintain its state. Changes to the document will be reflected in the text field display.


setPreferredWidth

public void setPreferredWidth(int width)
Configures the preferred width of this text field (the preferred height will be calculated from the font).


getSelectionBackground

public Background getSelectionBackground()
Returns the selection background configured for this component.


textInserted

public void textInserted(Document document,
                         int offset,
                         int length)
Description copied from interface: Document.Listener
Called when text is inserted into a document. The text will have already been inserted into the document.

Specified by:
textInserted in interface Document.Listener
Parameters:
document - the document into which text was inserted.
offset - the offset into the document of the inserted text.
length - the length of the inserted text.

textRemoved

public void textRemoved(Document document,
                        int offset,
                        int length)
Description copied from interface: Document.Listener
Called when text is removed from a document. The text will have already been removed from the document.

Specified by:
textRemoved in interface Document.Listener
Parameters:
document - the document from which text was removed.
offset - the offset into the document of the removed text.
length - the length of the removed text.

acceptsFocus

public boolean acceptsFocus()
Description copied from class: Component
Returns whether or not this component accepts the keyboard focus.

Overrides:
acceptsFocus in class Component

dispatchEvent

public boolean dispatchEvent(Event event)
Description copied from class: Component
Instructs this component to process the supplied event. If the event is not processed, it will be passed up to its parent component for processing. Derived classes should thus only call super.dispatchEvent for events that they did not "consume".

Overrides:
dispatchEvent in class Component
Returns:
true if this event was consumed, false if not.

insertChar

protected char insertChar(char c)
Given the provided character, return the character to insert, or 0 to nix the insertion.


processCommand

protected boolean processCommand(int cmd)
Process the specified edit command, returning true if it was handled.


validatePaste

protected String validatePaste(String pasted)
Validate the pasted text. Return null to reject the paste event altogether, or the pasted text may be modified...


updateFromStyleConfig

protected void updateFromStyleConfig(int state,
                                     StyleConfig.Original config)
Description copied from class: Component
Updates from the resolved style config.

Overrides:
updateFromStyleConfig in class TextComponent

wasAdded

protected void wasAdded()
Description copied from class: Component
This method is called when we are added to a hierarchy that is connected to a top-level window (at which point we can rely on having a look and feel and can set ourselves up).

Overrides:
wasAdded in class Component

wasRemoved

protected void wasRemoved()
Description copied from class: Component
This method is called when we are removed from a hierarchy that is connected to a top-level window. If we wish to clean up after things done in Component.wasAdded(), this is a fine place to do so.

Overrides:
wasRemoved in class Component

layout

protected void layout()
Description copied from class: Component
Instructs this component to lay itself out. This is called as a result of the component changing size.

Overrides:
layout in class Component

stateDidChange

protected void stateDidChange()
Description copied from class: Component
Called when the component's state has changed.

Overrides:
stateDidChange in class Component

gainedFocus

protected void gainedFocus()
Called when this text field has gained the focus.


lostFocus

protected void lostFocus()
Called when this text field has lost the focus.


showCursor

protected boolean showCursor()
Should we show the cursor?


usePlaceholder

protected boolean usePlaceholder()
Would we want to use our placeholder text if we did not have focus?


getDisplayText

protected String getDisplayText()
This method allows a derived class (specifically PasswordField) to display something other than the actual contents of the text field.


renderCursor

protected void renderCursor(Renderer renderer,
                            int x,
                            int y,
                            int height)
Helper method to render the cursor.


selectionIsEmpty

protected boolean selectionIsEmpty()
Checks whether the selection is empty.


selectionContains

protected boolean selectionContains(int pos)
Determines whether the selection contains the specified position.


getSelectedText

protected String getSelectedText()
Returns the currently selected text.


deleteSelectedText

protected String deleteSelectedText()
Deletes the currently selected text.

Returns:
the previously selected text (an empty string if nothing was selected).

replaceSelectedText

protected void replaceSelectedText(String text,
                                   EditableTextComponent.CompoundType compoundType)
Replaces the currently selected text with the supplied text.


setCursorPos

protected void setCursorPos(int cursorPos)
Updates the cursor position, moving the visible representation as well as the insertion and deletion point.


setSelection

protected void setSelection(int cursorPos,
                            int selectPos)
Updates the selection.


recreateGlyphs

protected void recreateGlyphs()
Recreates the entity that we use to render our text.


hasGlyphs

protected abstract boolean hasGlyphs()
Do we have glyphs computed?


clearGlyphs

protected abstract void clearGlyphs()
Clears out our text textures and other related bits.


createGlyphs

protected abstract void createGlyphs()
Create the entity that we use to render our text.


getPosition

protected abstract int getPosition(int mouseX,
                                   int mouseY)
Get the position in our document, given the mouse local mouse coordinates that have already had the insets taken into account.


selectionWasSet

protected abstract void selectionWasSet()
Update any internal positions after the selection is set.


nextUndoId

protected int nextUndoId(EditableTextComponent.CompoundType compoundType)
Returns an undo operation id.

Parameters:
compoundType - identifies the edit type for purposes of compounding events together.