# Class RichView

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.editor.EditorView
com.codename1.ui.editor.RichView

All Implemented Interfaces:
  `Animation, Editable, StyleListener, TextInputClient`

public class RichView extends EditorView
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.

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

  ### Fields inherited from interface TextInputClient

  `KEY_BACKSPACE, KEY_COPY, KEY_CUT, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_REDO, KEY_RIGHT, KEY_SELECT_ALL, KEY_UNDO, KEY_UP, MOD_ALT, MOD_CTRL, MOD_SHIFT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RichView(EditorHost host)`
  Creates a rich text view.

- ## Method Summary

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

  ### Methods inherited from class EditorView

  `animate, baseFontSizePixels, blur, calcPreferredSize, commitText, contentTotalHeight, contentWidth, deleteSurroundingText, documentEdited, finishComposing, firstVisibleLine, focusGained, focusLost, getCaretOffset, getCaretRect, getConfig, getContentLeftInset, getDocument, getEditingState, getHorizontalScroll, getLineHeight, getMaximumVerticalScroll, getSelectionEnd, getSelectionStart, getText, getTextColor, getTextLength, getTextRange, getUndoManager, getVerticalScroll, handleTypedText, hasSelection, host, inputFocusGained, inputFocusLost, insertText, invalidateLayout, isEditableState, keyPressed, keyReleased, keyRepeated, laidOut, lineAtContentY, lineTop, lineTopContent, longPointerPress, offsetAtPoint, onEditorAction, onKeyCommand, paint, paintBeforeContent, paintComposingUnderline, paintContent, paintLineDecorations, performRedo, performUndo, pointerDragged, pointerPressed, pointerReleased, rectForOffset, refreshUndoAfterState, replaceRange, replaceRange, scrollByPixels, selectAll, selectionRects, setBackgroundColor, setComposingText, setEditableState, setFontSizeDips, setSelectionColor, setSelectionRange, setText, setTextColor`

  ### Methods inherited from class Component

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

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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`: the plain text

    - `perChar`: one style per character (may be shorter; missing entries default)

    - `blockList`: one block attribute per paragraph (may be shorter; missing entries default)

  - ### 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)
    Description copied from class: `EditorView`
    Inserts clipboard data. Rich editor subclasses may override this to preserve formatting.
    Overrides:
      `pasteClipboardData` in class `EditorView`

  - ### copySelection

    protected void copySelection()
    Overrides:
      `copySelection` in class `EditorView`

  - ### setPlaceholder

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

  - ### uniformLineHeight

    protected boolean uniformLineHeight()
    Description copied from class: `EditorView`
    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.
    Overrides:
      `uniformLineHeight` in class `EditorView`

  - ### lineHeightAt

    protected int lineHeightAt(int line)
    Description copied from class: `EditorView`
    Returns the height of the given line. The default is uniform (`#getLineHeight()`); the rich text editor overrides this for headings and font size runs.
    Overrides:
      `lineHeightAt` in class `EditorView`

  - ### documentReset

    protected void documentReset()
    Description copied from class: `EditorView`
    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.
    Overrides:
      `documentReset` in class `EditorView`

  - ### documentReplaced

    protected void documentReplaced(int start, String removed, String inserted)
    Description copied from class: `EditorView`

    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`: the offset at which the replacement happened

    - `removed`: the removed text

    - `inserted`: the inserted text

    Overrides:
      `documentReplaced` in class `EditorView`

  - ### captureDocumentState

    protected Object captureDocumentState()
    Description copied from class: `EditorView`
    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.
    Overrides:
      `captureDocumentState` in class `EditorView`

  - ### restoreDocumentState

    protected void restoreDocumentState(Object snapshot)
    Description copied from class: `EditorView`
    Restores a feature-layer snapshot captured by `#captureDocumentState()`.
    Overrides:
      `restoreDocumentState` in class `EditorView`

  - ### 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)
    Description copied from class: `EditorView`

    Moves the caret to a new offset, optionally extending the selection.

    ###### Parameters

    - `newCaret`: the target offset (clamped to the document)

    - `extend`: true to extend the selection from the current anchor

    Overrides:
      `moveCaret` in class `EditorView`

  - ### measureColumnX

    protected int measureColumnX(int line, String text, int col, Font f)
    Description copied from class: `EditorView`
    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.
    Overrides:
      `measureColumnX` in class `EditorView`

  - ### columnAtX

    protected int columnAtX(int line, String text, int localX, Font f)
    Description copied from class: `EditorView`
    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.
    Overrides:
      `columnAtX` in class `EditorView`

  - ### lineVisualSegments

    protected int[] lineVisualSegments(int line, String text, int from, int to, Font f)
    Description copied from class: `EditorView`
    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.
    Overrides:
      `lineVisualSegments` in class `EditorView`

  - ### lineContentOffsetX

    protected int lineContentOffsetX(int line)
    Description copied from class: `EditorView`
    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).
    Overrides:
      `lineContentOffsetX` in class `EditorView`

  - ### paintLine

    protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)
    Description copied from class: `EditorView`

    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`: the graphics context

    - `line`: the zero based line index

    - `text`: the line text

    - `x`: the x pixel at which the line text starts

    - `y`: the top y pixel of the line

    - `lineHeight`: the line height

    - `f`: the font

    Overrides:
      `paintLine` in class `EditorView`

  - ### getEditorFont

    protected Font getEditorFont()
    Description copied from class: `EditorView`
    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.
    Overrides:
      `getEditorFont` in class `EditorView`

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