Class TouchSelection

java.lang.Object
com.codename1.ui.editor.TouchSelection

public final class TouchSelection extends Object

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 Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    What the chrome needs from the editor it decorates.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Toolbar action: copy the selection.
    static final int
    Toolbar action: cut the selection.
    static final int
    press grabbed the handle at the end of the selection.
    static final int
    press hit nothing; the chrome was dismissed.
    static final int
    Toolbar action: paste over the selection.
    static final int
    Toolbar action: select everything.
    static final int
    press grabbed the handle at the start of the selection.
    static final int
    press hit a toolbar button, whose action the host has already run.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the chrome for an editor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether the chrome is showing.
    void
    Paints the handles and the toolbar when shown.
    int
    press(Component owner, int x, int y)
    Hit tests a press.
    void
    setShown(boolean value)
    Shows or dismisses the chrome.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MISSED

      public static final int MISSED
      press hit nothing; the chrome was dismissed.
      See Also:
    • TOOLBAR

      public static final int TOOLBAR
      press hit a toolbar button, whose action the host has already run.
      See Also:
    • START_HANDLE

      public static final int START_HANDLE
      press grabbed the handle at the start of the selection.
      See Also:
    • END_HANDLE

      public static final int END_HANDLE
      press grabbed the handle at the end of the selection.
      See Also:
    • COPY

      public static final int COPY
      Toolbar action: copy the selection.
      See Also:
    • CUT

      public static final int CUT
      Toolbar action: cut the selection.
      See Also:
    • PASTE

      public static final int PASTE
      Toolbar action: paste over the selection.
      See Also:
    • SELECT_ALL

      public static final int SELECT_ALL
      Toolbar action: select everything.
      See Also:
  • Constructor Details

    • TouchSelection

      public TouchSelection(TouchSelection.Host host)

      Creates the chrome for an editor.

      Parameters
      • 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
      • value: 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
      • g: the graphics

      • owner: 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
      • owner: the editor

      • x: the absolute x

      • y: the absolute y

      Returns

      MISSED, TOOLBAR, START_HANDLE or END_HANDLE