com.jmex.bui
Class BTextField

java.lang.Object
  extended by com.jmex.bui.BComponent
      extended by com.jmex.bui.BTextComponent
          extended by com.jmex.bui.BTextField
All Implemented Interfaces:
Document.Listener, EditCommands
Direct Known Subclasses:
BPasswordField

public class BTextField
extends BTextComponent
implements EditCommands, Document.Listener

Displays and allows for the editing of a single line of text.


Field Summary
protected  int _cursp
           
protected  int _cursx
           
protected  BText _glyphs
           
protected  BKeyMap _keymap
           
protected  int _prefWidth
           
protected  boolean _showCursor
           
protected  Rectangle _srect
           
protected  Document _text
           
protected  int _txoff
           
 
Fields inherited from class com.jmex.bui.BTextComponent
_effcols, _effsizes, _haligns, _lineSpacings, _teffects, _textfacts, _valigns
 
Fields inherited from class com.jmex.bui.BComponent
_alpha, _backgrounds, _bbuf, _borders, _colors, _cursor, _enabled, _height, _hover, _insets, _listeners, _parent, _preferredSize, _properties, _styleClass, _tipmouse, _tipStyle, _tiptext, _valid, _visible, _width, _x, _y, DEFAULT, DISABLED, HOVER, STATE_COUNT, STATE_PCLASSES
 
Fields inherited from interface com.jmex.bui.text.EditCommands
ACTION, BACKSPACE, CLEAR, CURSOR_LEFT, CURSOR_RIGHT, DELETE, END_OF_LINE, RELEASE_FOCUS, START_OF_LINE
 
Constructor Summary
BTextField()
          Creates a blank text field.
BTextField(int maxLength)
          Creates a blank text field with maximum input length.
BTextField(String text)
          Creates a text field with the specified starting text.
BTextField(String text, int maxLength)
          Creates a text field with the specified starting text and max length.
 
Method Summary
 boolean acceptsFocus()
          Returns whether or not this component accepts the keyboard focus.
protected  void clearGlyphs()
          Clears out our text textures and other related bits.
protected  Dimension computePreferredSize(int whint, int hhint)
          Computes and returns a preferred size for this component.
protected  void configureStyle(BStyleSheet style)
          Instructs this component to fetch its style configuration from the supplied style sheet.
 boolean dispatchEvent(BEvent event)
          Instructs this component to process the supplied event.
protected  void gainedFocus()
          Called when this text field has gained the focus.
protected  String getDefaultStyleClass()
          Returns the default stylesheet class to be used for all instances of this component.
protected  String getDisplayText()
          This method allows a derived class (specifically BPasswordField) 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.
 String getText()
          Returns the text currently being displayed by this component.
protected  void layout()
          Instructs this component to lay itself out.
protected  void lostFocus()
          Called when this text field has lost the focus.
protected  void recreateGlyphs()
          Recreates the entity that we use to render our text.
protected  void renderComponent(Renderer renderer)
          Renders any custom bits for this component.
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 setPreferredWidth(int width)
          Configures the preferred width of this text field (the preferred height will be calculated from the font).
 void setText(String text)
          Configures this text field with the specified text for display and editing.
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 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.jmex.bui.BTextComponent
checkNonDefault, checkNonDefaultInt, checkNonDefaultVal, getEffectColor, getEffectSize, getHorizontalAlignment, getLabelConfig, getLineSpacing, getTextEffect, getTextFactory, getTextFactory, getVerticalAlignment
 
Methods inherited from class com.jmex.bui.BComponent
addListener, applyDefaultStates, boundsToString, changeCursor, createTooltipComponent, emitEvent, getAbsoluteX, getAbsoluteY, getAlpha, getBackground, getBorder, getBounds, getColor, getCursor, getFocusTarget, getHeight, getHitComponent, getInsets, getNextFocus, getParent, getPreferredSize, getPreviousFocus, getProperty, getState, getStateCount, getStatePseudoClass, getStyleClass, getTooltipText, getWidth, getWindow, getX, getY, hasFocus, intersectScissorBox, invalidate, isAdded, isEnabled, isShowing, isTooltipRelativeToMouse, isValid, isVisible, removeAllListeners, removeListener, render, renderBackground, renderBorder, requestFocus, restoreScissorState, setAlpha, setBackground, setBounds, setCursor, setEnabled, setLocation, setParent, setPreferredSize, setPreferredSize, setProperty, setSize, setStyleClass, setTooltipRelativeToMouse, setTooltipText, setVisible, updateCursor, 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

_glyphs

protected BText _glyphs

_keymap

protected BKeyMap _keymap

_prefWidth

protected int _prefWidth

_showCursor

protected boolean _showCursor

_cursp

protected int _cursp

_cursx

protected int _cursx

_txoff

protected int _txoff

_srect

protected Rectangle _srect
Constructor Detail

BTextField

public BTextField()
Creates a blank text field.


BTextField

public BTextField(int maxLength)
Creates a blank text field with maximum input length. The maximum input length is controlled by a LengthLimitedDocument, changing the document will remove the length control.


BTextField

public BTextField(String text)
Creates a text field with the specified starting text.


BTextField

public BTextField(String text,
                  int maxLength)
Creates a text field with the specified starting text and max length. The maximum input length is controlled by a LengthLimitedDocument, changing the document will remove the length control.

Method Detail

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 BTextComponent

getText

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

Specified by:
getText in class BTextComponent

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).


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: BComponent
Returns whether or not this component accepts the keyboard focus.

Overrides:
acceptsFocus in class BComponent

dispatchEvent

public boolean dispatchEvent(BEvent event)
Description copied from class: BComponent
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 BComponent
Returns:
true if this event was consumed, false if not.

getDefaultStyleClass

protected String getDefaultStyleClass()
Description copied from class: BComponent
Returns the default stylesheet class to be used for all instances of this component. Derived classes will likely want to override this method and set up a default class for their type of component.

Overrides:
getDefaultStyleClass in class BComponent

configureStyle

protected void configureStyle(BStyleSheet style)
Description copied from class: BComponent
Instructs this component to fetch its style configuration from the supplied style sheet. This method is called when a component is added to the interface hierarchy.

Overrides:
configureStyle in class BTextComponent

wasAdded

protected void wasAdded()
Description copied from class: BComponent
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 BComponent

wasRemoved

protected void wasRemoved()
Description copied from class: BComponent
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 BComponent.wasAdded(), this is a fine place to do so.

Overrides:
wasRemoved in class BComponent

layout

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

Overrides:
layout in class BComponent

stateDidChange

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

Overrides:
stateDidChange in class BComponent

renderComponent

protected void renderComponent(Renderer renderer)
Description copied from class: BComponent
Renders any custom bits for this component. This is called with the graphics context translated to (0, 0) relative to this component.

Overrides:
renderComponent in class BComponent

computePreferredSize

protected Dimension computePreferredSize(int whint,
                                         int hhint)
Description copied from class: BComponent
Computes and returns a preferred size for this component. This method is called if no overriding preferred size has been supplied.

Overrides:
computePreferredSize in class BComponent
Returns:
the computed preferred size of this component in a newly created Dimension instance which will be adopted (and modified) by the caller.

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.


recreateGlyphs

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


clearGlyphs

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


getDisplayText

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


setCursorPos

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



Copyright © 2008 Michael Bayne. All Rights Reserved.