public class Edit extends Control implements TextControl, HasValue<java.lang.String>
Here is an example showing an edit control being used:
public class MyProgram extends MainWindow { Edit edit; public void initUI() { edit = new Edit(); 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 popupNonBlocking, never with popup. 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 initUI() { 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")).popupNonBlocking(); } break; case ControlEvent.WINDOW_CLOSED: if (event.target == mb) ed.setText("Window closed."); break; } } }A long click on an Edit will result in a menu with copy/paste options to be displayed.
clipboardDelay
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
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 capitalise property
|
static byte |
ALL_NORMAL
to be used in the capitalise property
|
static byte |
ALL_UPPER
to be used in the capitalise property
|
boolean |
autoSelect
If set to true, the text will be auto-selected when the focus enters.
|
protected int |
back0 |
protected int |
back1 |
protected UpdateListener |
blinkListener |
static CalculatorBox |
calculator
The CalculatorBox used in all Edits.
|
static CalendarBox |
calendar
The CalendarBox used in all Edits.
|
protected boolean |
canMoveFocus
Set to false to disable focus change on this Edit
|
byte |
capitalise
Sets the capitalise settings for this Edit.
|
java.lang.String |
caption
The caption to draw when this Edit is empty.
|
int |
captionColor
The caption's color.
|
Image |
captionIcon
An optional caption's icon
|
CaptionPress |
captionPress
Handler for the CaptionPress
|
protected java.lang.StringBuffer |
chars |
static int |
clipboardDelay
Defines the time that the user will have to press to see a popup menu with copy/paste options.
|
static java.lang.String |
commandStr
Used to inform that a command operation has been made.
|
static java.lang.String |
copyStr
Used to inform that a copy operation has been made.
|
static byte |
CURRENCY
to be used in the setMode method
|
static java.lang.String |
currencyCharsSet
to be used in the setValidChars method
|
protected boolean |
cursorShowing |
static int |
cursorThickness
Cursor thickness
|
protected int |
cursorX |
static java.lang.String |
cutStr
Used to inform that a cut operation has been made.
|
static byte |
DATE
to be used in the setMode method
|
static java.lang.String |
dateSet
to be used in the setValidChars method
|
boolean |
drawLine |
protected boolean |
editable
Specifies if the control accepts input from the user.
|
protected int |
fColor |
int |
focusColor
Color to apply to the Edit when it has focus (works only on Android user interface style).
|
protected int[] |
fourColors |
protected int |
gap |
protected boolean |
hasBorder |
boolean |
hasCursorWhenNotEditable
Set to false if you don't want the cursor to blink when the edit is not editable
|
protected boolean |
hasFocus |
protected int |
insertPos |
protected boolean |
isMaskedEdit |
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
|
static byte |
KBD_NUMERIC
The NumericBox will be used for this Edit
|
static byte |
KBD_TIME
The TimeBox will be used for this Edit
|
protected byte |
kbdType |
static VirtualKeyboard |
keyboard
The KeyboardBox used in all Edits.
|
java.lang.String |
keyboardTitle
Defines a title that can be used in the Keyboards.
|
int |
lineColor
The line's color.
|
protected char[] |
mask
used only to compute the preferred width of this edit.
|
protected java.lang.StringBuffer |
masked |
protected FloatingLabel<Edit> |
materialCaption
Font used for the caption when hovering above the edit
|
protected int |
maxLength |
protected byte |
mode |
static byte |
NORMAL
to be used in the setMode method
|
protected Image |
npback |
static java.lang.String |
numbersSet
to be used in the setValidChars method
|
static CalculatorBox |
numeric
The NumericBox used in all Edits.
|
Rect |
oldBounds |
java.lang.String |
optionalValue4CalculatorBox
Defines an optional value to be used in the CalculatorBox when the keyboard type is KBD_NUMERIC or KBD_CALCULATOR.
|
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.
|
static java.lang.String |
pasteStr
Used to inform that a paste operation has been made.
|
boolean |
persistentSelection
Keep the selection persistent; otherwise, it is reset if you change the letter
|
static int |
prefH |
protected int |
pushedInsertPos |
protected int |
pushedStartSelectPos |
protected int |
pushedxOffset |
CalculatorBox.RangeCheck |
rangeCheck |
static boolean |
removeFocusOnAction |
static java.lang.String |
replaceStr
Used to inform that a replace operation has been made.
|
boolean |
selectLast
Keep selection of last character
|
boolean |
showKeyboardOnNextEvent |
protected int |
startSelectPos |
static TimeBox |
time
The TimeBox used in all Edits.
|
protected boolean |
useFillAsPreferred |
static boolean |
useNativeNumericPad
Set to true on Android devices to use the native numeric pad when mode is set to CURRENCY.
|
static boolean |
useNumericBoxInsteadOfCalculator
Use the NumericBox instead of the Calculator in all Edits that have mode equal to CURRENCY.
|
protected java.lang.String |
validChars |
boolean |
virtualKeyboard
Defines if this Edit can behave as with virtual keyboard or not.
|
protected int |
xMax |
protected int |
xMin |
protected int |
xOffset |
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
Edit()
Construct an Edit with FILL as preferred width.
|
Edit(java.lang.String mask)
Construct an Edit with the default width computed based in the specified
mask and in the control's font.
|
Modifier and Type | Method and Description |
---|---|
protected int |
charPos2x(int n) |
void |
clear()
Clears this control, settings the text to clearValueStr.
|
void |
clipboardCopy()
Copies the text to the clipboard.
|
void |
clipboardCut()
Cuts the selected text to the clipboard.
|
void |
clipboardPaste()
Paste from the clipboard into the Edit at the current insert position.
|
protected void |
draw(Graphics g) |
int |
getCaptionIconHeightFactor() |
int |
getCaptionIconPadding() |
Edit |
getCopy()
Returns a copy of this Edit with almost all features.
|
int[] |
getCursorPos()
Returns an array with the cursor positions.
|
int |
getDecimalPlaces()
Returns the number of decimal places.
|
static char[] |
getDefaultCurrencyMask(int decimalPlaces) |
byte |
getKeyboardType()
Returns the keyboard type of this Edit control.
|
int |
getLength()
Returns the length of the text.
|
java.lang.String |
getMask()
Returns the mask passed on the constructor.
|
FloatingLabel<Edit> |
getMaterialCaption()
Returns the materialCaption.
|
int |
getMaxLength() |
int |
getMode()
Return the current mode.
|
int |
getPreferredHeight()
Returns the preferred height of this control.
|
int |
getPreferredWidth()
Returns the preferred width of this control.
|
java.lang.String |
getText()
Returns the text displayed in the edit control.
|
java.lang.StringBuffer |
getTextBuffer()
Returns the text's buffer.
|
java.lang.String |
getTextWithoutMask()
Returns the text without the mask.
|
protected int |
getTextY() |
protected int |
getTotalCharWidth() |
int |
getTrimmedLength()
Returns the length of the text after applying a trim to it.
|
java.lang.String |
getValue() |
protected int |
getX0() |
Control |
handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on
the KeyEvent.
|
protected void |
hideSip() |
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
|
void |
mapKeys(java.lang.String from,
java.lang.String to)
Maps the keys in the from char array into the keys in the to char array.
|
protected void |
onBoundsChanged(boolean screenChanged)
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.
|
protected void |
onFontChanged()
Called after a setFont
|
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.
|
static boolean |
popupsHidden() |
protected void |
pushPosState() |
void |
setCaptionIconHeightFactor(int captionIconHeightFactor) |
void |
setCaptionIconPadding(int captionIconPadding) |
void |
setCursorPos(int pos)
Sets the cursor position
|
void |
setCursorPos(int start,
int end)
Sets the selected text of this Edit (if start != end).
|
void |
setDecimalPlaces(int count)
Set the number of decimal placed if a masked edit with CURRENCY mode.
|
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 mode constants,
without masking.
|
void |
setMode(byte mode,
boolean maskedEdit)
Used to set the valid characters that can be entered by using one of the mode constants,
optionally enabling the mask to be applied to the input.
|
void |
setRect(int x,
int y,
int width,
int height,
Control relative,
boolean screenChanged)
The relative positioning will be made with the given control (relative).
|
void |
setText(java.lang.String s)
Sets the text displayed in the edit control.
|
void |
setText(java.lang.String s,
boolean postPressed) |
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).
|
void |
setValue(java.lang.String value) |
protected void |
shiftScreen(boolean force) |
protected void |
shiftTo(Control next) |
protected boolean |
willOpenKeyboard()
Returns true if this is a MultiEdit or an Edit that has a standard keyboard.
|
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary
protected UpdateListener blinkListener
public static final int prefH
protected boolean hasFocus
protected boolean cursorShowing
protected boolean editable
setEditable(boolean)
public boolean overwrite
public int alignment
public java.lang.String caption
captionColor
public int captionColor
public int lineColor
public Image captionIcon
public CalculatorBox.RangeCheck rangeCheck
CalculatorBox.rangeCheck
public static boolean useNativeNumericPad
protected java.lang.StringBuffer chars
protected boolean hasBorder
protected int xMax
protected int xMin
protected int gap
protected int fColor
protected int back0
protected int back1
protected int[] fourColors
protected boolean isMaskedEdit
protected int insertPos
protected int startSelectPos
protected int xOffset
protected boolean useFillAsPreferred
protected java.lang.StringBuffer masked
protected int cursorX
protected Image npback
public boolean showKeyboardOnNextEvent
public static java.lang.String copyStr
public static java.lang.String cutStr
public static java.lang.String pasteStr
public static java.lang.String replaceStr
public static java.lang.String commandStr
protected boolean canMoveFocus
public CaptionPress captionPress
public boolean drawLine
public java.lang.String optionalValue4CalculatorBox
public java.lang.String keyboardTitle
public static int clipboardDelay
protected java.lang.String validChars
public static VirtualKeyboard keyboard
public static CalendarBox calendar
public static CalculatorBox calculator
public static CalculatorBox numeric
public static TimeBox time
protected byte mode
protected int maxLength
protected char[] mask
public byte capitalise
ALL_NORMAL
,
ALL_UPPER
,
ALL_LOWER
public static boolean removeFocusOnAction
public int focusColor
public static boolean useNumericBoxInsteadOfCalculator
ed.setKeyboard(Edit.KBD_NUMERIC)
.protected byte kbdType
public boolean hasCursorWhenNotEditable
public boolean autoSelect
public boolean selectLast
public boolean persistentSelection
public static final byte KBD_NONE
public static final byte KBD_DEFAULT
public static final byte KBD_KEYBOARD
public static final byte KBD_CALCULATOR
public static final byte KBD_CALENDAR
public static final byte KBD_NUMERIC
public static final byte KBD_TIME
public static final java.lang.String numbersSet
public static final java.lang.String currencyCharsSet
public static final java.lang.String dateSet
public static final byte NORMAL
public static final byte DATE
public static final byte CURRENCY
public static final byte PASSWORD
public static final byte PASSWORD_ALL
public static final byte ALL_NORMAL
public static final byte ALL_UPPER
public static final byte ALL_LOWER
public boolean virtualKeyboard
public static int cursorThickness
protected FloatingLabel<Edit> materialCaption
protected int pushedInsertPos
protected int pushedStartSelectPos
protected int pushedxOffset
public Rect oldBounds
public Edit()
public Edit(java.lang.String mask)
setMode(byte, boolean)
public void mapKeys(java.lang.String from, java.lang.String to)
ed.mapKeys("uiojklnm!.","1234567890");To make sure that lowercase characters are also handled, you should also change the capitalise mode:
ed.capitalise = Edit.ALL_LOWER;If you want to disable a set of keys, use the setValidChars method. Note that mapKeys have precendence over setValidChars.
from
- The source keys. Must have the same length of to
. Set to null to disable mapping.to
- The destination keys. Must have the same length of from
setValidChars(String)
public FloatingLabel<Edit> getMaterialCaption()
public void setDecimalPlaces(int count)
public int getDecimalPlaces()
public void setKeyboard(byte kbd)
public byte getKeyboardType()
KBD_NONE
,
KBD_DEFAULT
,
KBD_KEYBOARD
,
KBD_CALCULATOR
,
KBD_CALENDAR
,
KBD_NUMERIC
,
KBD_TIME
protected void onFontChanged()
Control
onFontChanged
in class Control
public java.lang.String getMask()
public void setMode(byte mode)
true
as parameter.
Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.NORMAL
,
DATE
,
CURRENCY
,
PASSWORD
,
PASSWORD_ALL
public int getMode()
public void setMode(byte mode, boolean maskedEdit)
NORMAL
,
DATE
,
CURRENCY
,
PASSWORD
,
PASSWORD_ALL
public static char[] getDefaultCurrencyMask(int decimalPlaces)
public void setValidChars(java.lang.String validCharsString)
protected boolean isCharValid(char c)
public void setMaxLength(int length)
public int getMaxLength()
protected void pushPosState()
protected void popPosState()
protected int getX0()
protected int charPos2x(int n)
public java.lang.String getText()
getText
in interface TextControl
getTextWithoutMask()
public java.lang.String getTextWithoutMask()
getText()
public java.lang.StringBuffer getTextBuffer()
public void setText(java.lang.String s, boolean postPressed)
public void setText(java.lang.String s)
setText
in interface TextControl
public void setEditable(boolean on)
public boolean isEditable()
protected void onBoundsChanged(boolean screenChanged)
Control
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public int getPreferredWidth()
Control
getPreferredWidth
in class Control
public int getPreferredHeight()
Control
getPreferredHeight
in class Control
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Control
protected int getTotalCharWidth()
protected int getTextY()
protected void draw(Graphics g)
public void setCursorPos(int start, int end)
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();
public void setCursorPos(int pos)
public int[] getCursorPos()
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); ...
public void popupKCC()
protected void shiftScreen(boolean force)
protected void hideSip()
public void onEvent(Event event)
protected void shiftTo(Control next)
public static boolean popupsHidden()
protected void onWindowPaintFinished()
Control
onWindowPaintFinished
in class Control
public void onPaint(Graphics g)
public int getLength()
public int getTrimmedLength()
getText().trim().length()
.public void clear()
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Control
handleGeographicalFocusChangeKeys
in class Control
ke
- The KeyEvent to be processedSettings.geographicalFocus
public void clipboardCopy()
public void clipboardCut()
public void clipboardPaste()
public Edit getCopy()
protected boolean willOpenKeyboard()
Control
willOpenKeyboard
in class Control
public java.lang.String getValue()
public void setValue(java.lang.String value)
public int getCaptionIconHeightFactor()
public void setCaptionIconHeightFactor(int captionIconHeightFactor)
public int getCaptionIconPadding()
public void setCaptionIconPadding(int captionIconPadding)
public void setRect(int x, int y, int width, int height, Control relative, boolean screenChanged)
Control
Important note: you can't use FILL/FIT with BEFORE/RIGHT/BOTTOM (for x,y).
add(new Label("1"),CENTER,CENTER); add(new Label("2"),AFTER,SAME); add(new Label("3"),SAME,AFTER); add(new Label("4"),BEFORE,SAME); add(new Label("5"),BEFORE,BEFORE);You will see this on screen:
512 43Note: add(control, x,y) does:
add(control); control.setRect(x,y,PREFERRED,PREFERRED);
Important! Always add the control to the container before doing a setRect.
The relative positioning does not work well if the control is placed outside screen bounds.
setRect
in class Control
x
- One of the relative positioning constants: LEFT, RIGHT, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.y
- One of the relative positioning constants: TOP, BOTTOM, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.width
- One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.height
- One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.relative
- To whom the position should be relative to; or null to be relative to the last control.screenChanged
- Indicates that a screen change (resize, collapse) occured and the reposition
method is calling this method. Set by the system. If you call this method directly, always pass false to it.Control.LEFT
,
Control.TOP
,
Control.RIGHT
,
Control.BOTTOM
,
Control.BEFORE
,
Control.AFTER
,
Control.CENTER
,
Control.SAME
,
Control.FILL
,
Control.PREFERRED
,
Control.FIT
,
Control.CENTER_OF
,
Control.RIGHT_OF
,
Control.BOTTOM_OF
,
Control.SCREENSIZE
,
Control.SCREENSIZEMIN
,
Control.SCREENSIZEMAX
,
Control.PARENTSIZE
,
Control.PARENTSIZEMIN
,
Control.PARENTSIZEMAX
,
Control.FONTSIZE
,
Container.add(Control, int, int)
,
Container.add(Control, int, int, Control)