Package totalcross.ui
Class Edit
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Edit
-
- All Implemented Interfaces:
HasValue<java.lang.String>,TextControl
- Direct Known Subclasses:
KeyboardEdit,OutlinedEdit
public class Edit extends Control implements TextControl, HasValue<java.lang.String>
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 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.- See Also:
clipboardDelay
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description intalignmentSets the alignment of this Edit, which can be LEFT (default), CENTER or RIGHT.static byteALL_LOWERto be used in the capitalise propertystatic byteALL_NORMALto be used in the capitalise propertystatic byteALL_UPPERto be used in the capitalise propertybooleanautoSelectIf set to true, the text will be auto-selected when the focus enters.protected intback0protected intback1protected UpdateListenerblinkListenerstatic CalculatorBoxcalculatorThe CalculatorBox used in all Edits.static CalendarBoxcalendarThe CalendarBox used in all Edits.protected booleancanMoveFocusSet to false to disable focus change on this EditbytecapitaliseSets the capitalise settings for this Edit.java.lang.StringcaptionThe caption to draw when this Edit is empty.intcaptionColorThe caption's color.ImagecaptionIconAn optional caption's iconCaptionPresscaptionPressHandler for the CaptionPressprotected java.lang.StringBuffercharsstatic intclipboardDelayDefines the time that the user will have to press to see a popup menu with copy/paste options.static java.lang.StringcommandStrUsed to inform that a command operation has been made.static java.lang.StringcopyStrUsed to inform that a copy operation has been made.static byteCURRENCYto be used in the setMode methodstatic java.lang.StringcurrencyCharsSetto be used in the setValidChars methodprotected booleancursorShowingstatic intcursorThicknessCursor thicknessprotected intcursorXstatic java.lang.StringcutStrUsed to inform that a cut operation has been made.static byteDATEto be used in the setMode methodstatic java.lang.StringdateSetto be used in the setValidChars methodbooleandrawLineprotected booleaneditableSpecifies if the control accepts input from the user.protected intfColorintfocusColorColor to apply to the Edit when it has focus (works only on Android user interface style).booleanforceBackgroundColorIf setted it will force the Edit to use the color on background.protected int[]fourColorsprotected intgapprotected booleanhasBorderbooleanhasCursorWhenNotEditableSet to false if you don't want the cursor to blink when the edit is not editableprotected booleanhasFocusprotected intinsertPosprotected booleanisMaskedEditstatic byteKBD_CALCULATORThe Calculator will be used for this Edit.static byteKBD_CALENDARThe Calendar will be used for this Edit.static byteKBD_DEFAULTThe default keyboard for the current mode will be used for this Editstatic byteKBD_KEYBOARDThe Keyboard class (or the internal virtual keyboard) will be used for this Edit.static byteKBD_NONENo keyboard will be popped up for this Editstatic byteKBD_NUMERICThe NumericBox will be used for this Editstatic byteKBD_TIMEThe TimeBox will be used for this Editprotected bytekbdTypestatic VirtualKeyboardkeyboardThe KeyboardBox used in all Edits.java.lang.StringkeyboardTitleDefines a title that can be used in the Keyboards.intlineColorThe line's color.protected char[]maskused only to compute the preferred width of this edit.protected java.lang.StringBuffermaskedprotected FloatingLabel<Edit>materialCaptionFont used for the caption when hovering above the editprotected intmaxLengthprotected bytemodestatic byteNORMALto be used in the setMode methodprotected Imagenpbackstatic java.lang.StringnumbersSetto be used in the setValidChars methodstatic CalculatorBoxnumericThe NumericBox used in all Edits.RectoldBoundsjava.lang.StringoptionalValue4CalculatorBoxDefines an optional value to be used in the CalculatorBox when the keyboard type is KBD_NUMERIC or KBD_CALCULATOR.booleanoverwriteSpecifies if new chars should overwrite existing ones.static bytePASSWORDto be used in the setMode method.static bytePASSWORD_ALLto be used in the setMode method.static java.lang.StringpasteStrUsed to inform that a paste operation has been made.booleanpersistentSelectionKeep the selection persistent; otherwise, it is reset if you change the letterstatic intprefHprotected intpushedInsertPosprotected intpushedStartSelectPosprotected intpushedxOffsetCalculatorBox.RangeCheckrangeCheckstatic booleanremoveFocusOnActionstatic java.lang.StringreplaceStrUsed to inform that a replace operation has been made.booleanselectLastKeep selection of last characterbooleanshowKeyboardOnNextEventprotected intstartSelectPosstatic TimeBoxtimeThe TimeBox used in all Edits.protected booleanuseFillAsPreferredstatic booleanuseNativeNumericPadSet to true on Android devices to use the native numeric pad when mode is set to CURRENCY.static booleanuseNumericBoxInsteadOfCalculatorUse the NumericBox instead of the Calculator in all Edits that have mode equal to CURRENCY.protected java.lang.StringvalidCharsbooleanvirtualKeyboardDefines if this Edit can behave as with virtual keyboard or not.protected intxMaxprotected intxMinprotected intxOffset-
Fields inherited from class totalcross.ui.Control
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intcharPos2x(int n)voidclear()Clears this control, settings the text to clearValueStr.voidclipboardCopy()Copies the text to the clipboard.voidclipboardCut()Cuts the selected text to the clipboard.voidclipboardPaste()Paste from the clipboard into the Edit at the current insert position.protected voiddraw(Graphics g)intgetCaptionIconHeightFactor()intgetCaptionIconPadding()EditgetCopy()Returns a copy of this Edit with almost all features.int[]getCursorPos()Returns an array with the cursor positions.intgetDecimalPlaces()Returns the number of decimal places.static char[]getDefaultCurrencyMask(int decimalPlaces)bytegetKeyboardType()Returns the keyboard type of this Edit control.intgetLength()Returns the length of the text.java.lang.StringgetMask()Returns the mask passed on the constructor.FloatingLabel<Edit>getMaterialCaption()Returns the materialCaption.intgetMaxLength()intgetMode()Return the current mode.intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.java.lang.StringgetText()Returns the text displayed in the edit control.java.lang.StringBuffergetTextBuffer()Returns the text's buffer.java.lang.StringgetTextWithoutMask()Returns the text without the mask.protected intgetTextY()protected intgetTotalCharWidth()intgetTrimmedLength()Returns the length of the text after applying a trim to it.java.lang.StringgetValue()protected intgetX0()ControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.protected voidhideSip()protected booleanisCharValid(char c)Return true if the given char exists in the set of valid characters for this EditbooleanisEditable()Gets if the control accepts input from the uservoidmapKeys(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 voidonBoundsChanged(boolean screenChanged)Called after a setRect.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called by the system to pass events to the edit control.protected voidonFontChanged()Called after a setFontvoidonPaint(Graphics g)Called by the system to draw the edit control.protected voidonWindowPaintFinished()Called after the window has finished a paint.protected voidpopPosState()voidpopupKCC()User method to popup the keyboard/calendar/calculator for this edit.static booleanpopupsHidden()protected voidpushPosState()voidsetCaptionIconHeightFactor(int captionIconHeightFactor)voidsetCaptionIconPadding(int captionIconPadding)voidsetCursorPos(int pos)Sets the cursor positionvoidsetCursorPos(int start, int end)Sets the selected text of this Edit (if start != end).voidsetDecimalPlaces(int count)Set the number of decimal placed if a masked edit with CURRENCY mode.voidsetEditable(boolean on)Sets if the control accepts input from the user.voidsetKeyboard(byte kbd)Used to change the default keyboard to be used with this Edit control.voidsetMaxLength(int length)Sets the desired maximum length for text entered in the Edit.voidsetMode(byte mode)Used to set the valid characters that can be entered by using one of the mode constants, without masking.voidsetMode(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.voidsetRect(int x, int y, int width, int height, Control relative, boolean screenChanged)The relative positioning will be made with the given control (relative).voidsetText(java.lang.String s)Sets the text displayed in the edit control.voidsetText(java.lang.String s, boolean postPressed)voidsetValidChars(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).voidsetValue(java.lang.String value)protected voidshiftScreen(boolean force)protected voidshiftTo(Control next)protected booleanwillOpenKeyboard()Returns true if this is a MultiEdit or an Edit that has a standard keyboard.-
Methods inherited from class totalcross.ui.Control
_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
-
-
-
-
Field Detail
-
blinkListener
protected UpdateListener blinkListener
-
prefH
public static final int prefH
-
hasFocus
protected boolean hasFocus
-
cursorShowing
protected boolean cursorShowing
-
editable
protected boolean editable
Specifies if the control accepts input from the user. Note: do not change this directly; use the setEditable method instead.- See Also:
setEditable(boolean)
-
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
-
caption
public java.lang.String caption
The caption to draw when this Edit is empty. In Material UI, you must set the caption BEFORE you add this control to the container; also remember to set the height to at least PREFERRED, it is 75% taller.- See Also:
captionColor
-
captionColor
public int captionColor
The caption's color.
-
lineColor
public int lineColor
The line's color.
-
captionIcon
public Image captionIcon
An optional caption's icon
-
rangeCheck
public CalculatorBox.RangeCheck rangeCheck
- See Also:
CalculatorBox.rangeCheck
-
useNativeNumericPad
public static boolean useNativeNumericPad
Set to true on Android devices to use the native numeric pad when mode is set to CURRENCY. Note that the numeric keybaord will probably appear only on the default keyboard.
-
chars
protected java.lang.StringBuffer chars
-
hasBorder
protected boolean hasBorder
-
xMax
protected int xMax
-
xMin
protected int xMin
-
gap
protected int gap
-
fColor
protected int fColor
-
back0
protected int back0
-
back1
protected int back1
-
fourColors
protected int[] fourColors
-
isMaskedEdit
protected boolean isMaskedEdit
-
insertPos
protected int insertPos
-
startSelectPos
protected int startSelectPos
-
xOffset
protected int xOffset
-
useFillAsPreferred
protected boolean useFillAsPreferred
-
masked
protected java.lang.StringBuffer masked
-
cursorX
protected int cursorX
-
npback
protected Image npback
-
showKeyboardOnNextEvent
public boolean showKeyboardOnNextEvent
-
copyStr
public static java.lang.String copyStr
Used to inform that a copy operation has been made. You can localize this message if you wish.
-
cutStr
public static java.lang.String cutStr
Used to inform that a cut operation has been made. You can localize this message if you wish.
-
pasteStr
public static java.lang.String pasteStr
Used to inform that a paste operation has been made. You can localize this message if you wish.
-
replaceStr
public static java.lang.String replaceStr
Used to inform that a replace operation has been made. You can localize this message if you wish.
-
commandStr
public static java.lang.String commandStr
Used to inform that a command operation has been made. You can localize this message if you wish.
-
canMoveFocus
protected boolean canMoveFocus
Set to false to disable focus change on this Edit
-
captionPress
public CaptionPress captionPress
Handler for the CaptionPress
-
drawLine
public boolean drawLine
-
optionalValue4CalculatorBox
public java.lang.String optionalValue4CalculatorBox
Defines an optional value to be used in the CalculatorBox when the keyboard type is KBD_NUMERIC or KBD_CALCULATOR. Replaces the decimal separator / 00 char.- Since:
- TotalCross 1.5
-
keyboardTitle
public java.lang.String keyboardTitle
Defines a title that can be used in the Keyboards.- Since:
- TotalCross 1.53
-
clipboardDelay
public static int clipboardDelay
Defines the time that the user will have to press to see a popup menu with copy/paste options. Set to -1 to disable it; defaults to 1500 (1.5 seconds) in pen devices, -1 in finger devices (because in these devices . Also affects MultiEdit.- Since:
- TotalCross 1.3
-
forceBackgroundColor
public boolean forceBackgroundColor
If setted it will force the Edit to use the color on background.
-
validChars
protected java.lang.String validChars
-
keyboard
public static VirtualKeyboard keyboard
The KeyboardBox used in all Edits.
-
calendar
public static CalendarBox calendar
The CalendarBox used in all Edits.
-
calculator
public static CalculatorBox calculator
The CalculatorBox used in all Edits.
-
numeric
public static CalculatorBox numeric
The NumericBox used in all Edits.
-
time
public static TimeBox time
The TimeBox used in all Edits.
-
mode
protected byte mode
-
maxLength
protected int maxLength
-
mask
protected char[] mask
used only to compute the preferred width of this edit. If the mask is empty, the edit fills to width.
-
capitalise
public byte capitalise
Sets the capitalise settings for this Edit. Text entered will made as is, uppercase or lowercase- See Also:
ALL_NORMAL,ALL_UPPER,ALL_LOWER
-
removeFocusOnAction
public static boolean removeFocusOnAction
-
focusColor
public int focusColor
Color to apply to the Edit when it has focus (works only on Android user interface style). By default, there's only a blinking cursor.- Since:
- TotalCross 1.3
-
useNumericBoxInsteadOfCalculator
public static boolean useNumericBoxInsteadOfCalculator
Use the NumericBox instead of the Calculator in all Edits that have mode equal to CURRENCY. Note that you can set for each control by callinged.setKeyboard(Edit.KBD_NUMERIC).- Since:
- TotalCross 1.3
-
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. True by default on penless devices.
-
selectLast
public boolean selectLast
Keep selection of last character
-
persistentSelection
public boolean persistentSelection
Keep the selection persistent; otherwise, it is reset if you change the letter
-
KBD_NONE
public static final byte KBD_NONE
No keyboard will be popped up for this Edit- See Also:
- Constant Field Values
-
KBD_DEFAULT
public static final byte KBD_DEFAULT
The default keyboard for the current mode will be used for this Edit- See Also:
- Constant Field Values
-
KBD_KEYBOARD
public static final byte KBD_KEYBOARD
The Keyboard class (or the internal virtual keyboard) will be used for this Edit. To change the window colors that may open, make sure to see the UIColors static attributes.- See Also:
- Constant Field Values
-
KBD_CALCULATOR
public static final byte KBD_CALCULATOR
The Calculator will be used for this Edit. To change the window colors that may open, make sure to see the UIColors static attributes.- See Also:
- Constant Field Values
-
KBD_CALENDAR
public static final byte KBD_CALENDAR
The Calendar will be used for this Edit. To change the window colors that may open, make sure to see the UIColors static attributes.- See Also:
- Constant Field Values
-
KBD_NUMERIC
public static final byte KBD_NUMERIC
The NumericBox will be used for this Edit- See Also:
- Constant Field Values
-
KBD_TIME
public static final byte KBD_TIME
The TimeBox will be used for this Edit- See Also:
- Constant Field Values
-
numbersSet
public static final java.lang.String numbersSet
to be used in the setValidChars method- See Also:
- Constant Field Values
-
currencyCharsSet
public static final java.lang.String currencyCharsSet
to be used in the setValidChars method- See Also:
- Constant Field Values
-
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- See Also:
- Constant Field Values
-
DATE
public static final byte DATE
to be used in the setMode method- See Also:
- Constant Field Values
-
CURRENCY
public static final byte CURRENCY
to be used in the setMode method- See Also:
- Constant Field Values
-
PASSWORD
public static final byte PASSWORD
to be used in the setMode method. The last char will be always shown- See Also:
- Constant Field Values
-
PASSWORD_ALL
public static final byte PASSWORD_ALL
to be used in the setMode method. All chars are replaced by '*'- See Also:
- Constant Field Values
-
ALL_NORMAL
public static final byte ALL_NORMAL
to be used in the capitalise property- See Also:
- Constant Field Values
-
ALL_UPPER
public static final byte ALL_UPPER
to be used in the capitalise property- See Also:
- Constant Field Values
-
ALL_LOWER
public static final byte ALL_LOWER
to be used in the capitalise property- See Also:
- Constant Field Values
-
virtualKeyboard
public boolean virtualKeyboard
Defines if this Edit can behave as with virtual keyboard or not.- Since:
- TotalCross 1.6
-
cursorThickness
public static int cursorThickness
Cursor thickness
-
materialCaption
protected FloatingLabel<Edit> materialCaption
Font used for the caption when hovering above the edit
-
pushedInsertPos
protected int pushedInsertPos
-
pushedStartSelectPos
protected int pushedStartSelectPos
-
pushedxOffset
protected int pushedxOffset
-
oldBounds
public Rect oldBounds
-
-
Constructor Detail
-
Edit
public Edit()
Construct an Edit with FILL as preferred width. Note that you cannot use RIGHT or CENTER at the x coordinate if you use this constructor.
-
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. In order to allow the mask to be used as a real mask, you must call the setMode method. If mask is "", the FILL width is choosen.- See Also:
setMode(byte, boolean)
-
-
Method Detail
-
mapKeys
public 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. For example enable a 'numeric pad' on devices that has the 1 in the u character, you can use this: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.- Parameters:
from- The source keys. Must have the same length ofto. Set to null to disable mapping.to- The destination keys. Must have the same length offrom- Since:
- TotalCross 1.01
- See Also:
setValidChars(String)
-
getMaterialCaption
public FloatingLabel<Edit> getMaterialCaption()
Returns the materialCaption. Returns null if Material Design is not set.
-
setDecimalPlaces
public void setDecimalPlaces(int count)
Set the number of decimal placed if a masked edit with CURRENCY mode. Default is 2 decimal places. It cannot be used with masked Edits; pass the number of decimal places in the mask itself. The only exception is when you want to use the default CURRENCY mask, passing a null mask in the constructor; in this situation, you can call setDecimalPlaces before calling setMode, and a mask will be constructed with the given number of decimals.
-
getDecimalPlaces
public int getDecimalPlaces()
Returns the number of decimal places.
-
setKeyboard
public void setKeyboard(byte kbd)
Used to change the default keyboard to be used with this Edit control. To change the window colors that may open, make sure to see the UIColors static attributes. Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.
-
getKeyboardType
public byte getKeyboardType()
Returns the keyboard type of this Edit control.- Since:
- SuperWaba 5.67
- See Also:
KBD_NONE,KBD_DEFAULT,KBD_KEYBOARD,KBD_CALCULATOR,KBD_CALENDAR,KBD_NUMERIC,KBD_TIME
-
onFontChanged
protected void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
getMask
public java.lang.String getMask()
Returns the mask passed on the constructor.
-
setMode
public void setMode(byte mode)
Used to set the valid characters that can be entered by using one of the mode constants, without masking. To enable masking the input, you have to call the setMode method passing the mode andtrueas parameter. Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.- See Also:
NORMAL,DATE,CURRENCY,PASSWORD,PASSWORD_ALL
-
getMode
public int getMode()
Return the current mode.- Since:
- TotalCross 1.27
-
setMode
public 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. Note that setMode calls setKeyboard(KBD_DEFAULT), so be sure to set the mode before calling setKeyboard.- See Also:
NORMAL,DATE,CURRENCY,PASSWORD,PASSWORD_ALL
-
getDefaultCurrencyMask
public static char[] getDefaultCurrencyMask(int decimalPlaces)
-
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. The chars are case insensitive. If you pass "" (empty string), no chars will be able to be inputted, and movement, delete and copy/paste operations will also be disabled.
-
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. Does nothing if the edit has a mask.- Since:
- SuperWaba 2.0 beta 4
-
getMaxLength
public int getMaxLength()
-
pushPosState
protected void pushPosState()
-
popPosState
protected void popPosState()
-
getX0
protected int getX0()
-
charPos2x
protected int charPos2x(int n)
-
getText
public java.lang.String getText()
Returns the text displayed in the edit control. If masking is enabled, the text with the mask is returned; to get the text without the mask, use the getTextWithoutMask method.- Specified by:
getTextin interfaceTextControl- See Also:
getTextWithoutMask()
-
getTextWithoutMask
public java.lang.String getTextWithoutMask()
Returns the text without the mask. For non-currency mode, only chars whose corresponding mask is '9' are returned.- See Also:
getText()
-
getTextBuffer
public java.lang.StringBuffer getTextBuffer()
Returns the text's buffer. Do NOT change the buffer contents, since changing it will not affect the char widths array, thus, leading to a wrong display.- Since:
- TotalCross 1.0
-
setText
public void setText(java.lang.String s, boolean postPressed)
-
setText
public void setText(java.lang.String s)
Sets the text displayed in the edit control. If you're setting the text in CURRENCY mode, the text must be set not formatted (unmasked).- Specified by:
setTextin interfaceTextControl
-
setEditable
public void setEditable(boolean on)
Sets if the control accepts input from the user. If set to false, you must explicitly call the clear method of this edit.
-
isEditable
public boolean isEditable()
Gets if the control accepts input from the user
-
onBoundsChanged
protected void onBoundsChanged(boolean screenChanged)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
Description copied from class:ControlCalled 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:
onColorsChangedin classControl
-
getTotalCharWidth
protected int getTotalCharWidth()
-
getTextY
protected int getTextY()
-
draw
protected void draw(Graphics g)
-
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, callingsetCursorPos(-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();
-
setCursorPos
public void setCursorPos(int pos)
Sets the cursor position
-
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.
-
shiftScreen
protected void shiftScreen(boolean force)
-
hideSip
protected void hideSip()
-
onEvent
public void onEvent(Event event)
Called by the system to pass events to the edit control.
-
shiftTo
protected void shiftTo(Control next)
-
popupsHidden
public static boolean popupsHidden()
-
onWindowPaintFinished
protected void onWindowPaintFinished()
Description copied from class:ControlCalled after the window has finished a paint. Only called to the focused control and the parent's window.- Overrides:
onWindowPaintFinishedin classControl
-
onPaint
public void onPaint(Graphics g)
Called by the system to draw the edit control.
-
getLength
public int getLength()
Returns the length of the text.- Since:
- SuperWaba 4.21
-
getTrimmedLength
public int getTrimmedLength()
Returns the length of the text after applying a trim to it. This method consumes less memory thangetText().trim().length().- Since:
- TotalCross 1.3
-
clear
public void clear()
Clears this control, settings the text to clearValueStr. Note that if the Edit is not editable, you will have to explicitly call the clear method of this Edit.
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classControl- Parameters:
ke- The KeyEvent to be processed- Returns:
- The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
- See Also:
Settings.geographicalFocus
-
clipboardCopy
public void clipboardCopy()
Copies the text to the clipboard. If there's a selected text, copies the portion selected, otherwise, copies the whole text.- Since:
- TotalCross 1.14
-
clipboardCut
public void clipboardCut()
Cuts the selected text to the clipboard.- Since:
- TotalCross 1.14
-
clipboardPaste
public void clipboardPaste()
Paste from the clipboard into the Edit at the current insert position.- Since:
- TotalCross 1.14
-
getCopy
public Edit getCopy()
Returns a copy of this Edit with almost all features. Used by Keyboard and SIPBox classes.- Since:
- TotalCross 1.27
-
willOpenKeyboard
protected boolean willOpenKeyboard()
Description copied from class:ControlReturns true if this is a MultiEdit or an Edit that has a standard keyboard.- Overrides:
willOpenKeyboardin classControl
-
getValue
public java.lang.String getValue()
-
setValue
public void setValue(java.lang.String value)
-
getCaptionIconHeightFactor
public int getCaptionIconHeightFactor()
-
setCaptionIconHeightFactor
public void setCaptionIconHeightFactor(int captionIconHeightFactor)
-
getCaptionIconPadding
public int getCaptionIconPadding()
-
setCaptionIconPadding
public void setCaptionIconPadding(int captionIconPadding)
-
setRect
public void setRect(int x, int y, int width, int height, Control relative, boolean screenChanged)Description copied from class:ControlThe relative positioning will be made with the given control (relative). Note that in this case, only the SAME,BEFORE,AFTER are affected by the given control. Here is an example of relative positioning: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 43
Note: 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.
- Overrides:
setRectin classControl- Parameters:
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 therepositionmethod is calling this method. Set by the system. If you call this method directly, always pass false to it.- See Also:
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)
-
-