Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class TouchSelection
- Object
- TouchSelection
The touch selection chrome a text editor shows after a long press: a draggable handle at each end of the selection and a context toolbar with Copy, Cut, Paste and Select All.
The editor keeps the selection; this class only paints the chrome and says what a press
landed on. EditorView and the word processing DocumentView share it, so both editors
look and behave the same under a finger.
The host shows the chrome with setShown(true) after a long press selects a word, calls
paint after painting its content while a selection exists, and hands every press to
press before handling it itself.
Nested types
interface TouchSelection.Host | What the chrome needs from the editor it decorates. |
Fields
public static final int MISSED = 0 | press hit nothing; the chrome was dismissed. |
public static final int TOOLBAR = 1 | press hit a toolbar button, whose action the host has already run. |
public static final int START_HANDLE = 2 | press grabbed the handle at the start of the selection. |
public static final int END_HANDLE = 3 | press grabbed the handle at the end of the selection. |
public static final int COPY = 0 | Toolbar action: copy the selection. |
public static final int CUT = 1 | Toolbar action: cut the selection. |
public static final int PASTE = 2 | Toolbar action: paste over the selection. |
public static final int SELECT_ALL = 3 | Toolbar action: select everything. |
Constructors
public TouchSelection(TouchSelection.Host host) | Creates the chrome for an editor. |
Methods
public boolean isShown() | Whether the chrome is showing. |
public void setShown(boolean value) | Shows or dismisses the chrome. |
public void paint(Graphics g, Component owner) | Paints the handles and the toolbar when shown. |
public int press(Component owner, int x, int y) | Hit tests a press. |
Inherited methods
Field details
MISSED
public static final int MISSED = 0press hit nothing; the chrome was dismissed.TOOLBAR
public static final int TOOLBAR = 1press hit a toolbar button, whose action the host has already run.START_HANDLE
public static final int START_HANDLE = 2press grabbed the handle at the start of the selection.END_HANDLE
public static final int END_HANDLE = 3press grabbed the handle at the end of the selection.COPY
public static final int COPY = 0Toolbar action: copy the selection.
CUT
public static final int CUT = 1Toolbar action: cut the selection.
PASTE
public static final int PASTE = 2Toolbar action: paste over the selection.
SELECT_ALL
public static final int SELECT_ALL = 3Toolbar action: select everything.
Constructor details
TouchSelection
public TouchSelection(TouchSelection.Host host)Creates the chrome for an editor.
Parameters
hostTouchSelection.Host- the editor
Method details
isShown
public boolean isShown()Whether the chrome is showing.
Returns
true while shown
setShown
public void setShown(boolean value)Shows or dismisses the chrome.
Parameters
valueboolean- true to show it
paint
public void paint(Graphics g, Component owner)Paints the handles and the toolbar when shown. Call after painting the content, and only
while there is a selection.
Parameters
gGraphics- the graphics
ownerComponent- the editor, whose position the coordinates are relative to
press
public int press(Component owner, int x, int y)Hit tests a press. A toolbar press runs its action; a press on neither handle nor
toolbar dismisses the chrome.
Parameters
ownerComponent- the editor
xint- the absolute x
yint- the absolute y
Returns
MISSED, TOOLBAR, START_HANDLE or END_HANDLE