Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class DocumentView

  1. Object
  2. Component
  3. ScrollSurface
  4. DocumentView

ImplementsAnimation, Editable, StyleListener, TextInputClient, TextInputClient.CompositionCancellation, TextInputGeometry.Provider

Shows a document as pages and edits it, the way DataGrid shows and edits a Sheet.

DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
DocumentView view = new DocumentView(model);
Form form = new Form("Document", new BorderLayout());
form.add(BorderLayout.CENTER, view);
form.show();

The view subscribes to its model while it is on a form and lays the document out again on every change, so anything that edits the model – the view itself, a toolbar, an undo button – is shown at once. Pages are laid out by DocumentLayout with the view’s Measurer (ScreenMeasurer by default, the fonts the view draws in). Set a PdfMeasurer to break pages exactly where the PDF export does, at the cost of spacing set by the PDF’s fonts.

A tap places the caret, a drag or a double tap selects, and typing, Backspace, Delete and Enter edit through the model, which gives undo for free. Pinch or Control and the wheel zooms; by default a page is fitted to the view’s width when it would not fit.

Constructors

public DocumentView()A view of an empty document.
public DocumentView(Document doc)A view of a document, in a model of its own.
public DocumentView(DocumentModel model)A view of a model.

Methods

public DocumentModel getModel()The model shown.
public final void setModel(DocumentModel value)Shows another model.
public Document getDocument()The document shown; a shortcut for getModel().getDocument().
public void setDocument(Document doc)Replaces the document, forgetting the undo history; a shortcut for getModel().reset(doc).
public void setMeasurer(Measurer value)Sets the measurer pages are laid out with, for instance a PdfMeasurer with TrueType fonts registered for a script the standard fonts lack.
public Measurer getMeasurer()The measurer pages are laid out with.
public DocumentLayout getLayout()The current layout.
public boolean isEditable()Whether the user may edit the document.
public void setEditable(boolean value)Lets the user edit the document, or only read and select it.
public float getZoom()The zoom factor on top of the fitted or natural size.
public void setZoom(float value)Sets the zoom factor on top of the fitted or natural size.
public boolean isFitWidth()Whether a page wider than the view is shrunk to fit its width.
public void setFitWidth(boolean value)Shrinks pages wider than the view to its width, or shows them at their natural size.
public TextPosition getCaret()The caret, or null when there is none.
public void setCaret(TextPosition value)Places the caret and clears the selection.
public void setSelection(TextPosition from, TextPosition to)Selects the text between two positions; equal positions place the caret.
public TextPosition[] getSelection()The selection, earlier end first, or null when nothing is selected.
public void addCaretListener(ActionListener l)Adds a listener told when the caret or the selection moves, for a toolbar showing the style at the caret.
public void removeCaretListener(ActionListener l)Removes a caret listener.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public float getScale()Pixels per point at the current size.
protected void scrollChanged()The scroll position changed.
public int[] itemBounds(int page, LayoutItem item)Where a laid out item is, in the view’s own coordinates at the current scroll.
protected void layoutSurface(int width, int height)Lays the surface out for a size: sets the header sizes and whatever the content’s size depends on.
protected int getContentWidth()The width of what scrolls, in pixels, without the left header.
protected int getContentHeight()The height of what scrolls, in pixels, without the top header.
protected boolean zoomBy(float factor, int x, int y)Zooms by factor around a point, for a pinch or Control/Command and the wheel.
public void setProofreader(Proofreader p)Underlines spelling and grammar problems with a wavy line, red for spelling and blue for grammar.
public Proofreader getProofreader()The proofreader underlining problems.
public ProofIssue proofIssueAt(TextPosition at, int max)The problem under a text position, with spelling suggestions, for a menu of fixes.
public void applySuggestion(String paragraphId, ProofIssue issue, String replacement)Replaces the range of a problem with one of its suggestions, as one undoable edit.
protected void paintContent(Graphics g, int x, int y)Paints what scrolls.
protected void paintComponentBox(Graphics g, LayoutItem item, int x, int y, int w, int h)Paints an embedded component’s box: its snapshot, or a frame naming its type.
public List<Comment> getCommentsAtCaret()The review comments over the caret.
public Comment commentSelection(String text)Adds a review comment over the selection, by the model’s author.
protected Font font(TextStyle style, int px)The platform font text of a style is drawn in, at a pixel size.
public TextPosition positionAt(int x, int y)The text position under a point in the view.
protected void tapped(int x, int y, boolean doubleTap)A tap that was not a drag or a long press.
protected boolean editStarted(int x, int y, ScrollSurface.EditTrigger trigger)Asked when a drag or a long press begins, at the point where the pointer went down, in the component’s coordinates.
protected void editMoved(int x, int y)The pointer of an edit moved, or the surface scrolled under it.
protected void editEnded(boolean committed)The edit is over.
protected boolean animateSurface()Advances the view’s own motion.
protected void focusGained()Callback allowing a developer to track when the component gains focus
protected void focusLost()Callback allowing a developer to track wheh the component loses focus
public void paint(Graphics g)Paints the view, then the touch selection handles and toolbar over it.
public void copySelection()Copies the selection to the clipboard as plain text, HTML, RTF and Markdown, so it pastes with its formatting into a word processor, a browser or a text editor alike.
public void cutSelection()Copies the selection to the clipboard and deletes it.
public void pasteClipboard()Pastes the clipboard over the selection, keeping formatting when the clipboard holds HTML, RTF or Markdown.
public void selectAll()Selects the whole document.
public void typeText(String text)Types text at the caret, replacing the selection.
public void deleteBackward()Deletes the selection, or the character before the caret, joining paragraphs at a paragraph start.
public void deleteForward()Deletes the selection, or the character after the caret.
public void moveCaret(boolean forward, boolean extend)Moves the caret one character, or extends the selection when extend is true.
public void moveCaretLine(boolean down, boolean extend)Moves the caret a line up or down, or extends the selection.
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
public void commitText(String text)Typed text from the platform’s keyboard or input method.
public void setComposingText(String text, int relativeCaret)Composition is committed whole: the composing text is typed as it is.
public void finishComposing()Nothing to do: composing text is never shown before it is committed.
public void deleteSurroundingText(int before, int after)Deletes around the caret, within its paragraph.
public void onKeyCommand(int command, int modifiers)A key command from the platform.
public void onEditorAction(int action)The Enter action splits the paragraph.
public TextInputState getEditingState()The caret’s paragraph, as the platform sees the text being edited.
public int[] getCaretRect()The caret rectangle in screen coordinates.
public TextInputConfig getConfig()Multi-line text with autocorrect.
public void inputFocusGained()Nothing to do.
public void inputFocusLost()The platform let go of input.
public void cancelComposing()Nothing to undo: composing text is never inserted before it is committed.
public TextInputGeometry getGeometrySnapshot()The caret and selection rectangles the platform places its candidate window by.
public int getTextLength()The length of the caret’s paragraph.
public String getTextRange(int start, int end)Part of the caret’s paragraph.
public int[] rectForOffset(int offset)Where an offset of the caret’s paragraph is on screen.
public int offsetAtPoint(int x, int y)The offset in the caret’s paragraph nearest a screen point.
public int[] selectionRects(int start, int end)The selection rectangles of a range of the caret’s paragraph.
public void replaceRange(int start, int end, String text)Replaces part of the caret’s paragraph.
public void setSelectionRange(int start, int end)Selects part of the caret’s paragraph.

Inherited nested types

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

DocumentView

public DocumentView()
A view of an empty document.

DocumentView

public DocumentView(Document doc)
A view of a document, in a model of its own.

Parameters

doc Document
the document

DocumentView

public DocumentView(DocumentModel model)
A view of a model.

Parameters

model DocumentModel
the model

Method details

getModel

public DocumentModel getModel()
The model shown.

Returns

the model

setModel

public final void setModel(DocumentModel value)
Shows another model.

Parameters

value DocumentModel
the model

getDocument

public Document getDocument()
The document shown; a shortcut for getModel().getDocument().

Returns

the document

setDocument

public void setDocument(Document doc)
Replaces the document, forgetting the undo history; a shortcut for getModel().reset(doc).

Parameters

doc Document
the document

setMeasurer

public void setMeasurer(Measurer value)
Sets the measurer pages are laid out with, for instance a PdfMeasurer with TrueType fonts registered for a script the standard fonts lack.

Parameters

value Measurer
the measurer

getMeasurer

public Measurer getMeasurer()
The measurer pages are laid out with.

Returns

the measurer

getLayout

public DocumentLayout getLayout()
The current layout.

Returns

the layout of the model’s document

isEditable

public boolean isEditable()
Whether the user may edit the document.

Returns

true by default

setEditable

public void setEditable(boolean value)
Lets the user edit the document, or only read and select it.

Parameters

value boolean
true to allow editing

getZoom

public float getZoom()
The zoom factor on top of the fitted or natural size.

Returns

the factor, 1 by default

setZoom

public void setZoom(float value)
Sets the zoom factor on top of the fitted or natural size.

Parameters

value float
between 0.25 and 6

isFitWidth

public boolean isFitWidth()
Whether a page wider than the view is shrunk to fit its width.

Returns

true by default

setFitWidth

public void setFitWidth(boolean value)
Shrinks pages wider than the view to its width, or shows them at their natural size.

Parameters

value boolean
true to fit

getCaret

public TextPosition getCaret()
The caret, or null when there is none.

Returns

the caret position

setCaret

public void setCaret(TextPosition value)
Places the caret and clears the selection.

Parameters

value TextPosition
the position, or null to remove the caret

setSelection

public void setSelection(TextPosition from, TextPosition to)
Selects the text between two positions; equal positions place the caret.

Parameters

from TextPosition
where the selection is anchored
to TextPosition
where the caret is

getSelection

public TextPosition[] getSelection()
The selection, earlier end first, or null when nothing is selected.

Returns

the two ends, or null

addCaretListener

public void addCaretListener(ActionListener l)
Adds a listener told when the caret or the selection moves, for a toolbar showing the style at the caret.

Parameters

l ActionListener
the listener

removeCaretListener

public void removeCaretListener(ActionListener l)
Removes a caret listener.

Parameters

l ActionListener
the listener

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

getScale

public float getScale()
Pixels per point at the current size.

Returns

the scale

scrollChanged

protected void scrollChanged()
The scroll position changed.

itemBounds

public int[] itemBounds(int page, LayoutItem item)
Where a laid out item is, in the view’s own coordinates at the current scroll.

Parameters

page int
the item’s page
item LayoutItem
the item

Returns

{x, y, width, height} in pixels

layoutSurface

protected void layoutSurface(int width, int height)
Lays the surface out for a size: sets the header sizes and whatever the content’s size depends on. Called before every paint and every pointer event, so it has to return at once when nothing has changed.

getContentWidth

protected int getContentWidth()
The width of what scrolls, in pixels, without the left header.

getContentHeight

protected int getContentHeight()
The height of what scrolls, in pixels, without the top header.

zoomBy

protected boolean zoomBy(float factor, int x, int y)
Zooms by factor around a point, for a pinch or Control/Command and the wheel.

Returns

false when the surface has no zoom, so the gesture is left alone

setProofreader

public void setProofreader(Proofreader p)
Underlines spelling and grammar problems with a wavy line, red for spelling and blue for grammar.

Parameters

p Proofreader
the proofreader, or null to stop

getProofreader

public Proofreader getProofreader()
The proofreader underlining problems.

Returns

the proofreader, or null

proofIssueAt

public ProofIssue proofIssueAt(TextPosition at, int max)
The problem under a text position, with spelling suggestions, for a menu of fixes.

Parameters

at TextPosition
the position
max int
the most suggestions

Returns

the issue, or null when there is none or no proofreader

applySuggestion

public void applySuggestion(String paragraphId, ProofIssue issue, String replacement)
Replaces the range of a problem with one of its suggestions, as one undoable edit.

Parameters

paragraphId String
the paragraph the issue was found in
issue ProofIssue
the issue
replacement String
the text to put in its place

paintContent

protected void paintContent(Graphics g, int x, int y)
Paints what scrolls. x and y are where the content’s own origin is on screen, which is off screen once it has scrolled. The graphics is clipped to the content region.

paintComponentBox

protected void paintComponentBox(Graphics g, LayoutItem item, int x, int y, int w, int h)
Paints an embedded component’s box: its snapshot, or a frame naming its type. A subclass that hosts live components paints them here.

Parameters

g Graphics
the graphics
item LayoutItem
the laid out component
x int
the box’s left edge in pixels
y int
its top edge
w int
its width
h int
its height

getCommentsAtCaret

public List<Comment> getCommentsAtCaret()
The review comments over the caret.

Returns

the comments, empty when there is no caret

commentSelection

public Comment commentSelection(String text)
Adds a review comment over the selection, by the model’s author.

Parameters

text String
the comment

Returns

the comment, or null when nothing is selected

font

protected Font font(TextStyle style, int px)
The platform font text of a style is drawn in, at a pixel size.

Parameters

style TextStyle
the style
px int
the size in pixels

Returns

the font

positionAt

public TextPosition positionAt(int x, int y)
The text position under a point in the view.

Parameters

x int
in the component’s coordinates
y int
in the component’s coordinates

Returns

the position, or null

tapped

protected void tapped(int x, int y, boolean doubleTap)
A tap that was not a drag or a long press.

editStarted

protected boolean editStarted(int x, int y, ScrollSurface.EditTrigger trigger)
Asked when a drag or a long press begins, at the point where the pointer went down, in the component’s coordinates.

Parameters

x int
Not documented.
y int
Not documented.
trigger ScrollSurface.EditTrigger
what kind of gesture it is

Returns

true when an edit has begun and the drag belongs to it; false to pan

editMoved

protected void editMoved(int x, int y)
The pointer of an edit moved, or the surface scrolled under it.

editEnded

protected void editEnded(boolean committed)
The edit is over. committed is false when it was cancelled: by cancelEdit, a second finger, or the surface leaving the form.

animateSurface

protected boolean animateSurface()
Advances the view’s own motion. Called every frame while the surface animates; call requestAnimation to start the frames.

Returns

true while the view still has something moving

focusGained

protected void focusGained()
Callback allowing a developer to track when the component gains focus

focusLost

protected void focusLost()
Callback allowing a developer to track wheh the component loses focus

paint

public void paint(Graphics g)
Paints the view, then the touch selection handles and toolbar over it.

Parameters

g Graphics
the graphics

copySelection

public void copySelection()
Copies the selection to the clipboard as plain text, HTML, RTF and Markdown, so it pastes with its formatting into a word processor, a browser or a text editor alike.

cutSelection

public void cutSelection()
Copies the selection to the clipboard and deletes it.

pasteClipboard

public void pasteClipboard()
Pastes the clipboard over the selection, keeping formatting when the clipboard holds HTML, RTF or Markdown.

selectAll

public void selectAll()
Selects the whole document.

typeText

public void typeText(String text)
Types text at the caret, replacing the selection.

Parameters

text String
the text; a line break splits the paragraph

deleteBackward

public void deleteBackward()
Deletes the selection, or the character before the caret, joining paragraphs at a paragraph start.

deleteForward

public void deleteForward()
Deletes the selection, or the character after the caret.

moveCaret

public void moveCaret(boolean forward, boolean extend)
Moves the caret one character, or extends the selection when extend is true.

Parameters

forward boolean
true to move right
extend boolean
true to keep the selection anchor

moveCaretLine

public void moveCaretLine(boolean down, boolean extend)
Moves the caret a line up or down, or extends the selection.

Parameters

down boolean
true to move down
extend boolean
true to keep the selection anchor

keyPressed

public void keyPressed(int keyCode)
If this Component is focused, the key pressed event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

commitText

public void commitText(String text)
Typed text from the platform’s keyboard or input method.

Parameters

text String
the text

setComposingText

public void setComposingText(String text, int relativeCaret)
Composition is committed whole: the composing text is typed as it is.

Parameters

text String
the composing text
relativeCaret int
ignored

finishComposing

public void finishComposing()
Nothing to do: composing text is never shown before it is committed.

deleteSurroundingText

public void deleteSurroundingText(int before, int after)
Deletes around the caret, within its paragraph.

Parameters

before int
characters before the caret
after int
characters after it

onKeyCommand

public void onKeyCommand(int command, int modifiers)
A key command from the platform.

Parameters

command int
one of the TextInputClient commands
modifiers int
modifier bits

onEditorAction

public void onEditorAction(int action)
The Enter action splits the paragraph.

Parameters

action int
the action

getEditingState

public TextInputState getEditingState()
The caret’s paragraph, as the platform sees the text being edited.

Returns

the state

getCaretRect

public int[] getCaretRect()
The caret rectangle in screen coordinates.

Returns

{x, y, width, height}

getConfig

public TextInputConfig getConfig()
Multi-line text with autocorrect.

Returns

the configuration

inputFocusGained

public void inputFocusGained()
Nothing to do.

inputFocusLost

public void inputFocusLost()
The platform let go of input.

cancelComposing

public void cancelComposing()
Nothing to undo: composing text is never inserted before it is committed.

getGeometrySnapshot

public TextInputGeometry getGeometrySnapshot()
The caret and selection rectangles the platform places its candidate window by.

Returns

the snapshot

getTextLength

public int getTextLength()
The length of the caret’s paragraph.

Returns

the length

getTextRange

public String getTextRange(int start, int end)
Part of the caret’s paragraph.

Parameters

start int
from
end int
to

Returns

the text

rectForOffset

public int[] rectForOffset(int offset)
Where an offset of the caret’s paragraph is on screen.

Parameters

offset int
the offset

Returns

{x, y, width, height} in screen coordinates

offsetAtPoint

public int offsetAtPoint(int x, int y)
The offset in the caret’s paragraph nearest a screen point.

Parameters

x int
screen x
y int
screen y

Returns

the offset

selectionRects

public int[] selectionRects(int start, int end)
The selection rectangles of a range of the caret’s paragraph.

Parameters

start int
from
end int
to

Returns

the rectangle from the start’s caret to the end’s, as {x, y, w, h}

replaceRange

public void replaceRange(int start, int end, String text)
Replaces part of the caret’s paragraph.

Parameters

start int
from
end int
to
text String
the replacement

setSelectionRange

public void setSelectionRange(int start, int end)
Selects part of the caret’s paragraph.

Parameters

start int
the anchor
end int
the caret