public class MultiEdit extends Container implements Scrollable, TextControl, HasValue<java.lang.String>
Here is an example showing an Edit control being used:
import totalcross.ui.*; public class MyProgram extends MainWindow { MultiEdit mEdit; public void initUI() { // the constructor method is called with the mask, the number of lines // and the vertical interval in pixel between two lines mEdit = new MultiEdit("",3,1); add(mEdit,LEFT,TOP); // add/setRect must precede setText mEdit.setText("What text you want"); // eventually } }If the MultiEdit is not editable, the user can scroll the edit a page at a time just by clicking in the middle upper or middle lower.
IN MATERIAL UI, IS VERY IMPORTANT THAT THE CAPTION IS SET BEFORE ADDING THE CONTROL.
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
boolean |
autoSelect
If set to true, the text will be auto-selected when the focus enters.
|
byte |
capitalise
Sets the capitalise settings for this MultiEdit.
|
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 |
boolean |
drawDots
If true, a dotted line appears under each row of text (on by default)
|
protected boolean |
editable |
protected IntVector |
first |
protected Flick |
flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
|
int |
gap
The gap between the rows.
|
static boolean |
hasCursorWhenNotEditable
Set to false if you don't want the cursor to blink when the edit is not editable
|
protected boolean |
hasFocus |
protected boolean |
improvedGeographicalFocus
Set to true if you want the control to decide whether to gain/lose focus automatically, without having to press ACTION.
|
boolean |
justify
Set to true to justify the text when the MultiEdit is NOT editable.
|
int |
lastInsertPos
The last insert position before this control looses focus.
|
java.lang.String |
mask
The mask used to infer the preferred width.
|
boolean |
persistentSelection
Keep the selection persistent; otherwise, it is reset if you change the letter
|
int |
rowCount
Used to set the number of rows of this MultiEdit; used as parameter to compute the preferred height.
|
protected ScrollBar |
sb |
boolean |
selectLast
Keep selection of last character
|
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
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 |
---|
MultiEdit()
Constructs a MultiEdit with 1 pixel as space between lines and with no lines.
|
MultiEdit(int rowCount,
int spaceBetweenLines)
Constructor for a text Edit with a vertical scroll Bar, gap is 1
by default and control's bounds must be specified with a setRect.
|
MultiEdit(java.lang.String mask,
int rowCount,
int spaceBetweenLines)
Constructor for a text Edit with a vertical scroll Bar, gap is 1
by default and control's bounds must be given with a setRect.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canScrollContent(int direction,
java.lang.Object target)
Checks if there is room to flick this container in the given direction.
|
void |
clear()
Clears the text of this control.
|
void |
cutText(int sel1,
int sel2)
Cuts the text on the given range.
|
protected void |
draw(Graphics g) |
void |
flickEnded(boolean atPenDown)
Called when the flick animation is ended.
|
boolean |
flickStarted()
Called when the flick animation is started.
|
MultiEdit |
getCopy()
Returns a copy of this Edit with almost all features.
|
int[] |
getCursorPos()
Returns an array with the cursor positions.
|
Flick |
getFlick()
Returns the current flick object.
|
void |
getFocusableControls(Vector v)
Get a list of child controls of this container which are focus candidates
|
byte |
getKeyboardType()
Returns the keyboard type of this Edit control.
|
int |
getLength()
Returns the length of the text.
|
int |
getMaxLength() |
int |
getNumberOfTextLines()
Gets total number of lines in the text
|
int |
getPreferredHeight()
Returns the preferred height of this control.
|
int |
getPreferredWidth()
Returns the preferred width of this control.
|
int |
getScrollPosition(int direction)
Returns the current position given the direction.
|
java.lang.String |
getText()
Returns the text displayed in the edit control.
|
java.lang.StringBuffer |
getTextBuffer()
Returns the text's buffer.
|
java.lang.String |
getValue() |
Control |
handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on
the KeyEvent.
|
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)
Draws the border (if any).
|
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 |
requestFocus()
Sets the focus to this control.
|
boolean |
scrollContent(int xDelta,
int yDelta,
boolean fromFlick)
Performs a relative move.
|
void |
scrollToBottom()
Scrolls the text to bottom.
|
void |
scrollToLine(int line)
Scrolls the text to the given line.
|
void |
scrollToTop()
Scrolls the tex to the top.
|
void |
setCursorPos(int pos)
Sets the cursor position, ranging from 0 to the text' length.
|
void |
setCursorPos(int start,
int end)
Sets the selected text of this Edit (if start != end).
|
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 |
setRect(int x,
int y,
int width,
int height,
Control relative,
boolean screenChanged)
Sets the rect for this MultiEdit.
|
void |
setScrollbarsAlwaysVisible(boolean asNeeded)
Set to true to hide the vertical scrollbar when it isn't needed (instead of disabling it).
|
void |
setText(java.lang.String s)
Sets the text displayed in the edit control.
|
void |
setText(java.lang.String s,
boolean postPressed)
Sets the text displayed in the edit control.
|
void |
setTextGap(int leftTextGap,
int rightTextGap,
int topTextGap,
int bottomTextGap)
Sets the gap between the contents and the borders of the MultiEdit.
|
void |
setValidChars(java.lang.String validCharsString)
sets the valid chars that can be entered in this edit.
|
void |
setValue(java.lang.String value) |
boolean |
wasScrolled()
Returns true if the control was scrolled since last pen down
|
protected boolean |
willOpenKeyboard()
Returns true if this is a MultiEdit or an Edit that has a standard keyboard.
|
add, add, add, add, add, broadcastEvent, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_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, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary
protected boolean hasFocus
protected boolean editable
public static boolean hasCursorWhenNotEditable
protected boolean improvedGeographicalFocus
public int lastInsertPos
public CaptionPress captionPress
protected IntVector first
protected java.lang.StringBuffer chars
protected ScrollBar sb
public java.lang.String mask
public int rowCount
public byte capitalise
Edit.ALL_NORMAL
,
Edit.ALL_UPPER
,
Edit.ALL_LOWER
public boolean autoSelect
public boolean drawDots
public int gap
public boolean justify
public java.lang.String caption
captionColor
public int captionColor
public Image captionIcon
protected Flick flick
public boolean selectLast
public boolean persistentSelection
public MultiEdit()
public MultiEdit(int rowCount, int spaceBetweenLines)
public MultiEdit(java.lang.String mask, int rowCount, int spaceBetweenLines)
public boolean flickStarted()
Scrollable
flickStarted
in interface Scrollable
public void flickEnded(boolean atPenDown)
Scrollable
flickEnded
in interface Scrollable
atPenDown
- Flag indicating if the animation ended due to a pendown event.public boolean canScrollContent(int direction, java.lang.Object target)
Scrollable
canScrollContent
in interface Scrollable
direction
- The direction we want to flick given by one of the following constants:target
- The target of the series of PEN events that triggered this flick attempt.public boolean scrollContent(int xDelta, int yDelta, boolean fromFlick)
Scrollable
scrollContent
in interface Scrollable
xDelta
- The relative amount of pixels to move in the X axis.yDelta
- The relative amount of pixels to move in the Y axis.public int getScrollPosition(int direction)
Scrollable
getScrollPosition
in interface Scrollable
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 int getPreferredHeight()
Control
getPreferredHeight
in class Control
public int getPreferredWidth()
Control
getPreferredWidth
in class Control
public void setMaxLength(int length)
public int getMaxLength()
public void setKeyboard(byte kbd)
public void setValidChars(java.lang.String validCharsString)
public java.lang.String getText()
getText
in interface TextControl
public java.lang.StringBuffer getTextBuffer()
public void setText(java.lang.String s)
setText
in interface TextControl
public void setText(java.lang.String s, boolean postPressed)
public void setEditable(boolean on)
public boolean isEditable()
public int getNumberOfTextLines()
public void setScrollbarsAlwaysVisible(boolean asNeeded)
public void popupKCC()
protected void onBoundsChanged(boolean screenChanged)
Control
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public void onEvent(Event event)
public void cutText(int sel1, int sel2)
protected void draw(Graphics g)
protected void onWindowPaintFinished()
Control
onWindowPaintFinished
in class Control
public void onPaint(Graphics g)
Container
super.onPaint(g);
, or the border will not be drawn.protected void pushPosState()
protected void popPosState()
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Container
public void setRect(int x, int y, int width, int height, Control relative, boolean screenChanged)
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)
protected void onFontChanged()
Control
onFontChanged
in class Control
public void getFocusableControls(Vector v)
Container
getFocusableControls
in class Container
v
- A vector into which to add the focus candidates.public void scrollToLine(int line)
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Control
handleGeographicalFocusChangeKeys
in class Control
ke
- The KeyEvent to be processedSettings.geographicalFocus
public void scrollToBottom()
public void scrollToTop()
public int getLength()
public void requestFocus()
Control
isHighlighting = false
.requestFocus
in class Control
public byte getKeyboardType()
Edit.KBD_NONE
,
Edit.KBD_DEFAULT
,
Edit.KBD_KEYBOARD
,
Edit.KBD_CALCULATOR
,
Edit.KBD_CALCULATOR
public MultiEdit getCopy()
public Flick getFlick()
Scrollable
getFlick
in interface Scrollable
public boolean wasScrolled()
Scrollable
wasScrolled
in interface Scrollable
protected boolean willOpenKeyboard()
Control
willOpenKeyboard
in class Control
public void setCursorPos(int pos)
lastInsertPos
to recover cursor position.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 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 java.lang.String getValue()
public void setValue(java.lang.String value)
public void setTextGap(int leftTextGap, int rightTextGap, int topTextGap, int bottomTextGap)