Class 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.
  • 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.