public class RichView

  1. Object
  2. Component
  3. EditorView
  4. RichView

ImplementsAnimation, Editable, StyleListener, TextInputClient

The pure rich text editor surface. It renders styled text (bold / italic / underline / strike, foreground and highlight color, relative font size) organized into paragraphs with block attributes (headings, preformatted, block quotes, alignment, ordered / unordered lists and indentation) on top of the shared EditorView engine, keeping a parallel InlineStyles and RichBlocks model in lockstep with the text.

Constructors

public RichView(EditorHost host)Creates a rich text view.

Methods

public InlineStyles getInlineStyles()Returns the inline style model.
public RichBlocks getBlocks()Returns the block attribute model.
public List<String> getLinkRuns()Returns the hyperlink target parallel model.
public List<String> getImageSources()Returns the image source parallel model.
public void importContent(String text, List<TextStyle> perChar, List<RichBlocks.BlockAttr> blockList, List<String> links, List<Image> images, List<String> sources)Replaces the document with imported content: text plus per character styles and per paragraph block attributes.
public void insertContent(String text, List<TextStyle> perChar, List<RichBlocks.BlockAttr> blockList, List<String> links, List<Image> images, List<String> sources, boolean blockContent)Inserts imported rich content at the selection while preserving its inline and block metadata.
protected void pasteClipboardData(Object data)Inserts clipboard data.
public void copySelection()Copies the selection to the clipboard.
public void setPlaceholder(String text)Sets the placeholder text shown when the document is empty.
protected boolean uniformLineHeight()True when every line has the same height (the common case, and the fast path).
protected int lineHeightAt(int line)Returns the height of the given line.
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 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 Object captureDocumentState()Captures feature-layer state associated with the document for undo/redo.
protected void restoreDocumentState(Object snapshot)Restores a feature-layer snapshot captured by #captureDocumentState().
public void insertImageObject(Image img, String source)Inserts an inline image at the caret (replacing any selection).
public void moveCaret(int newCaret, boolean extend)Moves the caret to a new offset, optionally extending the selection.
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 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 void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)Paints a single line of text.
protected Font getEditorFont()Returns the font used to render text.
public void toggleBold()Toggles bold on the selection (or the pending typing style when the selection is empty).
public void toggleItalic()Toggles italic.
public void toggleUnderline()Toggles underline.
public void toggleStrike()Toggles strike-through.
public void setForeColor(int rgb)Sets the foreground color on the selection.
public void setHighlight(int rgb)Sets the highlight color on the selection.
public void setFontSizeLevel(int level)Sets the relative font size level (1..7) on the selection.
public void removeFormat()Removes all inline formatting from the selection.
public void setBlockFormat(String tag)Sets the block type (p, h1..h6, pre, blockquote) on the selected paragraphs.
public void setAlign(int align)Sets the alignment on the selected paragraphs.
public void setList(int listType)Applies (or toggles off) an ordered / unordered list on the selected paragraphs.
public void indentBlocks()Increases the indentation of the selected paragraphs.
public void outdentBlocks()Decreases the indentation of the selected paragraphs.
public void applyLink(String url)Applies a hyperlink target and its default appearance to the selection.
public void removeLinkStyle()Removes the link appearance from the selection.
public boolean queryState(String command)Returns whether an inline command (bold, italic, underline, strikeThrough) is active for the current selection.

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

RichView

public RichView(EditorHost host)
Creates a rich text view.

Method details

getInlineStyles

public InlineStyles getInlineStyles()
Returns the inline style model.

getBlocks

public RichBlocks getBlocks()
Returns the block attribute model.

getLinkRuns

public List<String> getLinkRuns()
Returns the hyperlink target parallel model.

getImageSources

public List<String> getImageSources()
Returns the image source parallel model.

importContent

public void importContent(String text, List<TextStyle> perChar, List<RichBlocks.BlockAttr> blockList, List<String> links, List<Image> images, List<String> sources)
Replaces the document with imported content: text plus per character styles and per paragraph block attributes. Used by the HTML importer.

Parameters

text String
the plain text
perChar List<TextStyle>
one style per character (may be shorter; missing entries default)
blockList List<RichBlocks.BlockAttr>
one block attribute per paragraph (may be shorter; missing entries default)
links List<String>
Not documented.
images List<Image>
Not documented.
sources List<String>
Not documented.

insertContent

public void insertContent(String text, List<TextStyle> perChar, List<RichBlocks.BlockAttr> blockList, List<String> links, List<Image> images, List<String> sources, boolean blockContent)
Inserts imported rich content at the selection while preserving its inline and block metadata.

pasteClipboardData

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

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.

setPlaceholder

public void setPlaceholder(String text)
Sets the placeholder text shown when the document is empty.

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.

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.

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.

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

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 snapshot)
Restores a feature-layer snapshot captured by #captureDocumentState().

insertImageObject

public void insertImageObject(Image img, String source)
Inserts an inline image at the caret (replacing any selection).

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

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.

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).

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

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.

toggleBold

public void toggleBold()
Toggles bold on the selection (or the pending typing style when the selection is empty).

toggleItalic

public void toggleItalic()
Toggles italic.

toggleUnderline

public void toggleUnderline()
Toggles underline.

toggleStrike

public void toggleStrike()
Toggles strike-through.

setForeColor

public void setForeColor(int rgb)
Sets the foreground color on the selection.

setHighlight

public void setHighlight(int rgb)
Sets the highlight color on the selection.

setFontSizeLevel

public void setFontSizeLevel(int level)
Sets the relative font size level (1..7) on the selection.

removeFormat

public void removeFormat()
Removes all inline formatting from the selection.

setBlockFormat

public void setBlockFormat(String tag)
Sets the block type (p, h1..h6, pre, blockquote) on the selected paragraphs.

setAlign

public void setAlign(int align)
Sets the alignment on the selected paragraphs.

setList

public void setList(int listType)
Applies (or toggles off) an ordered / unordered list on the selected paragraphs.

indentBlocks

public void indentBlocks()
Increases the indentation of the selected paragraphs.

outdentBlocks

public void outdentBlocks()
Decreases the indentation of the selected paragraphs.

applyLink

public void applyLink(String url)
Applies a hyperlink target and its default appearance to the selection.

removeLinkStyle

public void removeLinkStyle()
Removes the link appearance from the selection.

queryState

public boolean queryState(String command)
Returns whether an inline command (bold, italic, underline, strikeThrough) is active for the current selection.