Class RichView
- All Implemented Interfaces:
Animation, Editable, StyleListener, TextInputClient
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_CURSORFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidApplies a hyperlink target and its default appearance to the selection.protected ObjectCaptures feature-layer state associated with the document for undo/redo.protected intReturns the column nearest a given content-local x pixel on a line.protected voidprotected voiddocumentReplaced(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 voidHook invoked when the whole document is reset (e.g. by#setText(String)), so feature layers can rebuild their parallel models.Returns the block attribute model.protected FontReturns the font used to render text.Returns the image source parallel model.Returns the inline style model.Returns the hyperlink target parallel model.voidimportContent(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.voidIncreases the indentation of the selected paragraphs.voidinsertContent(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.voidinsertImageObject(Image img, String source) Inserts an inline image at the caret (replacing any selection).protected intlineContentOffsetX(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 intlineHeightAt(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 intmeasureColumnX(int line, String text, int col, Font f) Returns the visual pixel x (from the start of a line) of the caret before logical columncol.voidmoveCaret(int newCaret, boolean extend) Moves the caret to a new offset, optionally extending the selection.voidDecreases the indentation of the selected paragraphs.protected voidPaints a single line of text.protected voidpasteClipboardData(Object data) Inserts clipboard data.booleanqueryState(String command) Returns whether an inline command (bold,italic,underline,strikeThrough) is active for the current selection.voidRemoves all inline formatting from the selection.voidRemoves the link appearance from the selection.protected voidrestoreDocumentState(Object snapshot) Restores a feature-layer snapshot captured by#captureDocumentState().voidsetAlign(int align) Sets the alignment on the selected paragraphs.voidsetBlockFormat(String tag) Sets the block type (p,h1..h6,pre,blockquote) on the selected paragraphs.voidsetFontSizeLevel(int level) Sets the relative font size level (1..7) on the selection.voidsetForeColor(int rgb) Sets the foreground color on the selection.voidsetHighlight(int rgb) Sets the highlight color on the selection.voidsetList(int listType) Applies (or toggles off) an ordered / unordered list on the selected paragraphs.voidsetPlaceholder(String text) Sets the placeholder text shown when the document is empty.voidToggles bold on the selection (or the pending typing style when the selection is empty).voidToggles italic.voidToggles strike-through.voidToggles underline.protected booleanTrue 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, setTextColorMethods 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
-
Constructor Details
-
RichView
Creates a rich text view.
-
-
Method Details
-
getInlineStyles
Returns the inline style model. -
getBlocks
Returns the block attribute model. -
getLinkRuns
-
getImageSources
-
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
-
pasteClipboardData
Description copied from class:EditorViewInserts clipboard data. Rich editor subclasses may override this to preserve formatting.- Overrides:
pasteClipboardDatain classEditorView
-
copySelection
protected void copySelection()- Overrides:
copySelectionin classEditorView
-
setPlaceholder
Sets the placeholder text shown when the document is empty. -
uniformLineHeight
protected boolean uniformLineHeight()Description copied from class:EditorViewTrue 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:
uniformLineHeightin classEditorView
-
lineHeightAt
protected int lineHeightAt(int line) Description copied from class:EditorViewReturns the height of the given line. The default is uniform (#getLineHeight()); the rich text editor overrides this for headings and font size runs.- Overrides:
lineHeightAtin classEditorView
-
documentReset
protected void documentReset()Description copied from class:EditorViewHook 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:
documentResetin classEditorView
-
documentReplaced
Description copied from class:EditorViewHook 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:
documentReplacedin classEditorView
-
-
captureDocumentState
Description copied from class:EditorViewCaptures 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:
captureDocumentStatein classEditorView
-
restoreDocumentState
Description copied from class:EditorViewRestores a feature-layer snapshot captured by#captureDocumentState().- Overrides:
restoreDocumentStatein classEditorView
-
insertImageObject
-
moveCaret
public void moveCaret(int newCaret, boolean extend) Description copied from class:EditorViewMoves 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:
moveCaretin classEditorView
-
-
measureColumnX
Description copied from class:EditorViewReturns the visual pixel x (from the start of a line) of the caret before logical columncol. 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:
measureColumnXin classEditorView
-
columnAtX
Description copied from class:EditorViewReturns 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:
columnAtXin classEditorView
-
lineVisualSegments
Description copied from class:EditorViewReturns 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:
lineVisualSegmentsin classEditorView
-
lineContentOffsetX
protected int lineContentOffsetX(int line) Description copied from class:EditorViewReturns 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:
lineContentOffsetXin classEditorView
-
paintLine
Description copied from class:EditorViewPaints 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:
paintLinein classEditorView
-
-
getEditorFont
Description copied from class:EditorViewReturns 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:
getEditorFontin classEditorView
-
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
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
Applies a hyperlink target and its default appearance to the selection. -
removeLinkStyle
public void removeLinkStyle()Removes the link appearance from the selection. -
queryState
Returns whether an inline command (bold,italic,underline,strikeThrough) is active for the current selection.
-