public class EditorView

  1. Object
  2. Component
  3. EditorView

ImplementsAnimation, Editable, StyleListener, TextInputClient

Known subtypesEditField, CodeView, RichView

The pure Codename One text editing surface. It renders a plain text EditorDocument with its own Graphics code, owns the caret and selection, handles pointer and keyboard interaction, and captures text through the low level TextInputClient contract (soft keyboard / IME) when the platform supports it, falling back to raw keyPressed capture on physical keyboard platforms.

This class provides the shared editing behavior. Feature layers (syntax highlighting, the gutter, styled rich text) subclass it and override #paintContent(Graphics, int, int, int, int) and the document/measurement hooks.

Constructors

public EditorView(EditorHost host, boolean codeMode)Creates an editor view.

Methods

protected void scrollByPixels(int deltaX, int deltaY)Scrolls the content by the given pixel deltas (as delivered by the mouse wheel gesture).
protected final void setEditorHost(EditorHost h)Binds the editor host after construction.
public EditorDocument getDocument()Returns the backing document.
public UndoManager getUndoManager()Returns the undo manager.
public int getCaretOffset()Returns the current caret offset.
public void setBackgroundColor(int color)Sets the surface background color.
public void setTextColor(int color)Sets the default text color.
public void setSelectionColor(int color)Sets the selection highlight color.
protected int getTextColor()Returns the default text color used by the base renderer.
public void setText(String text)Replaces the whole document text and resets the caret and history.
public String getText()Returns the whole document text.
public void setEditableState(boolean editable)Enables or disables editing.
public boolean isEditableState()True when editing is enabled.
public void blur()Relinquishes focus and stops the active platform text-input session.
protected int baseFontSizePixels()Returns the base editor font size in pixels.
public void setFontSizeDips(int dips)Optionally overrides the editor font size in device independent pixels.
protected Font getEditorFont()Returns the font used to render text.
protected int getLineHeight()Returns the default height of a single visual line in pixels.
protected int lineHeightAt(int line)Returns the height of the given line.
protected boolean uniformLineHeight()True when every line has the same height (the common case, and the fast path).
protected void invalidateLayout()Invalidates the cached line layout (used by feature layers when line heights change).
protected int lineTopContent(int line)Returns the top y pixel of the given line relative to the content top (before scroll).
protected int contentTotalHeight()Returns the total content height in pixels.
protected int lineAtContentY(int y)Returns the line index at the given content relative y pixel.
protected int getContentLeftInset()Returns the left inset (padding plus any gutter) at which text starts.
protected int contentWidth()Returns the width available for text (component width minus padding and any gutter).
public boolean hasSelection()True when a non empty selection exists.
public int getSelectionStart()Returns the inclusive start offset of the selection (or the caret when none).
public int getSelectionEnd()Returns the exclusive end offset of the selection (or the caret when none).
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.
public void longPointerPress(int x, int y)If this Component is focused this method is invoked when the user presses and holds the pointer on the Component
protected void paintContent(Graphics g, int originX, int originY, int width, int height)Paints the document content.
protected void paintComposingUnderline(Graphics g, int line, String text, int lineStart, int lineEnd, int tx, int ly, int lineHeight, Font f)Draws the IME composition (marked text) underline for the portion of the active composing range that falls on the given line.
protected void paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f)Hook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter.
protected void paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)Hook invoked after a line’s text is drawn, used by the code editor to paint diagnostic squiggles.
protected int lineTop(int line)Returns the y pixel of the top of the given line in component local coordinates (scroll adjusted).
protected int firstVisibleLine()Returns the first fully or partially visible line index.
protected int getHorizontalScroll()Returns the current horizontal scroll offset in pixels.
protected int getVerticalScroll()Returns the current vertical scroll offset in pixels.
protected int getMaximumVerticalScroll()Returns the largest valid vertical content offset.
protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)Paints a single line of text.
public int offsetAtPoint(int absX, int absY)Returns the document offset nearest the given absolute screen point.
protected boolean consumesRawTextInput()This view edits text, so key codes reaching it are characters rather than commands.
protected boolean isEditAllowed(int start, int end)Whether the given range may be modified.
protected void replaceRange(int start, int end, String text, boolean record)Replaces the range [start, end) with text, updating the caret, history and platform input state.
protected void documentEdited(int fromOffset)Hook invoked when the document is mutated at fromOffset, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.
protected void documentReplaced(int start, String removed, String inserted)Hook invoked when a range is replaced, carrying the exact removed and inserted text so feature layers (e.g. the rich text editor) can keep a parallel style / block model in sync.
protected void documentReset()Hook invoked when the whole document is reset (e.g. by #setText(String)), so feature layers can rebuild their parallel models.
protected Object captureDocumentState()Captures feature-layer state associated with the document for undo/redo.
protected void restoreDocumentState(Object state)Restores a feature-layer snapshot captured by #captureDocumentState().
protected final void refreshUndoAfterState()Refreshes the most recent undo unit after a feature layer finishes decorating an inserted range.
public void insertText(String text)Inserts text at the caret, replacing any active selection.
protected boolean handleTypedText(String text)Hook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent).
protected void handleTab(boolean dedent)Handles a tab key press (delivered as #KEY_TAB).
protected EditorHost host()Returns the host bridge, for feature layers that need to fire editor events.
public void deleteBackward()Deletes the selection, or the character before the caret when there is none.
public void moveCaret(int newCaret, boolean extend)Moves the caret to a new offset, optionally extending the selection.
public void selectAll()Selects the entire document.
public void copySelection()Copies the selection to the clipboard.
public void cutSelection()Cuts the selection to the clipboard.
public void pasteClipboard()Inserts the clipboard contents at the caret.
protected void pasteClipboardData(Object data)Inserts clipboard data.
protected int lineContentOffsetX(int line)Returns the extra left offset of a line’s text within the content area (0 for plain text and code; the rich text editor overrides this for list bullets, indentation, block quotes and alignment so the caret and selection line up with the drawn text).
protected int measureColumnX(int line, String text, int col, Font f)Returns the visual pixel x (from the start of a line) of the caret before logical column col.
protected int columnAtX(int line, String text, int localX, Font f)Returns the column nearest a given content-local x pixel on a line.
protected int[] lineVisualSegments(int line, String text, int from, int to, Font f)Returns the visual selection segments for the logical range [from, to) on a line as a flat array of {x, width, x, width, ...} in content-local pixels.
protected void laidOut()This is a callback method to inform the Component when it’s been laidout on the parent Container
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
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
public void keyRepeated(int keyCode)If this Component is focused, the key repeat event will call this method.
public void keyReleased(int keyCode)If this Component is focused, the key released event will call this method
public void commitText(String text)Commits final text at the caret, replacing the active selection.
public void setComposingText(String text, int relativeCaret)Updates the in progress IME composition (marked text) at the caret.
public void finishComposing()Finalizes any active IME composition, committing the current marked text.
public void deleteSurroundingText(int before, int after)Deletes text around the caret, the primary deletion path used by soft keyboards.
public void onKeyCommand(int command, int modifiers)Delivers a non text key command (navigation, deletion, clipboard, undo).
public void performUndo()Undoes the last edit.
public void performRedo()Redoes the last undone edit.
public void onEditorAction(int action)Delivers the keyboard return key action (done / next / search / send) configured through TextInputConfig.
public TextInputState getEditingState()Returns the current editing state (surrounding text, selection and composition) so the platform can seed autocorrect and prediction.
public int[] getCaretRect()Returns the caret rectangle in absolute screen pixels {x, y, width, height}, used by the platform to anchor the IME candidate window and the selection loupe near the rendered caret.
public int[] rectForOffset(int offset)Returns the caret rectangle for an arbitrary offset in absolute screen pixels {x, y, w, h}.
public int getTextLength()Returns the total number of UTF-16 characters in the document.
public String getTextRange(int start, int end)Returns the text in [start, end).
public int[] selectionRects(int start, int end)Returns the selection rectangles covering [start, end) as a flat array of absolute-pixel rectangles {x, y, w, h, x, y, w, h, ...} (one entry per visual line the range spans).
public void replaceRange(int start, int end, String text)Replaces the range [start, end) with text (a direct, range based edit from the platform).
public void setSelectionRange(int start, int end)Sets the selection to [start, end) (a caret when equal).
public TextInputConfig getConfig()Returns the configuration describing the desired keyboard type and input behavior.
public void inputFocusGained()Notifies the client that it gained the platform input focus (became first responder).
public void inputFocusLost()Notifies the client that it lost the platform input focus.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.

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, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, 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, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, 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, isEditable, initComponent, 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, shouldBlockSideSwipe, 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

EditorView

public EditorView(EditorHost host, boolean codeMode)
Creates an editor view.

Parameters

host EditorHost
the bridge to the owning editor component / platform input source
codeMode boolean
true for a code editor (autocorrect and autocapitalize disabled)

Method details

scrollByPixels

protected void scrollByPixels(int deltaX, int deltaY)
Scrolls the content by the given pixel deltas (as delivered by the mouse wheel gesture).

setEditorHost

protected final void setEditorHost(EditorHost h)
Binds the editor host after construction. Used by a subclass that is its own host (see com.codename1.ui.EditField), which cannot pass this to the constructor.

getDocument

public EditorDocument getDocument()
Returns the backing document.

getUndoManager

public UndoManager getUndoManager()
Returns the undo manager.

getCaretOffset

public int getCaretOffset()
Returns the current caret offset.

setBackgroundColor

public void setBackgroundColor(int color)
Sets the surface background color.

setTextColor

public void setTextColor(int color)
Sets the default text color.

setSelectionColor

public void setSelectionColor(int color)
Sets the selection highlight color.

getTextColor

protected int getTextColor()
Returns the default text color used by the base renderer.

setText

public void setText(String text)
Replaces the whole document text and resets the caret and history.

getText

public String getText()
Returns the whole document text.

setEditableState

public void setEditableState(boolean editable)
Enables or disables editing.

isEditableState

public boolean isEditableState()
True when editing is enabled.

blur

public void blur()
Relinquishes focus and stops the active platform text-input session.

baseFontSizePixels

protected int baseFontSizePixels()
Returns the base editor font size in pixels.

setFontSizeDips

public void setFontSizeDips(int dips)
Optionally overrides the editor font size in device independent pixels. Pass 0 to use the font supplied by the component’s style (the default, which is correctly sized for the current skin).

getEditorFont

protected Font getEditorFont()
Returns the font used to render text. By default this is the component’s style font (managed and correctly sized by Codename One, and refreshed when the skin / theme reloads, which avoids stale native font handles rendering as squares). Subclasses may override to supply styled variants.

getLineHeight

protected int getLineHeight()
Returns the default height of a single visual line in pixels.

lineHeightAt

protected int lineHeightAt(int line)
Returns the height of the given line. The default is uniform (#getLineHeight()); the rich text editor overrides this for headings and font size runs.

uniformLineHeight

protected boolean uniformLineHeight()
True when every line has the same height (the common case, and the fast path). Feature layers with variable line heights override this to return false.

invalidateLayout

protected void invalidateLayout()
Invalidates the cached line layout (used by feature layers when line heights change).

lineTopContent

protected int lineTopContent(int line)
Returns the top y pixel of the given line relative to the content top (before scroll).

contentTotalHeight

protected int contentTotalHeight()
Returns the total content height in pixels.

lineAtContentY

protected int lineAtContentY(int y)
Returns the line index at the given content relative y pixel.

getContentLeftInset

protected int getContentLeftInset()
Returns the left inset (padding plus any gutter) at which text starts.

contentWidth

protected int contentWidth()
Returns the width available for text (component width minus padding and any gutter).

hasSelection

public boolean hasSelection()
True when a non empty selection exists.

getSelectionStart

public int getSelectionStart()
Returns the inclusive start offset of the selection (or the caret when none).

getSelectionEnd

public int getSelectionEnd()
Returns the exclusive end offset of the selection (or the caret when none).

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics

longPointerPress

public void longPointerPress(int x, int y)
If this Component is focused this method is invoked when the user presses and holds the pointer on the Component

paintContent

protected void paintContent(Graphics g, int originX, int originY, int width, int height)
Paints the document content. originY is already offset by the scroll position, so line n is at originY + n * getLineHeight(). Subclasses override to add highlighting, a gutter or styled runs but should call through for the shared caret / selection rendering, or reimplement it.

Parameters

g Graphics
the graphics context
originX int
the x pixel at which line text starts
originY int
the y pixel of the first line (scroll adjusted)
width int
the content width
height int
the content height

paintComposingUnderline

protected void paintComposingUnderline(Graphics g, int line, String text, int lineStart, int lineEnd, int tx, int ly, int lineHeight, Font f)
Draws the IME composition (marked text) underline for the portion of the active composing range that falls on the given line. The composing range is set by #setComposingText(String, int) while an input method is composing (e.g. CJK) and cleared by #finishComposing().

paintBeforeContent

protected void paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f)
Hook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter. originY is scroll adjusted so line n sits at originY + n * lineHeight.

paintLineDecorations

protected void paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)
Hook invoked after a line’s text is drawn, used by the code editor to paint diagnostic squiggles.

lineTop

protected int lineTop(int line)
Returns the y pixel of the top of the given line in component local coordinates (scroll adjusted).

firstVisibleLine

protected int firstVisibleLine()
Returns the first fully or partially visible line index.

getHorizontalScroll

protected int getHorizontalScroll()
Returns the current horizontal scroll offset in pixels.

getVerticalScroll

protected int getVerticalScroll()
Returns the current vertical scroll offset in pixels.

getMaximumVerticalScroll

protected int getMaximumVerticalScroll()
Returns the largest valid vertical content offset.

paintLine

protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)
Paints a single line of text. Subclasses override to add syntax coloring; the base implementation draws the whole line in the default text color.

Parameters

g Graphics
the graphics context
line int
the zero based line index
text String
the line text
x int
the x pixel at which the line text starts
y int
the top y pixel of the line
lineHeight int
the line height
f Font
the font

offsetAtPoint

public int offsetAtPoint(int absX, int absY)
Returns the document offset nearest the given absolute screen point.

Parameters

absX int
absolute x
absY int
absolute y

consumesRawTextInput

protected boolean consumesRawTextInput()

This view edits text, so key codes reaching it are characters rather than commands.

Only while it is editable. A read only view declines the insert in keyReleased, so claiming the code anyway took a colliding soft key away from the menu bar and then did nothing with it – the command was silently lost.

Returns

true if key codes reaching this component are text rather than commands

isEditAllowed

protected boolean isEditAllowed(int start, int end)
Whether the given range may be modified. Subclasses that make part of the document read only override this so every mutation path is covered, including input method composition, which writes to the document without going through #replaceRange(int, int, String, boolean).

Parameters

start int
inclusive start offset of the edit
end int

exclusive end offset of the edit

Returns: true when the edit may proceed

replaceRange

protected void replaceRange(int start, int end, String text, boolean record)
Replaces the range [start, end) with text, updating the caret, history and platform input state.

Parameters

start int
inclusive start offset
end int
exclusive end offset
text String
the replacement text (may be empty)
record boolean
true to record the mutation for undo

documentEdited

protected void documentEdited(int fromOffset)
Hook invoked when the document is mutated at fromOffset, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.

documentReplaced

protected void documentReplaced(int start, String removed, String inserted)
Hook invoked when a range is replaced, carrying the exact removed and inserted text so feature layers (e.g. the rich text editor) can keep a parallel style / block model in sync. The default is a no-op.

Parameters

start int
the offset at which the replacement happened
removed String
the removed text
inserted String
the inserted text

documentReset

protected void documentReset()
Hook invoked when the whole document is reset (e.g. by #setText(String)), so feature layers can rebuild their parallel models. The default is a no-op.

captureDocumentState

protected Object captureDocumentState()
Captures feature-layer state associated with the document for undo/redo. Plain and code editors return null; rich editors override this to snapshot formatting, blocks, links and images.

restoreDocumentState

protected void restoreDocumentState(Object state)
Restores a feature-layer snapshot captured by #captureDocumentState().

refreshUndoAfterState

protected final void refreshUndoAfterState()
Refreshes the most recent undo unit after a feature layer finishes decorating an inserted range.

insertText

public void insertText(String text)
Inserts text at the caret, replacing any active selection.

handleTypedText

protected boolean handleTypedText(String text)
Hook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent). Return true when the text was consumed. The default returns false.

Parameters

text String
the text being typed / committed

handleTab

protected void handleTab(boolean dedent)
Handles a tab key press (delivered as #KEY_TAB). Feature layers override this for indent / dedent behavior. The default inserts a tab character on a plain tab and does nothing on a dedent (a plain editor has no indentation to remove).

Parameters

dedent boolean
true when shift was held (shift-tab)

host

protected EditorHost host()
Returns the host bridge, for feature layers that need to fire editor events.

deleteBackward

public void deleteBackward()
Deletes the selection, or the character before the caret when there is none. This is what Backspace does, including its handling of a surrogate pair, and it is public so a host that has swallowed the keystroke – a desktop menu accelerator, for instance – can hand it back rather than approximating it with the IME oriented #deleteSurroundingText(int, int).

moveCaret

public void moveCaret(int newCaret, boolean extend)
Moves the caret to a new offset, optionally extending the selection.

Parameters

newCaret int
the target offset (clamped to the document)
extend boolean
true to extend the selection from the current anchor

selectAll

public void selectAll()
Selects the entire document.

copySelection

public void copySelection()
Copies the selection to the clipboard. Public so a host that owns the platform menu bar can route its Copy item here: a menu accelerator consumes the keystroke before the editor sees it, so the host has to perform the operation on the editor’s behalf.

cutSelection

public void cutSelection()
Cuts the selection to the clipboard. See #copySelection() for why this is public.

pasteClipboard

public void pasteClipboard()
Inserts the clipboard contents at the caret. See #copySelection() for why this is public.

pasteClipboardData

protected void pasteClipboardData(Object data)
Inserts clipboard data. Rich editor subclasses may override this to preserve formatting.

lineContentOffsetX

protected int lineContentOffsetX(int line)
Returns the extra left offset of a line’s text within the content area (0 for plain text and code; the rich text editor overrides this for list bullets, indentation, block quotes and alignment so the caret and selection line up with the drawn text).

measureColumnX

protected int measureColumnX(int line, String text, int col, Font f)
Returns the visual pixel x (from the start of a line) of the caret before logical column col. For plain left-to-right text this is simply the substring width; for lines containing right-to-left or mixed (bidirectional) text it maps the logical column through the resolved visual order so the caret lines up with the reordered glyphs. The rich text editor overrides this to measure per styled run.

columnAtX

protected int columnAtX(int line, String text, int localX, Font f)
Returns the column nearest a given content-local x pixel on a line. Bidi aware: it locates the visual run containing the pixel and maps back to a logical column. The rich text editor overrides it to be styled-run aware.

lineVisualSegments

protected int[] lineVisualSegments(int line, String text, int from, int to, Font f)
Returns the visual selection segments for the logical range [from, to) on a line as a flat array of {x, width, x, width, ...} in content-local pixels. A bidi line can yield several disjoint segments; a plain line yields a single segment.

laidOut

protected void laidOut()
This is a callback method to inform the Component when it’s been laidout on the parent Container

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

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.

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

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.

keyRepeated

public void keyRepeated(int keyCode)
If this Component is focused, the key repeat event will call this method.

Parameters

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

keyReleased

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

Parameters

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

commitText

public void commitText(String text)
Commits final text at the caret, replacing the active selection. This is the normal path for a typed character, an accepted autocorrect suggestion, dictation and paste.

Parameters

text String
the committed text

setComposingText

public void setComposingText(String text, int relativeCaret)
Updates the in progress IME composition (marked text) at the caret. The composing text is not yet final and is typically rendered underlined; it is replaced on the next #setComposingText and finalized by #finishComposing.

Parameters

text String
the current marked text
relativeCaret int
caret position relative to the marked text (platform convention)

finishComposing

public void finishComposing()
Finalizes any active IME composition, committing the current marked text.

deleteSurroundingText

public void deleteSurroundingText(int before, int after)
Deletes text around the caret, the primary deletion path used by soft keyboards.

Parameters

before int
number of UTF-16 units to delete before the caret
after int
number of UTF-16 units to delete after the caret

onKeyCommand

public void onKeyCommand(int command, int modifiers)
Delivers a non text key command (navigation, deletion, clipboard, undo). Text producing keys are delivered through #commitText instead.

Parameters

command int
one of the KEY_* constants
modifiers int
a bit mask of the MOD_* constants

performUndo

public void performUndo()
Undoes the last edit.

performRedo

public void performRedo()
Redoes the last undone edit.

onEditorAction

public void onEditorAction(int action)
Delivers the keyboard return key action (done / next / search / send) configured through TextInputConfig.

Parameters

action int
one of the TextInputConfig ACTION_* constants

getEditingState

public TextInputState getEditingState()
Returns the current editing state (surrounding text, selection and composition) so the platform can seed autocorrect and prediction. May return a window around the caret for very large documents.

getCaretRect

public int[] getCaretRect()
Returns the caret rectangle in absolute screen pixels {x, y, width, height}, used by the platform to anchor the IME candidate window and the selection loupe near the rendered caret.

rectForOffset

public int[] rectForOffset(int offset)
Returns the caret rectangle for an arbitrary offset in absolute screen pixels {x, y, w, h}.

getTextLength

public int getTextLength()
Returns the total number of UTF-16 characters in the document.

getTextRange

public String getTextRange(int start, int end)
Returns the text in [start, end).

selectionRects

public int[] selectionRects(int start, int end)
Returns the selection rectangles covering [start, end) as a flat array of absolute-pixel rectangles {x, y, w, h, x, y, w, h, ...} (one entry per visual line the range spans).

replaceRange

public void replaceRange(int start, int end, String text)
Replaces the range [start, end) with text (a direct, range based edit from the platform).

setSelectionRange

public void setSelectionRange(int start, int end)
Sets the selection to [start, end) (a caret when equal).

getConfig

public TextInputConfig getConfig()
Returns the configuration describing the desired keyboard type and input behavior.

inputFocusGained

public void inputFocusGained()
Notifies the client that it gained the platform input focus (became first responder).

inputFocusLost

public void inputFocusLost()
Notifies the client that it lost the platform input focus.

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content