Class DocumentView
- All Implemented Interfaces:
Animation, Editable, StyleListener, TextInputClient, TextInputClient.CompositionCancellation, TextInputGeometry.Provider
Shows a document as pages and edits it, the way DataGrid shows and edits a Sheet.
DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
DocumentView view = new DocumentView(model);
Form form = new Form("Document", new BorderLayout());
form.add(BorderLayout.CENTER, view);
form.show();
The view subscribes to its model while it is on a form and lays the document out again on
every change, so anything that edits the model -- the view itself, a toolbar, an undo button
-- is shown at once. Pages are laid out by DocumentLayout with the view's Measurer
(ScreenMeasurer by default, the fonts the view draws in). Set a PdfMeasurer to break
pages exactly where the PDF export does, at the cost of spacing set by the PDF's fonts.
A tap places the caret, a drag or a double tap selects, and typing, Backspace, Delete and Enter edit through the model, which gives undo for free. Pinch or Control and the wheel zooms; by default a page is fitted to the view's width when it would not fit.
-
Nested Class Summary
Nested classes/interfaces inherited from class ScrollSurface
ScrollSurface.EditTrigger, ScrollSurface.PageGridNested classes/interfaces inherited from interface TextInputClient
TextInputClient.CompositionCancellation -
Field Summary
Fields inherited from class ScrollSurface
HOVER_MS, LIFT_MS, SETTLE_MSFields 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_SCROLL_PAGE_DOWN, KEY_SCROLL_PAGE_UP, KEY_SELECT_ALL, KEY_TAB, KEY_UNDO, KEY_UP, KEY_WORD_LEFT, KEY_WORD_RIGHT, MOD_ALT, MOD_CTRL, MOD_SHIFT -
Constructor Summary
ConstructorsConstructorDescriptionA view of an empty document.DocumentView(Document doc) A view of a document, in a model of its own.DocumentView(DocumentModel model) A view of a model. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener told when the caret or the selection moves, for a toolbar showing the style at the caret.protected booleanAdvances the view's own motion.voidapplySuggestion(String paragraphId, ProofIssue issue, String replacement) Replaces the range of a problem with one of its suggestions, as one undoable edit.voidNothing to undo: composing text is never inserted before it is committed.commentSelection(String text) Adds a review comment over the selection, by the model's author.voidcommitText(String text) Typed text from the platform's keyboard or input method.voidCopies the selection to the clipboard as plain text, HTML, RTF and Markdown, so it pastes with its formatting into a word processor, a browser or a text editor alike.voidCopies the selection to the clipboard and deletes it.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.voidDeletes the selection, or the character before the caret, joining paragraphs at a paragraph start.voidDeletes the selection, or the character after the caret.voiddeleteSurroundingText(int before, int after) Deletes around the caret, within its paragraph.protected voideditEnded(boolean committed) The edit is over.protected voideditMoved(int x, int y) The pointer of an edit moved, or the surface scrolled under it.protected booleaneditStarted(int x, int y, ScrollSurface.EditTrigger trigger) Asked when a drag or a long press begins, at the point where the pointer went down, in the component's coordinates.voidNothing to do: composing text is never shown before it is committed.protected voidCallback allowing a developer to track when the component gains focusprotected voidCallback allowing a developer to track wheh the component loses focusprotected FontThe platform font text of a style is drawn in, at a pixel size.getCaret()The caret, or null when there is none.int[]The caret rectangle in screen coordinates.The review comments over the caret.Multi-line text with autocorrect.protected intThe height of what scrolls, in pixels, without the top header.protected intThe width of what scrolls, in pixels, without the left header.The document shown; a shortcut forgetModel().getDocument().The caret's paragraph, as the platform sees the text being edited.The caret and selection rectangles the platform places its candidate window by.The current layout.The measurer pages are laid out with.getModel()The model shown.The proofreader underlining problems.floatgetScale()Pixels per point at the current size.The selection, earlier end first, or null when nothing is selected.intThe length of the caret's paragraph.getTextRange(int start, int end) Part of the caret's paragraph.floatgetZoom()The zoom factor on top of the fitted or natural size.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statevoidNothing to do.voidThe platform let go of input.booleanTrue when the view shows its pages without chrome.booleanWhether the user may edit the document.booleanWhether a page wider than the view is shrunk to fit its width.int[]itemBounds(int page, LayoutItem item) Where a laid out item is, in the view's own coordinates at the current scroll.voidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodprotected voidlayoutSurface(int width, int height) Lays the surface out for a size: sets the header sizes and whatever the content's size depends on.voidmoveCaret(boolean forward, boolean extend) Moves the caret one character, or extends the selection whenextendis true.voidmoveCaretLine(boolean down, boolean extend) Moves the caret a line up or down, or extends the selection.intoffsetAtPoint(int x, int y) The offset in the caret's paragraph nearest a screen point.voidonEditorAction(int action) The Enter action splits the paragraph.voidonKeyCommand(int command, int modifiers) A key command from the platform.voidPaints the view, then the touch selection handles and toolbar over it.protected voidpaintComponentBox(Graphics g, LayoutItem item, int x, int y, int w, int h) Paints an embedded component's box: its snapshot, or a frame naming its type.protected voidpaintContent(Graphics g, int x, int y) Paints what scrolls.voidPastes the clipboard over the selection, keeping formatting when the clipboard holds HTML, RTF or Markdown.positionAt(int x, int y) The text position under a point in the view.proofIssueAt(TextPosition at, int max) The problem under a text position, with spelling suggestions, for a menu of fixes.int[]rectForOffset(int offset) Where an offset of the caret's paragraph is on screen.voidRemoves a caret listener.voidreplaceRange(int start, int end, String text) Replaces part of the caret's paragraph.protected voidThe scroll position changed.voidSelects the whole document.int[]selectionRects(int start, int end) The selection rectangles of a range of the caret's paragraph.voidsetCaret(TextPosition value) Places the caret and clears the selection.voidsetChromeless(boolean value) Shows the pages with nothing around them: no desk, no page edge and no white page, one page directly under the other with no gap.voidsetComposingText(String text, int relativeCaret) Composition is committed whole: the composing text is typed as it is.voidsetDocument(Document doc) Replaces the document, forgetting the undo history; a shortcut forgetModel().reset(doc).voidsetEditable(boolean value) Lets the user edit the document, or only read and select it.voidsetFitWidth(boolean value) Shrinks pages wider than the view to its width, or shows them at their natural size.voidsetFixedScale(float value) Pins the scale, in pixels per point, overriding fit-to-width and zoom; zero or less returns to them.voidsetMeasurer(Measurer value) Sets the measurer pages are laid out with, for instance aPdfMeasurerwith TrueType fonts registered for a script the standard fonts lack.final voidsetModel(DocumentModel value) Shows another model.voidUnderlines spelling and grammar problems with a wavy line, red for spelling and blue for grammar.voidsetSelection(TextPosition from, TextPosition to) Selects the text between two positions; equal positions place the caret.voidsetSelectionRange(int start, int end) Selects part of the caret's paragraph.voidsetZoom(float value) Sets the zoom factor on top of the fitted or natural size.protected voidtapped(int x, int y, boolean doubleTap) A tap that was not a drag or a long press.voidTypes text at the caret, replacing the selection.protected booleanzoomBy(float factor, int x, int y) Zooms byfactoraround a point, for a pinch or Control/Command and the wheel.Methods inherited from class ScrollSurface
animate, applySettle, calcPreferredSize, cancelEdit, currentTime, getBodyHeight, getBodyWidth, getBodyX, getContentOriginX, getFadingHoverTarget, getHeaderHeight, getHeaderWidth, getHeaderX, getHoverLevel, getHoverTarget, getLiftLevel, getMaxOffsetX, getMaxOffsetY, getOffsetX, getOffsetY, getPageGrid, getPageStep, hasHoverFeedback, hoverAt, hoverGone, isBounded, isDragEdits, isEditAutoScroll, isEditInProgress, isMirrored, isPrinting, longPointerPress, longPressed, mouseWheel, paintCorner, paintLeftHeader, paintOverlay, paintPage, paintTopHeader, pinch, pinchReleased, pointerDragged, pointerHover, pointerPressed, pointerReleased, pressStarted, refreshLayout, requestAnimation, restoreZoomState, saveZoomState, scrollTo, setAnimationTime, setBounded, setDragEdits, setHeaderSize, setHovered, setHoverTarget, setHoverTooltip, setOffsets, shouldBlockSideSwipe, startSettle, stopFlingMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, 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, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyReleased, keyRepeated, laidOut, longKeyPress, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, 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, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
DocumentView
public DocumentView()A view of an empty document. -
DocumentView
A view of a document, in a model of its own.
Parameters
doc: the document
-
DocumentView
A view of a model.
Parameters
model: the model
-
-
Method Details
-
getModel
The model shown.
Returns
the model
-
setModel
Shows another model.
Parameters
value: the model
-
getDocument
The document shown; a shortcut for
getModel().getDocument().Returns
the document
-
setDocument
Replaces the document, forgetting the undo history; a shortcut for
getModel().reset(doc).Parameters
doc: the document
-
setMeasurer
Sets the measurer pages are laid out with, for instance a
PdfMeasurerwith TrueType fonts registered for a script the standard fonts lack.Parameters
value: the measurer
-
getMeasurer
The measurer pages are laid out with.
Returns
the measurer
-
getLayout
The current layout.
Returns
the layout of the model's document
-
isEditable
public boolean isEditable()Whether the user may edit the document.
Returns
true by default
- Specified by:
isEditablein interfaceEditable- Overrides:
isEditablein classComponent
-
setEditable
public void setEditable(boolean value) Lets the user edit the document, or only read and select it.
Parameters
value: true to allow editing
-
getZoom
public float getZoom()The zoom factor on top of the fitted or natural size.
Returns
the factor, 1 by default
-
setZoom
public void setZoom(float value) Sets the zoom factor on top of the fitted or natural size.
Parameters
value: between 0.25 and 6
-
isFitWidth
public boolean isFitWidth()Whether a page wider than the view is shrunk to fit its width.
Returns
true by default
-
setFitWidth
public void setFitWidth(boolean value) Shrinks pages wider than the view to its width, or shows them at their natural size.
Parameters
value: true to fit
-
getCaret
The caret, or null when there is none.
Returns
the caret position
-
setCaret
Places the caret and clears the selection.
Parameters
value: the position, or null to remove the caret
-
setSelection
Selects the text between two positions; equal positions place the caret.
Parameters
-
from: where the selection is anchored -
to: where the caret is
-
-
getSelection
The selection, earlier end first, or null when nothing is selected.
Returns
the two ends, or null
-
addCaretListener
Adds a listener told when the caret or the selection moves, for a toolbar showing the style at the caret.
Parameters
l: the listener
-
removeCaretListener
Removes a caret listener.
Parameters
l: the listener
-
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classScrollSurface
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.- Overrides:
deinitializein classScrollSurface
-
getScale
public float getScale()Pixels per point at the current size.
Returns
the scale
-
setChromeless
public void setChromeless(boolean value) Shows the pages with nothing around them: no desk, no page edge and no white page, one page directly under the other with no gap. A view laid over a slide uses this to edit a text box in place, over the shape's own fill.
Parameters
value: true for no chrome
-
isChromeless
public boolean isChromeless()True when the view shows its pages without chrome.
Returns
true without chrome
-
setFixedScale
public void setFixedScale(float value) Pins the scale, in pixels per point, overriding fit-to-width and zoom; zero or less returns to them. A view laid over another painting of the same text uses this so both put every word in the same place.
Parameters
value: pixels per point, or 0
-
scrollChanged
protected void scrollChanged()Description copied from class:ScrollSurfaceThe scroll position changed.- Overrides:
scrollChangedin classScrollSurface
-
itemBounds
Where a laid out item is, in the view's own coordinates at the current scroll.
Parameters
-
page: the item's page -
item: the item
Returns
{x, y, width, height}in pixels -
-
layoutSurface
protected void layoutSurface(int width, int height) Description copied from class:ScrollSurfaceLays the surface out for a size: sets the header sizes and whatever the content's size depends on. Called before every paint and every pointer event, so it has to return at once when nothing has changed.- Specified by:
layoutSurfacein classScrollSurface
-
getContentWidth
protected int getContentWidth()Description copied from class:ScrollSurfaceThe width of what scrolls, in pixels, without the left header.- Specified by:
getContentWidthin classScrollSurface
-
getContentHeight
protected int getContentHeight()Description copied from class:ScrollSurfaceThe height of what scrolls, in pixels, without the top header.- Specified by:
getContentHeightin classScrollSurface
-
zoomBy
protected boolean zoomBy(float factor, int x, int y) Description copied from class:ScrollSurfaceZooms by
factoraround a point, for a pinch or Control/Command and the wheel.Returns
false when the surface has no zoom, so the gesture is left alone
- Overrides:
zoomByin classScrollSurface
-
setProofreader
Underlines spelling and grammar problems with a wavy line, red for spelling and blue for grammar.
Parameters
p: the proofreader, or null to stop
-
getProofreader
The proofreader underlining problems.
Returns
the proofreader, or null
-
proofIssueAt
The problem under a text position, with spelling suggestions, for a menu of fixes.
Parameters
-
at: the position -
max: the most suggestions
Returns
the issue, or null when there is none or no proofreader
-
-
applySuggestion
Replaces the range of a problem with one of its suggestions, as one undoable edit.
Parameters
-
paragraphId: the paragraph the issue was found in -
issue: the issue -
replacement: the text to put in its place
-
-
paintContent
Description copied from class:ScrollSurfacePaints what scrolls.xandyare where the content's own origin is on screen, which is off screen once it has scrolled. The graphics is clipped to the content region.- Specified by:
paintContentin classScrollSurface
-
paintComponentBox
Paints an embedded component's box: its snapshot, or a frame naming its type. A subclass that hosts live components paints them here.
Parameters
-
g: the graphics -
item: the laid out component -
x: the box's left edge in pixels -
y: its top edge -
w: its width -
h: its height
-
-
getCommentsAtCaret
-
commentSelection
-
font
-
positionAt
The text position under a point in the view.
Parameters
-
x: in the component's coordinates -
y: in the component's coordinates
Returns
the position, or null
-
-
tapped
protected void tapped(int x, int y, boolean doubleTap) Description copied from class:ScrollSurfaceA tap that was not a drag or a long press.- Overrides:
tappedin classScrollSurface
-
editStarted
Description copied from class:ScrollSurfaceAsked when a drag or a long press begins, at the point where the pointer went down, in the component's coordinates.
Parameters
trigger: what kind of gesture it is
Returns
true when an edit has begun and the drag belongs to it; false to pan
- Overrides:
editStartedin classScrollSurface
-
editMoved
protected void editMoved(int x, int y) Description copied from class:ScrollSurfaceThe pointer of an edit moved, or the surface scrolled under it.- Overrides:
editMovedin classScrollSurface
-
editEnded
protected void editEnded(boolean committed) Description copied from class:ScrollSurfaceThe edit is over.committedis false when it was cancelled: bycancelEdit, a second finger, or the surface leaving the form.- Overrides:
editEndedin classScrollSurface
-
animateSurface
protected boolean animateSurface()Description copied from class:ScrollSurfaceAdvances the view's own motion. Called every frame while the surface animates; call
requestAnimationto start the frames.Returns
true while the view still has something moving
- Overrides:
animateSurfacein classScrollSurface
-
focusGained
protected void focusGained()Description copied from class:ComponentCallback allowing a developer to track when the component gains focus- Overrides:
focusGainedin classComponent
-
focusLost
-
paint
Paints the view, then the touch selection handles and toolbar over it.
Parameters
g: the graphics
- Specified by:
paintin interfaceAnimation- Overrides:
paintin classScrollSurface
-
copySelection
public void copySelection()Copies the selection to the clipboard as plain text, HTML, RTF and Markdown, so it pastes with its formatting into a word processor, a browser or a text editor alike. -
cutSelection
public void cutSelection()Copies the selection to the clipboard and deletes it. -
pasteClipboard
public void pasteClipboard()Pastes the clipboard over the selection, keeping formatting when the clipboard holds HTML, RTF or Markdown. -
selectAll
public void selectAll()Selects the whole document. -
typeText
Types text at the caret, replacing the selection.
Parameters
text: the text; a line break splits the paragraph
-
deleteBackward
public void deleteBackward()Deletes the selection, or the character before the caret, joining paragraphs at a paragraph start. -
deleteForward
public void deleteForward()Deletes the selection, or the character after the caret. -
moveCaret
public void moveCaret(boolean forward, boolean extend) Moves the caret one character, or extends the selection when
extendis true.Parameters
-
forward: true to move right -
extend: true to keep the selection anchor
-
-
moveCaretLine
public void moveCaretLine(boolean down, boolean extend) Moves the caret a line up or down, or extends the selection.
Parameters
-
down: true to move down -
extend: true to keep the selection anchor
-
-
keyPressed
public void keyPressed(int keyCode) Description copied from class:ComponentIf this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classComponent
-
commitText
Typed text from the platform's keyboard or input method.
Parameters
text: the text
- Specified by:
commitTextin interfaceTextInputClient
-
setComposingText
Composition is committed whole: the composing text is typed as it is.
Parameters
-
text: the composing text -
relativeCaret: ignored
- Specified by:
setComposingTextin interfaceTextInputClient
-
-
finishComposing
public void finishComposing()Nothing to do: composing text is never shown before it is committed.- Specified by:
finishComposingin interfaceTextInputClient
-
deleteSurroundingText
public void deleteSurroundingText(int before, int after) Deletes around the caret, within its paragraph.
Parameters
-
before: characters before the caret -
after: characters after it
- Specified by:
deleteSurroundingTextin interfaceTextInputClient
-
-
onKeyCommand
public void onKeyCommand(int command, int modifiers) A key command from the platform.
Parameters
-
command: one of theTextInputClientcommands -
modifiers: modifier bits
- Specified by:
onKeyCommandin interfaceTextInputClient
-
-
onEditorAction
public void onEditorAction(int action) The Enter action splits the paragraph.
Parameters
action: the action
- Specified by:
onEditorActionin interfaceTextInputClient
-
getEditingState
The caret's paragraph, as the platform sees the text being edited.
Returns
the state
- Specified by:
getEditingStatein interfaceTextInputClient
-
getCaretRect
public int[] getCaretRect()The caret rectangle in screen coordinates.
Returns
{x, y, width, height}- Specified by:
getCaretRectin interfaceTextInputClient
-
getConfig
Multi-line text with autocorrect.
Returns
the configuration
- Specified by:
getConfigin interfaceTextInputClient
-
inputFocusGained
public void inputFocusGained()Nothing to do.- Specified by:
inputFocusGainedin interfaceTextInputClient
-
inputFocusLost
public void inputFocusLost()The platform let go of input.- Specified by:
inputFocusLostin interfaceTextInputClient
-
cancelComposing
public void cancelComposing()Nothing to undo: composing text is never inserted before it is committed.- Specified by:
cancelComposingin interfaceTextInputClient.CompositionCancellation
-
getGeometrySnapshot
The caret and selection rectangles the platform places its candidate window by.
Returns
the snapshot
- Specified by:
getGeometrySnapshotin interfaceTextInputGeometry.Provider
-
getTextLength
public int getTextLength()The length of the caret's paragraph.
Returns
the length
- Specified by:
getTextLengthin interfaceTextInputClient
-
getTextRange
Part of the caret's paragraph.
Parameters
-
start: from -
end: to
Returns
the text
- Specified by:
getTextRangein interfaceTextInputClient
-
-
rectForOffset
public int[] rectForOffset(int offset) Where an offset of the caret's paragraph is on screen.
Parameters
offset: the offset
Returns
{x, y, width, height}in screen coordinates- Specified by:
rectForOffsetin interfaceTextInputClient
-
offsetAtPoint
public int offsetAtPoint(int x, int y) The offset in the caret's paragraph nearest a screen point.
Parameters
-
x: screen x -
y: screen y
Returns
the offset
- Specified by:
offsetAtPointin interfaceTextInputClient
-
-
selectionRects
public int[] selectionRects(int start, int end) The selection rectangles of a range of the caret's paragraph.
Parameters
-
start: from -
end: to
Returns
the rectangle from the start's caret to the end's, as
{x, y, w, h}- Specified by:
selectionRectsin interfaceTextInputClient
-
-
replaceRange
Replaces part of the caret's paragraph.
Parameters
-
start: from -
end: to -
text: the replacement
- Specified by:
replaceRangein interfaceTextInputClient
-
-
setSelectionRange
public void setSelectionRange(int start, int end) Selects part of the caret's paragraph.
Parameters
-
start: the anchor -
end: the caret
- Specified by:
setSelectionRangein interfaceTextInputClient
-
-