public class RichView
- Object
- Component
- EditorView
- RichView
ImplementsAnimation, Editable, StyleListener, TextInputClient
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
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From EditorView
scrollByPixels, setEditorHost, getDocument, getUndoManager, getCaretOffset, setBackgroundColor, setTextColor, setSelectionColor, getTextColor, setText, getText, setEditableState, isEditableState, blur, baseFontSizePixels, setFontSizeDips, getLineHeight, invalidateLayout, lineTopContent, contentTotalHeight, lineAtContentY, getContentLeftInset, contentWidth, hasSelection, getSelectionStart, getSelectionEnd, paint, longPointerPress, paintContent, paintComposingUnderline, paintBeforeContent, paintLineDecorations, lineTop, firstVisibleLine, getHorizontalScroll, getVerticalScroll, getMaximumVerticalScroll, offsetAtPoint, consumesRawTextInput, isEditAllowed, replaceRange, documentEdited, refreshUndoAfterState, insertText, handleTypedText, handleTab, host, deleteBackward, selectAll, cutSelection, pasteClipboard, laidOut, focusGained, focusLost, deinitialize, animate, pointerPressed, pointerDragged, pointerReleased, keyPressed, keyRepeated, keyReleased, commitText, setComposingText, finishComposing, deleteSurroundingText, onKeyCommand, performUndo, performRedo, onEditorAction, getEditingState, getCaretRect, rectForOffset, getTextLength, getTextRange, selectionRects, replaceRange, setSelectionRange, getConfig, inputFocusGained, inputFocusLost, calcPreferredSize
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)Method details
getInlineStyles
public InlineStyles getInlineStyles()getBlocks
public RichBlocks getBlocks()getLinkRuns
public List<String> getLinkRuns()getImageSources
public List<String> getImageSources()importContent
public void importContent(String text, List<TextStyle> perChar, List<RichBlocks.BlockAttr> blockList, List<String> links, List<Image> images, List<String> sources)Parameters
textString- the plain text
perCharList<TextStyle>- one style per character (may be shorter; missing entries default)
blockListList<RichBlocks.BlockAttr>- one block attribute per paragraph (may be shorter; missing entries default)
linksList<String>- Not documented.
imagesList<Image>- Not documented.
sourcesList<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)pasteClipboardData
protected void pasteClipboardData(Object data)copySelection
public void copySelection()setPlaceholder
public void setPlaceholder(String text)uniformLineHeight
protected boolean uniformLineHeight()lineHeightAt
protected int lineHeightAt(int line)#getLineHeight()); the rich text
editor overrides this for headings and font size runs.documentReset
protected void documentReset()#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)Parameters
startint- the offset at which the replacement happened
removedString- the removed text
insertedString- the inserted text
captureDocumentState
protected Object captureDocumentState()restoreDocumentState
protected void restoreDocumentState(Object snapshot)#captureDocumentState().insertImageObject
public void insertImageObject(Image img, String source)moveCaret
public void moveCaret(int newCaret, boolean extend)Parameters
newCaretint- the target offset (clamped to the document)
extendboolean- true to extend the selection from the current anchor
measureColumnX
protected int measureColumnX(int line, String text, int col, Font f)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)lineVisualSegments
protected int[] lineVisualSegments(int line, String text, int from, int to, Font f)[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)paintLine
protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)Parameters
gGraphics- the graphics context
lineint- the zero based line index
textString- the line text
xint- the x pixel at which the line text starts
yint- the top y pixel of the line
lineHeightint- the line height
fFont- the font
getEditorFont
protected Font getEditorFont()toggleBold
public void toggleBold()toggleItalic
public void toggleItalic()toggleUnderline
public void toggleUnderline()toggleStrike
public void toggleStrike()setForeColor
public void setForeColor(int rgb)setHighlight
public void setHighlight(int rgb)setFontSizeLevel
public void setFontSizeLevel(int level)removeFormat
public void removeFormat()setBlockFormat
public void setBlockFormat(String tag)p, h1..h6, pre, blockquote) on the selected paragraphs.setAlign
public void setAlign(int align)setList
public void setList(int listType)indentBlocks
public void indentBlocks()outdentBlocks
public void outdentBlocks()applyLink
public void applyLink(String url)removeLinkStyle
public void removeLinkStyle()queryState
public boolean queryState(String command)bold, italic, underline, strikeThrough) is active for
the current selection.