Interface ViewActions<PS,​SEG,​S>

    • Method Detail

      • isEditable

        default boolean isEditable()
        Indicates whether this text area can be edited by the user. Note that this property doesn't affect editing through the API.
      • setEditable

        default void setEditable​(boolean value)
        Sets the value of the property editable.
        Property description:
      • isWrapText

        default boolean isWrapText()
        When a run of text exceeds the width of the text region, then this property indicates whether the text should wrap onto another line.
      • setWrapText

        default void setWrapText​(boolean value)
        Sets the value of the property wrapText.
        Property description:
      • getMouseOverTextDelay

        default Duration getMouseOverTextDelay()
        Defines how long the mouse has to stay still over the text before a MouseOverTextEvent of type MOUSE_OVER_TEXT_BEGIN is fired on this text area. When set to null, no MouseOverTextEvents are fired on this text area.

        Default value is null.

      • setMouseOverTextDelay

        default void setMouseOverTextDelay​(Duration delay)
        Sets the value of the property mouseOverTextDelay.
        Property description:
      • isAutoScrollOnDragDesired

        default boolean isAutoScrollOnDragDesired()
        Indicates whether area should auto scroll towards a MouseEvent.MOUSE_DRAGGED event. This can be used when additional drag behavior is added on top of the area's default drag behavior and one does not want this auto scroll feature to occur. This flag should be set to the correct value before the end of the process InputMap.
      • setAutoScrollOnDragDesired

        default void setAutoScrollOnDragDesired​(boolean val)
        Sets the value of the property autoScrollOnDragDesired.
        Property description:
      • setOnOutsideSelectionMousePressed

        void setOnOutsideSelectionMousePressed​(EventHandler<MouseEvent> handler)
        Runs the EventHandler when the user pressed the mouse over unselected text within the area.

        By default, this will move the caret to the position where the mouse was pressed and clear out any selection via the code:

        
             e -> {
                 CharacterHit hit = hit(e.getX(), e.getY());
                 moveTo(hit.getInsertionIndex(), SelectionPolicy.CLEAR);
             }
         
        .
      • getOnOutsideSelectionMousePressed

        EventHandler<MouseEvent> getOnOutsideSelectionMousePressed()
        Gets the value of the property onOutsideSelectionMousePressed.
        Property description:
      • setOnInsideSelectionMousePressReleased

        void setOnInsideSelectionMousePressReleased​(EventHandler<MouseEvent> handler)
        Runs the EventHandler when the mouse is released in this scenario: the user has selected some text and then "clicked" the mouse somewhere in that selection (the use pressed the mouse, did not drag it, and released the mouse). Note: this consumer is run on MouseEvent.MOUSE_RELEASED, not MouseEvent.MOUSE_CLICKED.

        By default, this will move the caret to the position where the mouse was clicked and clear out any selection via the code:

        
             e -> {
                 CharacterHit hit = hit(e.getX(), e.getY());
                 moveTo(hit.getInsertionIndex(), SelectionPolicy.CLEAR);
             }
         
        .
      • getOnInsideSelectionMousePressReleased

        EventHandler<MouseEvent> getOnInsideSelectionMousePressReleased()
        Gets the value of the property onInsideSelectionMousePressReleased.
        Property description:
      • getOnNewSelectionDrag

        default Consumer<Point2D> getOnNewSelectionDrag()
        Runs the consumer when the mouse is dragged in this scenario: the user has pressed the mouse over some unselected text, and dragged the mouse to a new location within the area, but has not yet released the mouse. Each time the user drags the mouse without releasing it, this hook's consumer gets called.

        By default, this will create a new selection or NavigationActions.SelectionPolicy.ADJUST the current one to be bigger or smaller via the code:

        
             e -> {
                 CharacterHit hit = hit(e.getX(), e.getY());
                 moveTo(hit.getInsertionIndex(), SelectionPolicy.ADJUST);
             }
         
        .
      • setOnNewSelectionDrag

        default void setOnNewSelectionDrag​(Consumer<Point2D> consumer)
        Sets the value of the property onNewSelectionDrag.
        Property description:
      • setOnNewSelectionDragFinished

        void setOnNewSelectionDragFinished​(EventHandler<MouseEvent> handler)
        Runs the EventHandler when the mouse is released in this scenario: the user has pressed the mouse over some unselected text, and dragged the mouse to a new location within the area, and released the mouse.

        By default, this will NavigationActions.SelectionPolicy.ADJUST the current selection to be bigger or smaller via the code:

        
             e -> {
                 CharacterHit hit = hit(e.getX(), e.getY());
                 moveTo(hit.getInsertionIndex(), SelectionPolicy.ADJUST);
             }
         
        .
      • getOnNewSelectionDragFinished

        EventHandler<MouseEvent> getOnNewSelectionDragFinished()
        Gets the value of the property onNewSelectionDragFinished.
        Property description:
      • getOnSelectionDrag

        default Consumer<Point2D> getOnSelectionDrag()
        Runs the consumer when the mouse is dragged in this scenario: the user has selected some text, pressed the mouse on top of the selection, dragged it to a new location within the area, but has not yet released the mouse. Each time the user drags the mouse without releasing it, this hook's consumer gets called.

        By default, this will displace the caret to that position within the area via the code:

        
             p -> {
                 CharacterHit hit = hit(p.getX(), p.getY());
                 displaceCaret(hit.getInsertionIndex());
             }
         
        .
      • setOnSelectionDrag

        default void setOnSelectionDrag​(Consumer<Point2D> consumer)
        Sets the value of the property onSelectionDrag.
        Property description:
      • setOnSelectionDropped

        void setOnSelectionDropped​(EventHandler<MouseEvent> handler)
        Runs the EventHandler when the mouse is released in this scenario: the user has selected some text, pressed the mouse on top of the selection, dragged it to a new location within the area, and released the mouse within the area.

        By default, this will relocate the selected text to the character index where the mouse was released via the code:

        
             e -> {
                 CharacterHit hit = hit(e.getX(), e.getY());
                 moveSelectedText(hit.getInsertionIndex());
             }
         
        .
      • getOnSelectionDropped

        EventHandler<MouseEvent> getOnSelectionDropped()
        Gets the value of the property onSelectionDropped.
        Property description:
      • getParagraphGraphicFactory

        default IntFunction<? extends Node> getParagraphGraphicFactory()
        Gets the function that maps a line index to a node that is positioned to the left of the first character in a paragraph's text. Useful for toggle points or indicating the line's number via LineNumberFactory.
      • setParagraphGraphicFactory

        default void setParagraphGraphicFactory​(IntFunction<? extends Node> factory)
        Sets the value of the property paragraphGraphicFactory.
        Property description:
      • getContextMenu

        default ContextMenu getContextMenu()
        Gets the ContextMenu for the area, which is by default null.
      • setContextMenu

        default void setContextMenu​(ContextMenu menu)
      • getContextMenuXOffset

        default double getContextMenuXOffset()
        Gets the horizontal amount in pixels by which to offset the getContextMenu() when it is shown, which has a default value of 2.
      • setContextMenuXOffset

        default void setContextMenuXOffset​(double offset)
        Sets the value of the property contextMenuXOffset.
        Property description:
      • getContextMenuYOffset

        default double getContextMenuYOffset()
        Gets the vertical amount in pixels by which to offset the getContextMenu() when it is shown, which has a default value of 2.
      • setContextMenuYOffset

        default void setContextMenuYOffset​(double offset)
        Sets the value of the property contextMenuYOffset.
        Property description:
      • estimatedScrollXProperty

        Var<Double> estimatedScrollXProperty()
        The estimated scrollX value. This can be set in order to scroll the content. Value is only accurate when area does not wrap lines and uses the same font size throughout the entire area.
      • estimatedScrollYProperty

        Var<Double> estimatedScrollYProperty()
        The estimated scrollY value. This can be set in order to scroll the content. Value is only accurate when area does not wrap lines and uses the same font size throughout the entire area.
      • totalWidthEstimateProperty

        Val<Double> totalWidthEstimateProperty()
        The estimated width of the entire document. Accurate when area does not wrap lines and uses the same font size throughout the entire area. Value is only supposed to be set by the skin, not the user.
      • totalHeightEstimateProperty

        Val<Double> totalHeightEstimateProperty()
        The estimated height of the entire document. Accurate when area does not wrap lines and uses the same font size throughout the entire area. Value is only supposed to be set by the skin, not the user.
      • viewportDirtyEvents

        EventStream<?> viewportDirtyEvents()
        Returns an EventStream that emits a null value every time the viewport becomes dirty (e.g. the viewport's width, height, scaleX, scaleY, estimatedScrollX, or estimatedScrollY values change)
      • getVisibleParagraphs

        LiveList<Paragraph<PS,​SEG,​S>> getVisibleParagraphs()
        Gets the visible paragraphs, even the ones that are barely displayed.
      • getApplyParagraphStyle

        BiConsumer<TextFlow,​PS> getApplyParagraphStyle()
        Gets the style applicator.
      • getViewportHeight

        double getViewportHeight()
        Gets the height of the viewport and ignores the padding values added to the area.
      • firstVisibleParToAllParIndex

        default int firstVisibleParToAllParIndex()
        Returns the index of the first visible paragraph in the index system of TextEditingArea.getParagraphs().
      • lastVisibleParToAllParIndex

        default int lastVisibleParToAllParIndex()
        Returns the index of the last visible paragraph in the index system of TextEditingArea.getParagraphs().
      • hit

        CharacterHit hit​(double x,
                         double y)
        Helpful for determining which letter is at point x, y:
             
             StyledTextArea area = // creation code
             area.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
                 CharacterHit hit = area.hit(e.getX(), e.getY());
                 int characterPosition = hit.getInsertionIndex();
        
                 // move the caret to that character's position
                 area.moveTo(characterPosition, SelectionPolicy.CLEAR);
             }
         
      • lineIndex

        int lineIndex​(int paragraphIndex,
                      int columnPosition)
        Returns 0 if the given paragraph displays its content across only one line, or returns the index of the line on which the given column position appears if the paragraph spans multiple lines.
      • getParagraphLinesCount

        int getParagraphLinesCount​(int paragraphIndex)
        Gets the number of lines a paragraph spans when isWrapText() is true, or otherwise returns 1. CAUTION: the underlying TextFlow does not immediately account for changes in the stage's width when the paragraph in question is a multi-line paragraph and text wrap is on. After calling Window.setWidth(double), it may take anywhere between 150-300 milliseconds for TextFlow to account for this and return the correct line count for the given paragraph. Otherwise, it may return a skewed number, such as the total number of characters on the line.
      • getCaretBoundsOnScreen

        <T extends Node & CaretOptional<Bounds> getCaretBoundsOnScreen​(T caret)
        Using the paragraph index of the "all paragraph" index system, returns the bounds of a caret on the given paragraph or Optional.empty() if no caret is on that paragraph or the pragraph is not visible.
      • getCharacterBoundsOnScreen

        Optional<Bounds> getCharacterBoundsOnScreen​(int from,
                                                    int to)
        Gets the character bounds on screen
        Parameters:
        from - the start position
        to - the end position
        Returns:
        the bounds or Optional.empty() if line is not visible or the range is only a newline character.
      • getVisibleParagraphBoundsOnScreen

        Bounds getVisibleParagraphBoundsOnScreen​(int visibleParagraphIndex)
        Returns the bounds of the paragraph if it is visible or Optional.empty() if it's not. The returned bounds object will always be within the bounds of the area. In other words, it takes scrolling into account. Note: the bound's width will always equal the area's width, not necessarily the paragraph's real width (if it's short and doesn't take up all of the area's provided horizontal space or if it's long and spans outside of the area's width).
        Parameters:
        visibleParagraphIndex - the index in area's list of visible paragraphs.
      • getParagraphBoundsOnScreen

        Optional<Bounds> getParagraphBoundsOnScreen​(int paragraphIndex)
        Returns the bounds of the paragraph if it is visible or Optional.empty() if it's not. The returned bounds object will always be within the bounds of the area. In other words, it takes scrolling into account. Note: the bound's width will always equal the area's width, not necessarily the paragraph's real width (if it's short and doesn't take up all of the area's provided horizontal space or if it's long and spans outside of the area's width).
        Parameters:
        paragraphIndex - the index in area's list of paragraphs (visible and invisible).
      • showParagraphInViewport

        void showParagraphInViewport​(int paragraphIndex)
        Shows the paragraph somewhere in the viewport. If the line is already visible, no noticeable change occurs. If line is above the current view, it appears at the top of the viewport. If the line is below the current view, it appears at the bottom of the viewport.
      • showParagraphAtTop

        void showParagraphAtTop​(int paragraphIndex)
        Lays out the viewport so that the paragraph is the first line (top) displayed in the viewport. Note: if the given area does not have enough lines that follow the given line to span its entire height, the paragraph may not appear at the very top of the viewport. Instead, it may simply be shown in the viewport. For example, given an unwrapped area whose height could show 10 lines but whose content only has 3 lines, calling showParagraphAtTop(3) would be no different than showParagraphAtTop(1).
      • showParagraphAtBottom

        void showParagraphAtBottom​(int paragraphIndex)
        Lays out the viewport so that the paragraph is the last line (bottom) displayed in the viewport. Note: if the given area does not have enough lines preceding the given line to span its entire height, the paragraph may not appear at the very bottom of the viewport. Instead, it may appear towards the bottom of the viewport with some extra space following it. For example, given an unwrapped area whose height could show 10 lines but whose content only has 7 lines, calling showParagraphAtBottom(1) would be no different than calling showParagraphAtBottom(7).
      • showParagraphRegion

        void showParagraphRegion​(int paragraphIndex,
                                 Bounds region)
        Lays out the viewport so that the given bounds (according to the paragraph's coordinate system) within the given paragraph is visible in the viewport.
      • requestFollowCaret

        void requestFollowCaret()
        If the caret is not visible within the area's view, the area will scroll so that caret is visible in the next layout pass. Use this method when you wish to "follow the caret" (i.e. auto-scroll to caret) after making a change (add/remove/modify area's segments).
      • selectLine

        default void selectLine()
        Selects the current line of a multi-line paragraph.
      • hideContextMenu

        default void hideContextMenu()
        Hides the area's context menu if it is not null and it is showing.