waba.ui
Class Edit

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Edit
Direct Known Subclasses:
Edit

public class Edit
extends Control

Edit is a text entry control.

Here is an example showing an edit control being used:

 public class MyProgram extends MainWindow
 {
 Edit edit;

 public void onStart()
  {
  edit = new Edit(""); // mask used to compute preferred width - empty = fill width
  add(edit,LEFT,TOP);
  }
 
Important: if you wish to open a popup window after a FOCUS_OUT event has occured, you must open the window with popupModal, never with popupBlockingModal. Otherwise, the window will be openned twice. Here's a sample code on how to proceed:
 public class Test extends MainWindow
 {
Edit ed;
MessageBox mb;

public void onStart()
{
add(ed = new Edit(""), LEFT, CENTER);
add(new Button("btn"), LEFT, AFTER+5);
}

public void onEvent(Event event)
{
switch (event.type)
{
case ControlEvent.FOCUS_OUT:
if (event.target == ed)
{
event.consumed = true; // this is important!
(mb=new MessageBox("Hi","Verinha")).popupModal();
}
break;
case ControlEvent.WINDOW_CLOSED:
if (event.target == mb)
ed.setText("Window closed.");
break;
}
}
}
 


Field Summary
 int alignment
          Sets the alignment of this Edit, which can be LEFT (default), CENTER or RIGHT.
static byte ALL_LOWER
          to be used in the setCapitaliseMode method
static byte ALL_NORMAL
          to be used in the setCapitaliseMode method
static byte ALL_UPPER
          to be used in the setCapitaliseMode method
 boolean autoSelect
          If set to true, the text will be auto-selected when the focus enters
static Calculator calculator
           
static Calendar calendar
           
protected  byte capitalise
           
static byte CURRENCY
          to be used in the setMode method
static java.lang.String currencyCharsSet
          to be used in the setValidChars method
static byte DATE
          to be used in the setMode method
static java.lang.String dateSet
          to be used in the setValidChars method
 boolean editable
          Specifies if the control accepts input from the user.
protected  boolean hasBorder
           
 boolean hasCursorWhenNotEditable
          Set to false if you don't want the cursor to blink when the edit is not editable
static byte KBD_CALCULATOR
          The Calculator will be used for this Edit
static byte KBD_CALENDAR
          The Calendar will be used for this Edit
static byte KBD_DEFAULT
          The default keyboard for the current mode will be used for this Edit
static byte KBD_KEYBOARD
          The Keyboard class (or the internal virtual keyboard) will be used for this Edit
static byte KBD_NONE
          No keyboard will be popped up for this Edit
protected  byte kbdType
           
static Keyboard keyboard
           
protected  int len
           
 java.lang.String mask
          used only to compute the preferred width of this edit.
protected  int maxLength
           
static byte NORMAL
          to be used in the setMode method
static java.lang.String numbersSet
          to be used in the setValidChars method
 boolean overwrite
          Specifies if new chars should overwrite existing ones.
static byte PASSWORD
          to be used in the setMode method.
static byte PASSWORD_ALL
          to be used in the setMode method.
protected  int pushedInsertPos
           
protected  int pushedStartSelectPos
           
protected  int pushedxOffset
           
static boolean removeFocusOnAction
           
protected  java.lang.String validChars
           
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
Edit()
          Construct an Edit with a default width of 10 chars.
Edit(java.lang.String mask)
          Construct an Edit with the default width computed based in the specified mask and in the control's font.
 
Method Summary
protected  int charPos2x(int n)
           
 void clear()
          Clears this control, settings the text to clearValueStr.
protected  void draw(Graphics g, boolean cursorOnly)
           
 int[] getCursorPos()
          Returns an array with the cursor positions.
 byte getKeyboardType()
           
 int getLength()
          Returns the length of the text.
 int getPreferredHeight()
          Returns the preffered height of this control.
 int getPreferredWidth()
          Returns the preffered width of this control.
 java.lang.String getText()
          Returns the text displayed in the edit control.
protected  boolean isCharValid(char c)
          Return true if the given char exists in the set of valid characters for this Edit
 boolean isEditable()
          Gets if the control accepts input from the user
protected  void onBoundsChanged()
          Called after a setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called by the system to pass events to the edit control.
 void onPaint(Graphics g)
          Called by the system to draw the edit control.
protected  void onWindowPaintFinished()
          Called after the window has finished a paint.
protected  void popPosState()
           
 void popupKCC()
          user method to popup the keyboard/calendar/calculator for this edit.
protected  void pushPosState()
           
 void setCapitaliseMode(byte cap)
          Sets the capitalise settings for this Edit.
 void setCursorPos(int start, int end)
          Sets the selected text of this Edit (if start !
 void setEditable(boolean on)
          Sets if the control accepts input from the user
 void setKeyboard(byte kbd)
          Used to change the default keyboard to be used with this Edit control.
 void setMaxLength(int length)
          Sets the desired maximum length for text entered in the Edit.
 void setMode(byte mode)
          Used to set the valid characters that can be entered by using one of the constants DATE, CURRENCY and NORMAL.
 void setText(java.lang.String s)
          Sets the text displayed in the edit control.
 void setValidChars(java.lang.String validCharsString)
          Sets the valid chars that can be entered in this edit (they are converted to uppercase to make the verification easy). if null is passed, any char can be entered. (case insensitive). added by guich
protected  int x2charPos(int x)
           
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onFontChanged, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

editable

public boolean editable
Specifies if the control accepts input from the user. Note: do not change this directly; use the setEditable instead

overwrite

public boolean overwrite
Specifies if new chars should overwrite existing ones.

alignment

public int alignment
Sets the alignment of this Edit, which can be LEFT (default), CENTER or RIGHT. Note that it will always edit at left, but on focus lost, it will drawn aligned.
Since:
SuperWaba 5.03

len

protected int len

hasBorder

protected boolean hasBorder

validChars

protected java.lang.String validChars

keyboard

public static Keyboard keyboard

calendar

public static Calendar calendar

calculator

public static Calculator calculator

maxLength

protected int maxLength

mask

public java.lang.String mask
used only to compute the preferred width of this edit. If the mask is empty, the edit fills to width. Can be accessed directly

capitalise

protected byte capitalise

removeFocusOnAction

public static boolean removeFocusOnAction

kbdType

protected byte kbdType

hasCursorWhenNotEditable

public boolean hasCursorWhenNotEditable
Set to false if you don't want the cursor to blink when the edit is not editable

autoSelect

public boolean autoSelect
If set to true, the text will be auto-selected when the focus enters

KBD_NONE

public static final byte KBD_NONE
No keyboard will be popped up for this Edit

KBD_DEFAULT

public static final byte KBD_DEFAULT
The default keyboard for the current mode will be used for this Edit

KBD_KEYBOARD

public static final byte KBD_KEYBOARD
The Keyboard class (or the internal virtual keyboard) will be used for this Edit

KBD_CALCULATOR

public static final byte KBD_CALCULATOR
The Calculator will be used for this Edit

KBD_CALENDAR

public static final byte KBD_CALENDAR
The Calendar will be used for this Edit

numbersSet

public static final java.lang.String numbersSet
to be used in the setValidChars method

currencyCharsSet

public static final java.lang.String currencyCharsSet
to be used in the setValidChars method

dateSet

public static final java.lang.String dateSet
to be used in the setValidChars method

NORMAL

public static final byte NORMAL
to be used in the setMode method

DATE

public static final byte DATE
to be used in the setMode method

CURRENCY

public static final byte CURRENCY
to be used in the setMode method

PASSWORD

public static final byte PASSWORD
to be used in the setMode method. The last char will be always shown

PASSWORD_ALL

public static final byte PASSWORD_ALL
to be used in the setMode method. All chars are replaced by '*'

ALL_NORMAL

public static final byte ALL_NORMAL
to be used in the setCapitaliseMode method

ALL_UPPER

public static final byte ALL_UPPER
to be used in the setCapitaliseMode method

ALL_LOWER

public static final byte ALL_LOWER
to be used in the setCapitaliseMode method

pushedInsertPos

protected int pushedInsertPos

pushedStartSelectPos

protected int pushedStartSelectPos

pushedxOffset

protected int pushedxOffset
Constructor Detail

Edit

public Edit()
Construct an Edit with a default width of 10 chars.

Edit

public Edit(java.lang.String mask)
Construct an Edit with the default width computed based in the specified mask and in the control's font. Note that the mask does not masks the input. If mask is "", the FILL width is choosen.
Method Detail

setCapitaliseMode

public void setCapitaliseMode(byte cap)
Sets the capitalise settings for this Edit. Use ALL_NORMAL, ALL_UPPER and ALL_LOWER. Text entered will made as is, uppercase or lowercase

setKeyboard

public void setKeyboard(byte kbd)
Used to change the default keyboard to be used with this Edit control. Use the constants KBD_xxxx. Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.

getKeyboardType

public byte getKeyboardType()

setMode

public void setMode(byte mode)
Used to set the valid characters that can be entered by using one of the constants DATE, CURRENCY and NORMAL. Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.

setValidChars

public void setValidChars(java.lang.String validCharsString)
Sets the valid chars that can be entered in this edit (they are converted to uppercase to make the verification easy). if null is passed, any char can be entered. (case insensitive). added by guich

isCharValid

protected boolean isCharValid(char c)
Return true if the given char exists in the set of valid characters for this Edit

setMaxLength

public void setMaxLength(int length)
Sets the desired maximum length for text entered in the Edit.
Since:
SuperWaba2.0beta4

pushPosState

protected void pushPosState()

popPosState

protected void popPosState()

x2charPos

protected int x2charPos(int x)

charPos2x

protected int charPos2x(int n)

getText

public java.lang.String getText()
Returns the text displayed in the edit control.

setText

public void setText(java.lang.String s)
Sets the text displayed in the edit control.

setEditable

public void setEditable(boolean on)
Sets if the control accepts input from the user

isEditable

public boolean isEditable()
Gets if the control accepts input from the user

onBoundsChanged

protected void onBoundsChanged()
Description copied from class: Control
Called after a setRect.
Overrides:
onBoundsChanged in class Control

getPreferredWidth

public int getPreferredWidth()
Description copied from class: Control
Returns the preffered width of this control.
Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Description copied from class: Control
Returns the preffered height of this control.
Overrides:
getPreferredHeight in class Control

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Control

draw

protected void draw(Graphics g,
                    boolean cursorOnly)

setCursorPos

public void setCursorPos(int start,
                         int end)
Sets the selected text of this Edit (if start != end). Can be used to set the cursor position, if start equals end. Start must be less or equal to end, and both must be >= 0. It can also be used to clear the selectedText, calling setCursorPos(-1,0). Note: if you're setting the cursor position before the edit is drawn for the first time, the edit will not be scrolled if the end position goes beyond the limits. Important! No bounds checking is made. Be sure to not call this method with invalid positions! Example:
 ed.setText("1234567890123456");
 ed.setCursorPos(3,14);
 ed.requestFocus();
 

getCursorPos

public int[] getCursorPos()
Returns an array with the cursor positions. You can use it with getText to find the selected text String. E.g.:
 int []cursorPos = ed.getCursorPos();
 int start = cursorPos[0];
 int end = cursorPos[1];
 String text = ed.getText();
 if (start != -1) // is the text selected?
 {
    String selectedText = text.substring(start,end);
    ...
 

popupKCC

public void popupKCC()
user method to popup the keyboard/calendar/calculator for this edit.

onEvent

public void onEvent(Event event)
Called by the system to pass events to the edit control.
Overrides:
onEvent in class Control
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

onWindowPaintFinished

protected void onWindowPaintFinished()
Description copied from class: Control
Called after the window has finished a paint.
Overrides:
onWindowPaintFinished in class Control

onPaint

public void onPaint(Graphics g)
Called by the system to draw the edit control.
Overrides:
onPaint in class Control
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

getLength

public int getLength()
Returns the length of the text.
Since:
SuperWaba 4.21

clear

public void clear()
Clears this control, settings the text to clearValueStr.
Overrides:
clear in class Control