fds.micro.ui
Class TextField

java.lang.Object
  extended byfds.micro.ui.Component
      extended byfds.micro.ui.TextField
Direct Known Subclasses:
DigitTextField

public class TextField
extends Component

This class implements a very basic text field.
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).

Warning: DO NOT USE the class if you want a full featured text field. Due to some JVM implementations this class often support only capital letters and digits. It depends on the Canvas.keyPressed(int keyCode) method implementation. Check that before using ;-)

A text field have a label and an entry zone.
Within the entry zone you can enter characters at the position of a displayed cursor.
You can move the cursor with left and right arrows, or with a pointing device if it exist.
To delete the character just before the cursor (equivalent to a "backspace" action), you must use the button mapped on your device with the FIRE game action.
No selection is supported.

You can read below a typical use within a class that inherit fds.micro.ui.RowPanel:

Construction

 ...
 this.field = new TextField(20, "My field label", "Default value"); // Maximum 20 characters long
 this.field.setBackground(192, 192, 192); // Light grey background
 this.field.setCursorColor(255, 0, 0); // Red cursor
 this.field.setTextColor(0, 0, 255); // Blue text in field entry zone
 this.append(this.field);
 ...
 
Event handling
 // By default, events are handled. If you want to change some behaviour you can overwrite the following methods: 
 public void keyPressed(int keyCode) {
     if(keyCode == mySpecialCode) {
         ...
     }
     else {
         super.keyPressed(keyCode);
     }
 }
 public void pointerPressed(int x, int y) {
     if((x > myXmin) && (x < myXmax) && (y > myYmin) && (y < myYmax)) {
         ...
     }
     else {
         super.pointerPressed(x, y);
     }
 }
 
Usage
 ...
 // Here we get the field content
 String content = this.field.getText();
 ...
 

Author:
Frédéric DE STEUR

Field Summary
static int LABEL_LEFT
          Specify that the label must be on the left of the field
static int LABEL_TOP
          Specify that the label must be on the top of the field
 
Fields inherited from class fds.micro.ui.Component
INTERN_BOTTOM_VALIGN, INTERN_CENTER_HALIGN, INTERN_CENTER_VALIGN, INTERN_LEFT_HALIGN, INTERN_RIGHT_HALIGN, INTERN_TOP_VALIGN
 
Constructor Summary
TextField()
          Build an empty text field without label.
TextField(int maxLength)
          Build an empty text field without label.
TextField(int maxLength, java.lang.String label)
          Build an empty text field with specified label.
TextField(int maxLength, java.lang.String label, java.lang.String text)
          Build a text field with specified label and initialized with given value.
TextField(java.lang.String label)
          Build an empty text field with specified label.
TextField(java.lang.String label, java.lang.String text)
          Build a text field with specified label and initialized with given value.
 
Method Summary
 void addValueChangeListener(ValueChangeListener listener)
          Add a listener object that will receive events produced by this component when the value is changed.
 int getCursorPosition()
          Get the position of the cursor in field.
 java.lang.String getLabel()
          Get the field label.
 javax.microedition.lcdui.Font getLabelFont()
          Get the font used to display the field label.
 int getLabelPosition()
          Get the position of the field label.
 int getLength()
          Get the number of entered characters.
 java.lang.String getText()
          Get the field value.
 javax.microedition.lcdui.Font getTextFont()
          Get the font used to display the field value.
 boolean isBoxOpaque()
          Get the entry zone opacity flag.
 void keyPressed(int keyCode, int gameAction)
          Called to notify the component that a key is pressed.
 void pointerPressed(int xpos, int ypos)
          Called to notify the component that pointer device was pressed.
 void removeValueChangListener(ValueChangeListener listener)
          Remove a listener.
 void setBorderColor(int red, int green, int blue)
          Set the color for field border.
 void setBoxOpaque(boolean boxOpaque)
          Set a new value for entry zone opacity flag.
 void setCursorColor(int red, int green, int blue)
          Set the color for field cursor.
 void setCursorPosition(int cursorPosition)
          Change the position of the cursor in field.
 void setFieldBackground(int red, int green, int blue)
          Set the color for field background.
 void setFieldBackgroundOff(int red, int green, int blue)
          Set the color for field background if component is disabled.
 void setLabel(java.lang.String label)
          Set the field label.
 void setLabelColor(int red, int green, int blue)
          Set the label color.
 void setLabelFont(javax.microedition.lcdui.Font labelFont)
          Change the font used to display the field label.
 void setLabelPosition(int labelPosition)
          Change the position of the field label.
 void setMaximumSize(int width, int height)
          Set the maximum size for this component.
 void setText(java.lang.String text)
          Set the field value.
 void setTextColor(int red, int green, int blue)
          Set the field value color.
 void setTextColorOff(int red, int green, int blue)
          Set the field value color if component is disabled.
 void setTextFont(javax.microedition.lcdui.Font textFont)
          Change the font used to display the field value.
 
Methods inherited from class fds.micro.ui.Component
addFocusListener, addItemListener, equals, getHAlign, getHeight, getParent, getVAlign, getWidth, getX, getY, isDisabled, isHaveFocus, isHidden, isManageFocus, isOpaque, removeFocusListener, removeItemListener, setBackground, setDisabled, setFocusColor, setHAlign, setHidden, setLocation, setManageFocus, setOpaque, setVAlign
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_LEFT

public static final int LABEL_LEFT
Specify that the label must be on the left of the field

See Also:
Constant Field Values

LABEL_TOP

public static final int LABEL_TOP
Specify that the label must be on the top of the field

See Also:
Constant Field Values
Constructor Detail

TextField

public TextField()
Build an empty text field without label.


TextField

public TextField(int maxLength)
Build an empty text field without label.

Parameters:
maxLength - The maximum length for this field.

TextField

public TextField(int maxLength,
                 java.lang.String label)
Build an empty text field with specified label.

Parameters:
maxLength - The maximum length for this field.
label - Label to display before the field (null if no label).

TextField

public TextField(int maxLength,
                 java.lang.String label,
                 java.lang.String text)
Build a text field with specified label and initialized with given value.

Parameters:
maxLength - The maximum length for this field.
label - Label to display before the field (null if no label).
text - Initial field value.

TextField

public TextField(java.lang.String label)
Build an empty text field with specified label.

Parameters:
label - Label to display before the field (null if no label).

TextField

public TextField(java.lang.String label,
                 java.lang.String text)
Build a text field with specified label and initialized with given value.

Parameters:
label - Label to display before the field (null if no label).
text - Initial field value.
Method Detail

addValueChangeListener

public void addValueChangeListener(ValueChangeListener listener)
Add a listener object that will receive events produced by this component when the value is changed.

Parameters:
listener - The listener to add.

getCursorPosition

public int getCursorPosition()
Get the position of the cursor in field.

Returns:
Returns the cursor position. Returns zero if the cursor is on the left.

getLabel

public java.lang.String getLabel()
Get the field label.

Returns:
Returns the label.

getLabelFont

public javax.microedition.lcdui.Font getLabelFont()
Get the font used to display the field label.

Returns:
Returns the font for label.

getLabelPosition

public int getLabelPosition()
Get the position of the field label.

Returns:
Returns the label position (LABEL_LEFT or LABEL_TOP).

getLength

public int getLength()
Get the number of entered characters.

Returns:
The length of the field value.

getText

public java.lang.String getText()
Get the field value.

Returns:
Returns the current field value.

getTextFont

public javax.microedition.lcdui.Font getTextFont()
Get the font used to display the field value.

Returns:
Returns the font for field value.

isBoxOpaque

public boolean isBoxOpaque()
Get the entry zone opacity flag.

Returns:
Returns true if background of entry zone is painted, otherwise false.

keyPressed

public void keyPressed(int keyCode,
                       int gameAction)
Called to notify the component that a key is pressed.

Specified by:
keyPressed in class Component
Parameters:
keyCode - The key code.
gameAction - Game action corresponding to the key code.

pointerPressed

public void pointerPressed(int xpos,
                           int ypos)
Called to notify the component that pointer device was pressed.

Specified by:
pointerPressed in class Component
Parameters:
xpos - The X position of pointer on parent Canvas.
ypos - The Y position of pointer on parent Canvas.

removeValueChangListener

public void removeValueChangListener(ValueChangeListener listener)
Remove a listener.

Parameters:
listener - The listener to remove.

setBorderColor

public void setBorderColor(int red,
                           int green,
                           int blue)
Set the color for field border.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setBoxOpaque

public void setBoxOpaque(boolean boxOpaque)
Set a new value for entry zone opacity flag.

Parameters:
boxOpaque - Must be true to paint background of entry zone, and false to not paint it.

setCursorColor

public void setCursorColor(int red,
                           int green,
                           int blue)
Set the color for field cursor.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setCursorPosition

public void setCursorPosition(int cursorPosition)
Change the position of the cursor in field. Do nothing if given position is out of range.

Parameters:
cursorPosition - The cursor position. Must be zero for the cursor to be on the left.

setFieldBackground

public void setFieldBackground(int red,
                               int green,
                               int blue)
Set the color for field background.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setFieldBackgroundOff

public void setFieldBackgroundOff(int red,
                                  int green,
                                  int blue)
Set the color for field background if component is disabled.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setLabel

public void setLabel(java.lang.String label)
Set the field label.

Parameters:
label - The label to set.

setLabelColor

public void setLabelColor(int red,
                          int green,
                          int blue)
Set the label color.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setLabelFont

public void setLabelFont(javax.microedition.lcdui.Font labelFont)
Change the font used to display the field label.

Parameters:
labelFont - The label font to set.

setLabelPosition

public void setLabelPosition(int labelPosition)
Change the position of the field label.

Parameters:
labelPosition - The label position to set. Must be LABEL_LEFT or LABEL_TOP.

setMaximumSize

public void setMaximumSize(int width,
                           int height)
Set the maximum size for this component.

Overrides:
setMaximumSize in class Component
Parameters:
width - The maximum width.
height - The maximum height.

setText

public void setText(java.lang.String text)
Set the field value.

Parameters:
text - The new field value.

setTextColor

public void setTextColor(int red,
                         int green,
                         int blue)
Set the field value color.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setTextColorOff

public void setTextColorOff(int red,
                            int green,
                            int blue)
Set the field value color if component is disabled.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setTextFont

public void setTextFont(javax.microedition.lcdui.Font textFont)
Change the font used to display the field value.

Parameters:
textFont - The field value font to set.