com.yospace.yae.yogi
Class YogiTextField

java.lang.Object
  |
  +--com.yospace.yae.yogi.YogiComponent
        |
        +--com.yospace.yae.yogi.YogiTextField
All Implemented Interfaces:
RendererFactory

public class YogiTextField
extends YogiComponent
implements RendererFactory

This is a MIDP compatible TextField. It allows the same method of text entry that MIDP uses to be used inside Yogi. Consequently YogiTextFields work in an identical way to MIDP TextFields.


Field Summary
static int CONSTRAINT_MASK
          Constant that defines the constraint mask for the text field.
static int CONSTRAINTS_ANY
          Constant used to set a text field to allow any kind of input.
static int CONSTRAINTS_EMAILADDR
          Constant used to set a text field to allow input of an email address only.
static int CONSTRAINTS_NUMERIC
          Constant used to set a text field to allow numeric input only.
static int CONSTRAINTS_PHONENUMBER
          Constant used to set a text field to allow input of a phone number only.
static int CONSTRAINTS_URL
          Constant used to set a text field to allow input of a URL only.
static int PASSWORD_MODIFIER
          Constant used to set a text field to use password mode where input is obscured.
static int PROPERTY_CONSTRAINTS
          Constant for the constraints property
static int PROPERTY_LABEL
          Constant for the label property
static int PROPERTY_MAXSIZE
          Constant for the maxsize property
static int PROPERTY_PASSWORD
          Constant for the password property
static int PROPERTY_STRING
          Constant for the string property
 
Fields inherited from class com.yospace.yae.yogi.YogiComponent
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, BORDER_DOTTED, BORDER_NONE, BORDER_PLAIN, BORDER_ROUNDED, BORDER_SOLID, COLOR_BACKGROUND, COLOR_BORDER, COLOR_FOREGROUND, FOCUS_DEFAULT, FOCUS_OFF, FOCUS_ON, PROPERTY_ALIGN, PROPERTY_BORDER_STYLE, PROPERTY_BOUNDS, PROPERTY_COLOR, PROPERTY_CONTEXT_ENABLED, PROPERTY_ENABLED, PROPERTY_FOCUS, PROPERTY_FOCUS_INDEX, PROPERTY_FOCUS_TRAVERSABLE, PROPERTY_FONT, PROPERTY_HOTKEY, PROPERTY_LOCATION, PROPERTY_OPAQUE, PROPERTY_SIZE, PROPERTY_VISIBLE, PROPERTY_X_INSET, PROPERTY_Y_INSET
 
Constructor Summary
YogiTextField()
          Default constructor creates a text field with no label, no initial value, of length 1 and no constraints.
YogiTextField(java.lang.String label, java.lang.String text, int maxSize, int constraints)
          Constructs a new YogiTextField with the given label, initial text, maximum size and contraints.
 
Method Summary
 void delete(int offset, int length)
          Deletes a region of characters from the text field.
 int getCaretPosition()
          Returns the current cursor position.
 YogiComponent getCellRendererComponent(AbstractTable table, java.lang.Object value, boolean isSelected, boolean cellHasFocus)
          Provided to implement the RendererFactory interface.
 int getChars(char[] data)
          Copies the contents of the text field into the character array data starting at position 0.
 int getConstraints()
          Gets the current constraints for the text field.
 java.lang.String getLabel()
          Gets the current label of the text field.
 int getMaxSize()
          Gets the maximum number of characters that the text field is allowed to contain.
 java.lang.String getString()
          Gets the contents of the text field and returns them as a String.
 java.lang.String getText()
          A convenience method that standardizes using getText within YoGI whilst keeping the getString of MIDP.
 javax.microedition.lcdui.TextField getTextField()
          An accessor method that allows access to the MIDP text field itself.
 void insert(char[] data, int offset, int length, int position)
          Inserts a range of characters from data into the text field.
 void insert(java.lang.String src, int position)
          Inserts the String src into the text field beginning at position pos.
 boolean isPassword()
          Gets whether the current string is a password or not.
 void setChars(char[] data, int offset, int length)
          Sets the text of the text field to be a range of characters in a character array.
 void setConstraints(int constraints)
          Sets the constraints for the text field.
 void setLabel(java.lang.String newLabel)
          Sets the label of the text field.
 int setMaxSize(int maxSize)
          Sets the maximum number of characters that the text field can contain.
 void setPassword(boolean password)
          Sets whether the string is a password.
 void setString(java.lang.String newText)
          Sets the current text inside the text field to be text.
 void setText(java.lang.String newText)
          A convenience method that standardizes using setText within YoGI whilst keeping the setString of MIDP.
 int size()
          Gets the current number of characters stored in the text field.
 
Methods inherited from class com.yospace.yae.yogi.YogiComponent
_debugPrintComponents, add, addPropertyChangeListener, bringForwards, bringInFrontOf, bringToFront, contains, containsComponent, ensureVisible, ensureVisible, findComponentAt, findCurrentFocus, findFirstFocus, findFocusDomainRoot, findFocusDomainRootImpl, findHotkeyComponent, findNextFocus, fireActionPerformedEvent, firePropertyChangeEvent, getAlign, getBorderStyle, getBounds, getColor, getColors, getComponent, getComponent, getComponentCount, getComponentIndex, getComponents, getFocusBounds, getFocusIndex, getFont, getGlobalLocation, getHeight, getHotkey, getId, getParent, getParent, getTreeLock, getUI, getWidth, getX, getXInset, getY, getYInset, hasFocus, isActive, isContextEnabled, isEnabled, isFocusDomainRoot, isFocusTraversable, isOpaque, isVisible, keyPressed, keyReleased, keyRepeated, paint, paintBackground, paintBorder, paintForeground, pointerDragged, pointerPressed, pointerReleased, remove, remove, removeAll, removePropertyChangeListener, repaint, repaint, repaintAfterRebounding, requestFocus, requestFocus, sendBackwards, sendBehind, sendToBack, setActionListener, setActive, setAlign, setBorderStyle, setBounds, setColor, setColors, setContextEnabled, setDefaultColor, setEnabled, setFocusDomainRoot, setFocusIndex, setFocusTraversable, setFont, setHotkey, setId, setLocation, setNoFocus, setOpaque, setProperty, setSize, setUI, setVisible, setXInset, setYInset, updateUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_STRING

public static final int PROPERTY_STRING
Constant for the string property

PROPERTY_LABEL

public static final int PROPERTY_LABEL
Constant for the label property

PROPERTY_MAXSIZE

public static final int PROPERTY_MAXSIZE
Constant for the maxsize property

PROPERTY_CONSTRAINTS

public static final int PROPERTY_CONSTRAINTS
Constant for the constraints property

PROPERTY_PASSWORD

public static final int PROPERTY_PASSWORD
Constant for the password property

CONSTRAINTS_ANY

public static int CONSTRAINTS_ANY
Constant used to set a text field to allow any kind of input.

CONSTRAINTS_EMAILADDR

public static int CONSTRAINTS_EMAILADDR
Constant used to set a text field to allow input of an email address only.

CONSTRAINTS_NUMERIC

public static int CONSTRAINTS_NUMERIC
Constant used to set a text field to allow numeric input only.

CONSTRAINTS_PHONENUMBER

public static int CONSTRAINTS_PHONENUMBER
Constant used to set a text field to allow input of a phone number only.

CONSTRAINTS_URL

public static int CONSTRAINTS_URL
Constant used to set a text field to allow input of a URL only.

CONSTRAINT_MASK

public static int CONSTRAINT_MASK
Constant that defines the constraint mask for the text field.

PASSWORD_MODIFIER

public static int PASSWORD_MODIFIER
Constant used to set a text field to use password mode where input is obscured.
Constructor Detail

YogiTextField

public YogiTextField()
Default constructor creates a text field with no label, no initial value, of length 1 and no constraints.

YogiTextField

public YogiTextField(java.lang.String label,
                     java.lang.String text,
                     int maxSize,
                     int constraints)
Constructs a new YogiTextField with the given label, initial text, maximum size and contraints.
Parameters:
label - the label for the text field, may not be displayed depending on the MIDP implmentation.
text - the initial text that the text field will contain.
maxSize - the maximum number of characters that the text field can contain.
constraints - see the MIDP constraints in TextField.
Method Detail

getTextField

public javax.microedition.lcdui.TextField getTextField()
An accessor method that allows access to the MIDP text field itself. This is used in the UI's for YogiTextField.
Returns:
the MIDP text field.

delete

public void delete(int offset,
                   int length)
Deletes a region of characters from the text field.
Parameters:
offset - the position of the start of the region to delete.
length - the length of the region to delete.

getCaretPosition

public int getCaretPosition()
Returns the current cursor position.
Returns:
the current cursor position.

getChars

public int getChars(char[] data)
Copies the contents of the text field into the character array data starting at position 0.
Parameters:
data - the character array into which the text field value will be copied.
Returns:
the number of characters that were copied.

getConstraints

public int getConstraints()
Gets the current constraints for the text field.
Returns:
the current constraints.

getMaxSize

public int getMaxSize()
Gets the maximum number of characters that the text field is allowed to contain.
Returns:
the maximum size of the text field.

getString

public java.lang.String getString()
Gets the contents of the text field and returns them as a String. Note that it is up to the UI delegate to mask the string if it is a password. The application code should always be able to get the (non password masked) string.
Returns:
the contents of the text field.

getText

public java.lang.String getText()
A convenience method that standardizes using getText within YoGI whilst keeping the getString of MIDP.
Returns:
the contents of the text field.
See Also:
getString()

insert

public void insert(char[] data,
                   int offset,
                   int length,
                   int position)
Inserts a range of characters from data into the text field. The range is defined by the offset from the start of the character array and the length from that start position. This range is then inserted into the text field starting at position position.
Parameters:
data - the source character array.
offset - the offset from the start of the array that the range begins.
length - the length of the range to be inserted.
position - the start position in the text array that the range of characters will be inserted into.

insert

public void insert(java.lang.String src,
                   int position)
Inserts the String src into the text field beginning at position pos.
Parameters:
src - the String to be inserted.
position - the starting position that the String will be inserted to.

setChars

public void setChars(char[] data,
                     int offset,
                     int length)
Sets the text of the text field to be a range of characters in a character array. If data is null then the text field will be set to being blank.

The component is repainted and a PROPERTY_STRING change event is fired.

Parameters:
data - the source character array.
offset - the start position of the range inside the character array.
length - the length of the range inside the character array.

setConstraints

public void setConstraints(int constraints)
Sets the constraints for the text field. If the current contents do not match the new constraints then the text field will be blanked.

The component is repainted and a PROPERTY_CONSTRAINTS change event is fired.

Parameters:
constraints - the new constraints for the text field.

setMaxSize

public int setMaxSize(int maxSize)
Sets the maximum number of characters that the text field can contain. If the current contents are longer than the new size then they will be truncated to fit.

If the value changes, the component is repainted and a PROPERTY_MAXSIZE change event is fired.

Parameters:
maxSize - the new maximum size.
Returns:
the actual new size of the text field, which may be less than requested.

setString

public void setString(java.lang.String newText)
Sets the current text inside the text field to be text. If the text is too long to fit into the text field then the maximum size is increased to fit the new value. (this is different from the MIDP specification).

If the value changes, the component is repainted and a PROPERTY_STRING change event is fired.

Parameters:
the - new text value in the text field.

setText

public void setText(java.lang.String newText)
A convenience method that standardizes using setText within YoGI whilst keeping the setString of MIDP.
Parameters:
newText - the new text value in the text field.
See Also:
setString(String)

setLabel

public void setLabel(java.lang.String newLabel)
Sets the label of the text field.

If the value changes, the component is repainted and a PROPERTY_LABEL change event is fired.

Parameters:
newLabel - the new label for the text field.

getLabel

public java.lang.String getLabel()
Gets the current label of the text field.
Returns:
the current label.

setPassword

public void setPassword(boolean password)
Sets whether the string is a password.

If the value changes, the component is repainted and a PROPERTY_PASSWORD change event is fired.

Parameters:
password - a boolean representing whether the string is a password.

isPassword

public boolean isPassword()
Gets whether the current string is a password or not. returns whether the current string is a password or not.

size

public int size()
Gets the current number of characters stored in the text field.
Returns:
the current number of characters stored in the text field.

getCellRendererComponent

public YogiComponent getCellRendererComponent(AbstractTable table,
                                              java.lang.Object value,
                                              boolean isSelected,
                                              boolean cellHasFocus)
Description copied from interface: RendererFactory
Provided to implement the RendererFactory interface. Returns a YogiComponent customised to the arguments passed from the AbstractTable subclass.
Specified by:
getCellRendererComponent in interface RendererFactory
Following copied from interface: com.yospace.yae.yogi.RendererFactory
Parameters:
table - the table for which the check box is rendering.
value - the object to be custom rendered.
isSelected - the selected state of the object to be custom rendered.
cellHasFocus - the focus state of the object to be custom rendered.
Returns:
the custom rendered YogiComponent.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.