Class GenericStyledArea<PS,​SEG,​S>

  • Type Parameters:
    PS - type of style that can be applied to paragraphs (e.g. TextFlow.
    SEG - type of segment used in Paragraph. Can be only text (plain or styled) or a type that combines text and other Nodes.
    S - type of style that can be applied to a segment.
    All Implemented Interfaces:
    javafx.css.Styleable, javafx.event.EventTarget, Virtualized, ClipboardActions<PS,​SEG,​S>, EditActions<PS,​SEG,​S>, TwoDimensional, NavigationActions<PS,​SEG,​S>, StyleActions<PS,​S>, TextEditingArea<PS,​SEG,​S>, UndoActions, ViewActions<PS,​SEG,​S>
    Direct Known Subclasses:
    StyledTextArea

    public class GenericStyledArea<PS,​SEG,​S>
    extends javafx.scene.layout.Region
    implements TextEditingArea<PS,​SEG,​S>, EditActions<PS,​SEG,​S>, ClipboardActions<PS,​SEG,​S>, NavigationActions<PS,​SEG,​S>, StyleActions<PS,​S>, UndoActions, ViewActions<PS,​SEG,​S>, TwoDimensional, Virtualized
    Text editing control that renders and edits a EditableStyledDocument. Accepts user input (keyboard, mouse) and provides API to assign style to text ranges. It is suitable for syntax highlighting and rich-text editors.

    Adding Scrollbars to the Area

    By default, scroll bars do not appear when the content spans outside of the viewport. To add scroll bars, the area needs to be wrapped in a VirtualizedScrollPane. For example,

    
     // shows area without scroll bars
     InlineCssTextArea area = new InlineCssTextArea();
    
     // add scroll bars that will display as needed
     VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);
    
     Parent parent = // creation code
     parent.getChildren().add(vsPane)
     

    Auto-Scrolling to the Caret

    Every time the underlying EditableStyledDocument changes via user interaction (e.g. typing) through the GenericStyledArea, the area will scroll to insure the caret is kept in view. However, this does not occur if changes are done programmatically. For example, let's say the area is displaying the bottom part of the area's EditableStyledDocument and some code changes something in the top part of the document that is not currently visible. If there is no call to requestFollowCaret() at the end of that code, the area will not auto-scroll to that section of the document. The change will occur, and the user will continue to see the bottom part of the document as before. If such a call is there, then the area will scroll to the top of the document and no longer display the bottom part of it.

    For example...

    
     // assuming the user is currently seeing the top of the area
    
     // then changing the bottom, currently not visible part of the area...
     int startParIdx = 40;
     int startColPosition = 2;
     int endParIdx = 42;
     int endColPosition = 10;
    
     // ...by itself will not scroll the viewport to where the change occurs
     area.replaceText(startParIdx, startColPosition, endParIdx, endColPosition, "replacement text");
    
     // adding this line after the last modification to the area will cause the viewport to scroll to that change
     // leaving the following line out will leave the viewport unaffected and the user will not notice any difference
     area.requestFollowCaret();
     

    Additionally, when overriding the default user-interaction behavior, remember to include a call to requestFollowCaret().

    Setting the area's UndoManager

    The default UndoManager can undo/redo either PlainTextChanges or RichTextChanges. To create your own specialized version that may use changes different than these (or a combination of these changes with others), create them using the convenient factory methods in UndoUtils.

    Overriding default keyboard behavior

    GenericStyledArea uses KEY_TYPED to handle ordinary character input and KEY_PRESSED to handle control key combinations (including Enter and Tab). To add or override some keyboard shortcuts, while keeping the rest in place, you would combine the default event handler with a new one that adds or overrides some of the default key combinations.

    For example, this is how to bind Ctrl+S to the save() operation:

    
     import static javafx.scene.input.KeyCode.*;
     import static javafx.scene.input.KeyCombination.*;
     import static org.fxmisc.wellbehaved.event.EventPattern.*;
     import static org.fxmisc.wellbehaved.event.InputMap.*;
    
     import org.fxmisc.wellbehaved.event.Nodes;
    
     // installs the following consume InputMap,
     // so that a CTRL+S event saves the document and consumes the event
     Nodes.addInputMap(area, consume(keyPressed(S, CONTROL_DOWN), event -> save()));
     

    Overriding default mouse behavior

    The area's default mouse behavior properly handles auto-scrolling and dragging the selected text to a new location. As such, some parts cannot be partially overridden without it affecting other behavior.

    The following lists either EventPatterns that cannot be overridden without negatively affecting the default mouse behavior or describe how to safely override things in a special way without disrupting the auto scroll behavior.

    CSS, Style Classes, and Pseudo Classes

    Refer to the RichTextFX CSS Reference Guide .

    Area Actions and Other Operations

    To distinguish the actual operations one can do on this area from the boilerplate methods within this area (e.g. properties and their getters/setters, etc.), look at the interfaces this area implements. Each lists and documents methods that fall under that category.

    To update multiple portions of the area's underlying document in one call, see createMultiChange().

    Calculating a Position Within the Area

    To calculate a position or index within the area, read through the javadoc of TwoDimensional and TwoDimensional.Bias. Also, read the difference between "position" and "index" in StyledDocument.getAbsolutePosition(int, int).

    See Also:
    EditableStyledDocument, TwoDimensional, TwoDimensional.Bias, VirtualFlow, VirtualizedScrollPane, Caret, Selection, CaretSelectionBind
    • Field Detail

      • EMPTY_RANGE

        public static final javafx.scene.control.IndexRange EMPTY_RANGE
        Index range [0, 0).
      • foldCheck

        protected boolean foldCheck
    • Constructor Detail

      • GenericStyledArea

        public GenericStyledArea​(PS initialParagraphStyle,
                                 java.util.function.BiConsumer<javafx.scene.text.TextFlow,​PS> applyParagraphStyle,
                                 S initialTextStyle,
                                 TextOps<SEG,​S> segmentOps,
                                 java.util.function.Function<StyledSegment<SEG,​S>,​javafx.scene.Node> nodeFactory)
        Creates a text area with empty text content.
        Parameters:
        initialParagraphStyle - style to use in places where no other style is specified (yet).
        applyParagraphStyle - function that, given a TextFlow node and a style, applies the style to the paragraph node. This function is used by the default skin to apply style to paragraph nodes.
        initialTextStyle - style to use in places where no other style is specified (yet).
        segmentOps - The operations which are defined on the text segment objects.
        nodeFactory - A function which is used to create the JavaFX scene nodes for a particular segment.
      • GenericStyledArea

        public GenericStyledArea​(PS initialParagraphStyle,
                                 java.util.function.BiConsumer<javafx.scene.text.TextFlow,​PS> applyParagraphStyle,
                                 S initialTextStyle,
                                 TextOps<SEG,​S> segmentOps,
                                 boolean preserveStyle,
                                 java.util.function.Function<StyledSegment<SEG,​S>,​javafx.scene.Node> nodeFactory)
        Same as GenericStyledArea(Object, BiConsumer, Object, TextOps, Function) but also allows one to specify whether the undo manager should be a plain or rich undo manager via preserveStyle.
        Parameters:
        initialParagraphStyle - style to use in places where no other style is specified (yet).
        applyParagraphStyle - function that, given a TextFlow node and a style, applies the style to the paragraph node. This function is used by the default skin to apply style to paragraph nodes.
        initialTextStyle - style to use in places where no other style is specified (yet).
        segmentOps - The operations which are defined on the text segment objects.
        preserveStyle - whether to use an undo manager that can undo/redo RichTextChanges or PlainTextChanges
        nodeFactory - A function which is used to create the JavaFX scene node for a particular segment.
      • GenericStyledArea

        public GenericStyledArea​(PS initialParagraphStyle,
                                 java.util.function.BiConsumer<javafx.scene.text.TextFlow,​PS> applyParagraphStyle,
                                 S initialTextStyle,
                                 EditableStyledDocument<PS,​SEG,​S> document,
                                 TextOps<SEG,​S> segmentOps,
                                 boolean preserveStyle,
                                 java.util.function.Function<StyledSegment<SEG,​S>,​javafx.scene.Node> nodeFactory)
        Creates an area with flexibility in all of its options.
        Parameters:
        initialParagraphStyle - style to use in places where no other style is specified (yet).
        applyParagraphStyle - function that, given a TextFlow node and a style, applies the style to the paragraph node. This function is used by the default skin to apply style to paragraph nodes.
        initialTextStyle - style to use in places where no other style is specified (yet).
        document - the document to render and edit
        segmentOps - The operations which are defined on the text segment objects.
        preserveStyle - whether to use an undo manager that can undo/redo RichTextChanges or PlainTextChanges
        nodeFactory - A function which is used to create the JavaFX scene node for a particular segment.
    • Method Detail

      • setEditable

        public void setEditable​(boolean value)
        Sets the value of the property editable.
        Specified by:
        setEditable in interface ViewActions<PS,​SEG,​S>
        Property description:
      • isEditable

        public boolean isEditable()
        Gets the value of the property editable.
        Specified by:
        isEditable in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setWrapText

        public void setWrapText​(boolean value)
        Sets the value of the property wrapText.
        Specified by:
        setWrapText in interface ViewActions<PS,​SEG,​S>
        Property description:
      • isWrapText

        public boolean isWrapText()
        Gets the value of the property wrapText.
        Specified by:
        isWrapText in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setUndoManager

        public void setUndoManager​(UndoManager undoManager)
        Description copied from interface: UndoActions
        Closes the current area's undo manager before setting it to the given one. Note: to create your own UndoManager, see the convenient factory methods in UndoUtils.
        Specified by:
        setUndoManager in interface UndoActions
        Parameters:
        undoManager - may be null in which case a no op undo manager will be set.
      • getLocale

        public java.util.Locale getLocale()
        This is used to determine word and sentence breaks while navigating or selecting. Override this method if your paragraph or text style accommodates Locales as well.
        Specified by:
        getLocale in interface TextEditingArea<PS,​SEG,​S>
        Returns:
        Locale.getDefault() by default
      • setLocale

        public void setLocale​(java.util.Locale editorLocale)
      • paragraphGraphicFactoryProperty

        public javafx.beans.property.ObjectProperty<java.util.function.IntFunction<? extends javafx.scene.Node>> paragraphGraphicFactoryProperty()
        Specified by:
        paragraphGraphicFactoryProperty in interface ViewActions<PS,​SEG,​S>
      • recreateParagraphGraphic

        public void recreateParagraphGraphic​(int parNdx)
      • getParagraphGraphic

        public javafx.scene.Node getParagraphGraphic​(int parNdx)
      • setPlaceholder

        public final void setPlaceholder​(javafx.scene.Node value)
        This Node is shown to the user, centered over the area, when the area has no text content.
        To customize the placeholder's layout override configurePlaceholder( Node )
      • setPlaceholder

        public void setPlaceholder​(javafx.scene.Node value,
                                   javafx.geometry.Pos where)
      • getPlaceholder

        public final javafx.scene.Node getPlaceholder()
        Gets the value of the property placeholder.
        Property description:
      • contextMenuObjectProperty

        public final javafx.beans.property.ObjectProperty<javafx.scene.control.ContextMenu> contextMenuObjectProperty()
        Specified by:
        contextMenuObjectProperty in interface ViewActions<PS,​SEG,​S>
      • setContextMenu

        public void setContextMenu​(javafx.scene.control.ContextMenu menu)
        Specified by:
        setContextMenu in interface ViewActions<PS,​SEG,​S>
      • getContextMenu

        public javafx.scene.control.ContextMenu getContextMenu()
        Description copied from interface: ViewActions
        Gets the ContextMenu for the area, which is by default null.
        Specified by:
        getContextMenu in interface ViewActions<PS,​SEG,​S>
      • isContextMenuPresent

        protected final boolean isContextMenuPresent()
      • setContextMenuXOffset

        public void setContextMenuXOffset​(double offset)
        Sets the value of the property contextMenuXOffset.
        Specified by:
        setContextMenuXOffset in interface ViewActions<PS,​SEG,​S>
        Property description:
      • getContextMenuXOffset

        public double getContextMenuXOffset()
        Gets the value of the property contextMenuXOffset.
        Specified by:
        getContextMenuXOffset in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setContextMenuYOffset

        public void setContextMenuYOffset​(double offset)
        Sets the value of the property contextMenuYOffset.
        Specified by:
        setContextMenuYOffset in interface ViewActions<PS,​SEG,​S>
        Property description:
      • getContextMenuYOffset

        public double getContextMenuYOffset()
        Gets the value of the property contextMenuYOffset.
        Specified by:
        getContextMenuYOffset in interface ViewActions<PS,​SEG,​S>
        Property description:
      • estimatedScrollXProperty

        public Var<java.lang.Double> estimatedScrollXProperty()
        Description copied from interface: ViewActions
        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.
        Specified by:
        estimatedScrollXProperty in interface ViewActions<PS,​SEG,​S>
        Specified by:
        estimatedScrollXProperty in interface Virtualized
      • estimatedScrollYProperty

        public Var<java.lang.Double> estimatedScrollYProperty()
        Description copied from interface: ViewActions
        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.
        Specified by:
        estimatedScrollYProperty in interface ViewActions<PS,​SEG,​S>
        Specified by:
        estimatedScrollYProperty in interface Virtualized
      • addCaret

        public final boolean addCaret​(CaretNode caret)
      • removeCaret

        public final boolean removeCaret​(CaretNode caret)
      • addSelection

        public final boolean addSelection​(Selection<PS,​SEG,​S> selection)
      • removeSelection

        public final boolean removeSelection​(Selection<PS,​SEG,​S> selection)
      • getOnOutsideSelectionMousePressed

        public final javafx.event.EventHandler<javafx.scene.input.MouseEvent> getOnOutsideSelectionMousePressed()
        Gets the value of the property onOutsideSelectionMousePressed.
        Specified by:
        getOnOutsideSelectionMousePressed in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setOnOutsideSelectionMousePressed

        public final void setOnOutsideSelectionMousePressed​(javafx.event.EventHandler<javafx.scene.input.MouseEvent> handler)
        Sets the value of the property onOutsideSelectionMousePressed.
        Specified by:
        setOnOutsideSelectionMousePressed in interface ViewActions<PS,​SEG,​S>
        Property description:
      • getOnInsideSelectionMousePressReleased

        public final javafx.event.EventHandler<javafx.scene.input.MouseEvent> getOnInsideSelectionMousePressReleased()
        Gets the value of the property onInsideSelectionMousePressReleased.
        Specified by:
        getOnInsideSelectionMousePressReleased in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setOnInsideSelectionMousePressReleased

        public final void setOnInsideSelectionMousePressReleased​(javafx.event.EventHandler<javafx.scene.input.MouseEvent> handler)
        Sets the value of the property onInsideSelectionMousePressReleased.
        Specified by:
        setOnInsideSelectionMousePressReleased in interface ViewActions<PS,​SEG,​S>
        Property description:
      • onNewSelectionDragProperty

        public final javafx.beans.property.ObjectProperty<java.util.function.Consumer<javafx.geometry.Point2D>> onNewSelectionDragProperty()
        Specified by:
        onNewSelectionDragProperty in interface ViewActions<PS,​SEG,​S>
      • getOnNewSelectionDragFinished

        public final javafx.event.EventHandler<javafx.scene.input.MouseEvent> getOnNewSelectionDragFinished()
        Gets the value of the property onNewSelectionDragFinished.
        Specified by:
        getOnNewSelectionDragFinished in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setOnNewSelectionDragFinished

        public final void setOnNewSelectionDragFinished​(javafx.event.EventHandler<javafx.scene.input.MouseEvent> handler)
        Sets the value of the property onNewSelectionDragFinished.
        Specified by:
        setOnNewSelectionDragFinished in interface ViewActions<PS,​SEG,​S>
        Property description:
      • onSelectionDragProperty

        public final javafx.beans.property.ObjectProperty<java.util.function.Consumer<javafx.geometry.Point2D>> onSelectionDragProperty()
        Specified by:
        onSelectionDragProperty in interface ViewActions<PS,​SEG,​S>
      • getOnSelectionDropped

        public final javafx.event.EventHandler<javafx.scene.input.MouseEvent> getOnSelectionDropped()
        Gets the value of the property onSelectionDropped.
        Specified by:
        getOnSelectionDropped in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setOnSelectionDropped

        public final void setOnSelectionDropped​(javafx.event.EventHandler<javafx.scene.input.MouseEvent> handler)
        Sets the value of the property onSelectionDropped.
        Specified by:
        setOnSelectionDropped in interface ViewActions<PS,​SEG,​S>
        Property description:
      • setAutoScrollOnDragDesired

        public void setAutoScrollOnDragDesired​(boolean val)
        Sets the value of the property autoScrollOnDragDesired.
        Specified by:
        setAutoScrollOnDragDesired in interface ViewActions<PS,​SEG,​S>
        Property description:
      • isAutoScrollOnDragDesired

        public boolean isAutoScrollOnDragDesired()
        Gets the value of the property autoScrollOnDragDesired.
        Specified by:
        isAutoScrollOnDragDesired in interface ViewActions<PS,​SEG,​S>
        Property description:
      • textProperty

        public final javafx.beans.value.ObservableValue<java.lang.String> textProperty()
        Specified by:
        textProperty in interface TextEditingArea<PS,​SEG,​S>
      • getDocument

        public final StyledDocument<PS,​SEG,​S> getDocument()
        Description copied from interface: TextEditingArea
        Rich-text content of this text-editing area. The returned document is immutable, it does not reflect subsequent edits of this text-editing area.
        Specified by:
        getDocument in interface TextEditingArea<PS,​SEG,​S>
      • lengthProperty

        public final javafx.beans.value.ObservableValue<java.lang.Integer> lengthProperty()
        Specified by:
        lengthProperty in interface TextEditingArea<PS,​SEG,​S>
      • totalWidthEstimateProperty

        public Val<java.lang.Double> totalWidthEstimateProperty()
        Description copied from interface: ViewActions
        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.
        Specified by:
        totalWidthEstimateProperty in interface ViewActions<PS,​SEG,​S>
        Specified by:
        totalWidthEstimateProperty in interface Virtualized
      • totalHeightEstimateProperty

        public Val<java.lang.Double> totalHeightEstimateProperty()
        Description copied from interface: ViewActions
        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.
        Specified by:
        totalHeightEstimateProperty in interface ViewActions<PS,​SEG,​S>
        Specified by:
        totalHeightEstimateProperty in interface Virtualized
      • viewportDirtyEvents

        public final EventStream<?> viewportDirtyEvents()
        Description copied from interface: ViewActions
        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)
        Specified by:
        viewportDirtyEvents in interface ViewActions<PS,​SEG,​S>
      • getApplyParagraphStyle

        public final java.util.function.BiConsumer<javafx.scene.text.TextFlow,​PS> getApplyParagraphStyle()
        Description copied from interface: ViewActions
        Gets the style applicator.
        Specified by:
        getApplyParagraphStyle in interface ViewActions<PS,​SEG,​S>
      • isPreserveStyle

        public final boolean isPreserveStyle()
        Description copied from interface: StyleActions
        Indicates whether style should be preserved on undo/redo (and in the future copy/paste and text move).
        Specified by:
        isPreserveStyle in interface StyleActions<PS,​SEG>
      • handleInputMethodEvent

        protected void handleInputMethodEvent​(javafx.scene.input.InputMethodEvent event)
      • configurePlaceholder

        protected void configurePlaceholder​(javafx.scene.Node placeholder)
        Override this to customize the placeholder's layout.
        The default position is centered over the area.
      • getViewportHeight

        public final double getViewportHeight()
        Description copied from interface: ViewActions
        Gets the height of the viewport and ignores the padding values added to the area.
        Specified by:
        getViewportHeight in interface ViewActions<PS,​SEG,​S>
      • hit

        public CharacterHit hit​(double x,
                                double y)
        Description copied from interface: ViewActions
        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);
             }
         
        Specified by:
        hit in interface ViewActions<PS,​SEG,​S>
      • lineIndex

        public final int lineIndex​(int paragraphIndex,
                                   int columnPosition)
        Description copied from interface: ViewActions
        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.
        Specified by:
        lineIndex in interface ViewActions<PS,​SEG,​S>
      • getParagraphLinesCount

        public int getParagraphLinesCount​(int paragraphIndex)
        Description copied from interface: ViewActions
        Gets the number of lines a paragraph spans when ViewActions.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.
        Specified by:
        getParagraphLinesCount in interface ViewActions<PS,​SEG,​S>
      • getCharacterBoundsOnScreen

        public java.util.Optional<javafx.geometry.Bounds> getCharacterBoundsOnScreen​(int from,
                                                                                     int to)
        Description copied from interface: ViewActions
        Gets the character bounds on screen
        Specified by:
        getCharacterBoundsOnScreen in interface ViewActions<PS,​SEG,​S>
        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.
      • getText

        public final java.lang.String getText​(int start,
                                              int end)
        Description copied from interface: TextEditingArea
        Returns text content of the given character range.
        Specified by:
        getText in interface TextEditingArea<PS,​SEG,​S>
      • getText

        public java.lang.String getText​(int paragraph)
        Description copied from interface: TextEditingArea
        Returns text content of the given paragraph.
        Specified by:
        getText in interface TextEditingArea<PS,​SEG,​S>
      • getText

        public java.lang.String getText​(javafx.scene.control.IndexRange range)
        Description copied from interface: TextEditingArea
        Returns text content of the given character range.
        Specified by:
        getText in interface TextEditingArea<PS,​SEG,​S>
      • getStyleOfChar

        public S getStyleOfChar​(int index)
        Description copied from interface: StyleActions
        Returns the style of the character with the given index. If index points to a line terminator character, the last style used in the paragraph terminated by that line terminator is returned.
        Specified by:
        getStyleOfChar in interface StyleActions<PS,​SEG>
      • getStyleAtPosition

        public S getStyleAtPosition​(int position)
        Description copied from interface: StyleActions
        Returns the style at the given position. That is the style of the character immediately preceding position, except when position points to a paragraph boundary, in which case it is the style at the beginning of the latter paragraph.

        In other words, most of the time getStyleAtPosition(p) is equivalent to getStyleOfChar(p-1), except when p points to a paragraph boundary, in which case it is equivalent to getStyleOfChar(p).

        Specified by:
        getStyleAtPosition in interface StyleActions<PS,​SEG>
      • getStyleRangeAtPosition

        public javafx.scene.control.IndexRange getStyleRangeAtPosition​(int position)
        Description copied from interface: StyleActions
        Returns the range of homogeneous style that includes the given position. If position points to a boundary between two styled ranges, then the range preceding position is returned. If position points to a boundary between two paragraphs, then the first styled range of the latter paragraph is returned.
        Specified by:
        getStyleRangeAtPosition in interface StyleActions<PS,​SEG>
      • getStyleOfChar

        public S getStyleOfChar​(int paragraph,
                                int index)
        Description copied from interface: StyleActions
        Returns the style of the character with the given index in the given paragraph. If index is beyond the end of the paragraph, the style at the end of line is returned. If index is negative, it is the same as if it was 0.
        Specified by:
        getStyleOfChar in interface StyleActions<PS,​SEG>
      • getStyleAtPosition

        public S getStyleAtPosition​(int paragraph,
                                    int position)
        Description copied from interface: StyleActions
        Returns the style at the given position in the given paragraph. This is equivalent to getStyleOfChar(paragraph, position-1).
        Specified by:
        getStyleAtPosition in interface StyleActions<PS,​SEG>
      • getStyleRangeAtPosition

        public javafx.scene.control.IndexRange getStyleRangeAtPosition​(int paragraph,
                                                                       int position)
        Description copied from interface: StyleActions
        Returns the range of homogeneous style that includes the given position in the given paragraph. If position points to a boundary between two styled ranges, then the range preceding position is returned.
        Specified by:
        getStyleRangeAtPosition in interface StyleActions<PS,​SEG>
      • getStyleSpans

        public StyleSpans<S> getStyleSpans​(int paragraph,
                                           int from,
                                           int to)
        Description copied from interface: StyleActions
        Returns the styles in the given character range of the given paragraph.
        Specified by:
        getStyleSpans in interface StyleActions<PS,​SEG>
      • getAbsolutePosition

        public int getAbsolutePosition​(int paragraphIndex,
                                       int columnIndex)
        Description copied from interface: TextEditingArea
        Returns the absolute position (i.e. the spot in-between characters) to the left of the given column in the given paragraph.

        For example, given a text with only one line "text" and the columnIndex value of 1, "position 1" would be returned:

          ┌ character index 0
          | ┌ character index 1
          | |   ┌ character index 3
          | |   |
          v v   v
        
         |t|e|x|t|
        
         ^ ^     ^
         | |     |
         | |     â”” position 4
         | â”” position 1
         â”” position 0
         

        Warning: Off-By-One errors can easily occur

        If the column index spans outside of the given paragraph's length, the returned value will pass on to the previous/next paragraph. In other words, given a document with two paragraphs (where the first paragraph's text is "some" and the second "thing"), then the following statements are true:

        • getAbsolutePosition(0, "some".length()) == 4 == getAbsolutePosition(1, -1)
        • getAbsolutePosition(0, "some".length() + 1) == 5 == getAbsolutePosition(1, 0)
        Specified by:
        getAbsolutePosition in interface TextEditingArea<PS,​SEG,​S>
        Parameters:
        paragraphIndex - The index of the paragraph from which to start.
        columnIndex - If positive, the index going forward (the given paragraph's line or the next one(s)). If negative, the index going backward (the previous paragraph's line(s)
      • position

        public TwoDimensional.Position position​(int row,
                                                int col)
        Description copied from interface: TwoDimensional
        Creates a two dimensional position in some entity (e.g. area, list of lists, list of some object with length) where the major value is the index within the outer list) and the minor value is either the index within the inner list or some amount of length in a list of objects that have length.
        Specified by:
        position in interface TwoDimensional
      • getVisibleParagraphBoundsOnScreen

        public javafx.geometry.Bounds getVisibleParagraphBoundsOnScreen​(int visibleParagraphIndex)
        Description copied from interface: ViewActions
        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).
        Specified by:
        getVisibleParagraphBoundsOnScreen in interface ViewActions<PS,​SEG,​S>
        Parameters:
        visibleParagraphIndex - the index in area's list of visible paragraphs.
      • getParagraphBoundsOnScreen

        public java.util.Optional<javafx.geometry.Bounds> getParagraphBoundsOnScreen​(int paragraphIndex)
        Description copied from interface: ViewActions
        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).
        Specified by:
        getParagraphBoundsOnScreen in interface ViewActions<PS,​SEG,​S>
        Parameters:
        paragraphIndex - the index in area's list of paragraphs (visible and invisible).
      • getCaretBoundsOnScreen

        public final <T extends javafx.scene.Node & Caret> java.util.Optional<javafx.geometry.Bounds> getCaretBoundsOnScreen​(T caret)
        Description copied from interface: ViewActions
        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.
        Specified by:
        getCaretBoundsOnScreen in interface ViewActions<PS,​SEG,​S>
      • scrollXBy

        public void scrollXBy​(double deltaX)
        Specified by:
        scrollXBy in interface Virtualized
      • scrollYBy

        public void scrollYBy​(double deltaY)
        Specified by:
        scrollYBy in interface Virtualized
      • scrollBy

        public void scrollBy​(javafx.geometry.Point2D deltas)
        Specified by:
        scrollBy in interface Virtualized
      • showParagraphInViewport

        public void showParagraphInViewport​(int paragraphIndex)
        Description copied from interface: ViewActions
        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.
        Specified by:
        showParagraphInViewport in interface ViewActions<PS,​SEG,​S>
      • showParagraphAtTop

        public void showParagraphAtTop​(int paragraphIndex)
        Description copied from interface: ViewActions
        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).
        Specified by:
        showParagraphAtTop in interface ViewActions<PS,​SEG,​S>
      • showParagraphAtBottom

        public void showParagraphAtBottom​(int paragraphIndex)
        Description copied from interface: ViewActions
        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).
        Specified by:
        showParagraphAtBottom in interface ViewActions<PS,​SEG,​S>
      • showParagraphRegion

        public void showParagraphRegion​(int paragraphIndex,
                                        javafx.geometry.Bounds region)
        Description copied from interface: ViewActions
        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.
        Specified by:
        showParagraphRegion in interface ViewActions<PS,​SEG,​S>
      • showParagraphAtCenter

        public void showParagraphAtCenter​(int paragraphIndex)
      • requestFollowCaret

        public void requestFollowCaret()
        Description copied from interface: ViewActions
        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).
        Specified by:
        requestFollowCaret in interface ViewActions<PS,​SEG,​S>
      • getCurrentLineStartInParargraph

        public int getCurrentLineStartInParargraph()
      • getCurrentLineEndInParargraph

        public int getCurrentLineEndInParargraph()
      • setLineHighlighterFill

        public void setLineHighlighterFill​(javafx.scene.paint.Paint highlight)
        The default fill is "highlighter" yellow. It can also be styled using CSS with:
        .styled-text-area .line-highlighter { -fx-fill: lime; }
        CSS selectors from Path, Shape, and Node can also be used.
      • isLineHighlighterOn

        public boolean isLineHighlighterOn()
      • setLineHighlighterOn

        public void setLineHighlighterOn​(boolean show)
        Highlights the line that the main caret is on.
        Line highlighting automatically follows the caret.
      • nextLine

        public void nextLine​(NavigationActions.SelectionPolicy selectionPolicy)
        Scrolls the text one line UP while maintaining the caret's position on screen, so that it is now on the NEXT line. Note: If the caret isn't visible then this is a noop.
      • prevLine

        public void prevLine​(NavigationActions.SelectionPolicy selectionPolicy)
        Scrolls the text one line DOWN while maintaining the caret's position on screen, so that it is now on the PREVIOUS line. Note: If the caret isn't visible then this is a noop.
      • displaceCaret

        public void displaceCaret​(int pos)
        Description copied from interface: TextEditingArea
        Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection's anchor or the selection. Do not confuse this method with NavigationActions.moveTo(int), which is the normal way of moving the caret. This method can be used to achieve the special case of positioning the caret outside or inside the selection, as opposed to always being at the boundary. Use with care.
        Specified by:
        displaceCaret in interface TextEditingArea<PS,​SEG,​S>
      • setStyle

        public void setStyle​(int from,
                             int to,
                             S style)
        Description copied from interface: StyleActions
        Sets style for the given character range.
        Specified by:
        setStyle in interface StyleActions<PS,​SEG>
      • setStyle

        public void setStyle​(int paragraph,
                             S style)
        Description copied from interface: StyleActions
        Sets style for the whole paragraph.
        Specified by:
        setStyle in interface StyleActions<PS,​SEG>
      • setStyle

        public void setStyle​(int paragraph,
                             int from,
                             int to,
                             S style)
        Description copied from interface: StyleActions
        Sets style for the given range relative in the given paragraph.
        Specified by:
        setStyle in interface StyleActions<PS,​SEG>
      • setStyleSpans

        public void setStyleSpans​(int from,
                                  StyleSpans<? extends S> styleSpans)
        Description copied from interface: StyleActions
        Set multiple style ranges at once. This is equivalent to
         for(StyleSpan<S> span: styleSpans) {
             setStyle(from, from + span.getLength(), span.getStyle());
             from += span.getLength();
         }
         
        but the actual implementation in SimpleEditableStyledDocument is more efficient.
        Specified by:
        setStyleSpans in interface StyleActions<PS,​SEG>
      • setStyleSpans

        public void setStyleSpans​(int paragraph,
                                  int from,
                                  StyleSpans<? extends S> styleSpans)
        Description copied from interface: StyleActions
        Set multiple style ranges of a paragraph at once. This is equivalent to
         for(StyleSpan<S> span: styleSpans) {
             setStyle(paragraph, from, from + span.getLength(), span.getStyle());
             from += span.getLength();
         }
         
        but the actual implementation in SimpleEditableStyledDocument is more efficient.
        Specified by:
        setStyleSpans in interface StyleActions<PS,​SEG>
      • setParagraphStyle

        public void setParagraphStyle​(int paragraph,
                                      PS paragraphStyle)
        Description copied from interface: StyleActions
        Sets style for the whole paragraph.
        Specified by:
        setParagraphStyle in interface StyleActions<PS,​SEG>
      • setTextInsertionStyle

        public final void setTextInsertionStyle​(S txtStyle)
        If you want to preset the style to be used for inserted text. Note that useInitialStyleForInsertion overrides this if true.
      • getTextInsertionStyle

        public final S getTextInsertionStyle()
      • setParagraphInsertionStyle

        public final void setParagraphInsertionStyle​(PS paraStyle)
        If you want to preset the style to be used. Note that useInitialStyleForInsertion overrides this if true.
      • getParagraphInsertionStyle

        public final PS getParagraphInsertionStyle()
      • replaceText

        public void replaceText​(int start,
                                int end,
                                java.lang.String text)
        Description copied from interface: TextEditingArea
        Replaces a range of characters with the given text. It must hold 0 <= start <= end <= getLength().
        Specified by:
        replaceText in interface TextEditingArea<PS,​SEG,​S>
        Parameters:
        start - Start index of the range to replace, inclusive.
        end - End index of the range to replace, exclusive.
        text - The text to put in place of the deleted range. It must not be null.
      • replace

        public void replace​(int start,
                            int end,
                            SEG seg,
                            S style)
        Description copied from interface: TextEditingArea
        Replaces a range of characters with the given segment. It must hold 0 <= start <= end <= getLength().
        Specified by:
        replace in interface TextEditingArea<PS,​SEG,​S>
        Parameters:
        start - Start index of the range to replace, inclusive.
        end - End index of the range to replace, exclusive.
        seg - The seg to put in place of the deleted range. It must not be null.
      • foldSelectedParagraphs

        protected void foldSelectedParagraphs​(java.util.function.UnaryOperator<PS> styleMixin)
        Convenience method to fold (hide/collapse) the currently selected paragraphs, into (i.e. excluding) the first paragraph of the range.
        Parameters:
        styleMixin - Given a paragraph style PS, return a new PS that will activate folding.

        See fold(int, int, UnaryOperator) for more info.

      • foldParagraphs

        protected void foldParagraphs​(int start,
                                      int end,
                                      java.util.function.UnaryOperator<PS> styleMixin)
        Folds (hides/collapses) paragraphs from start to end, into (i.e. excluding) the first paragraph of the range.
        Parameters:
        styleMixin - Given a paragraph style PS, return a new PS that will activate folding.

        See fold(int, int, UnaryOperator) for more info.

      • fold

        protected void fold​(int startPos,
                            int endPos,
                            java.util.function.UnaryOperator<PS> styleMixin)
        Folds (hides/collapses) paragraphs from character position startPos to endPos, into (i.e. excluding) the first paragraph of the range.

        Folding is achieved with the help of paragraph styling, which is applied to the paragraph's TextFlow object through the applyParagraphStyle BiConsumer (supplied in the constructor to GenericStyledArea). When applyParagraphStyle is to apply fold styling it just needs to set the TextFlow's visibility to collapsed for it to be folded. See InlineCssTextArea, StyleClassedTextArea, and RichTextDemo for different ways of doing this. Also read the GitHub Wiki.

        The UnaryOperator styleMixin must return a different paragraph style Object to what was submitted.

        Parameters:
        styleMixin - Given a paragraph style PS, return a new PS that will activate folding.
      • unfoldParagraphs

        protected void unfoldParagraphs​(int startingFrom,
                                        java.util.function.Predicate<PS> isFolded,
                                        java.util.function.UnaryOperator<PS> styleMixin)
        Unfolds paragraphs startingFrom onwards for the currently folded block.

        The UnaryOperator styleMixin must return a different paragraph style Object to what was submitted.

        Parameters:
        isFolded - Given a paragraph style PS check if it's folded.
        styleMixin - Given a paragraph style PS, return a new PS that excludes fold styling.
      • setAutoHeight

        public void setAutoHeight​(boolean value)
        Sets the value of the property autoHeight.
        Property description:
      • isAutoHeight

        public boolean isAutoHeight()
        Gets the value of the property autoHeight.
        Property description:
      • computePrefHeight

        protected double computePrefHeight​(double width)
        Overrides:
        computePrefHeight in class javafx.scene.layout.Region
      • layoutChildren

        protected void layoutChildren()
        Overrides:
        layoutChildren in class javafx.scene.Parent
      • getCssMetaData

        public java.util.List<javafx.css.CssMetaData<? extends javafx.css.Styleable,​?>> getCssMetaData()
        Specified by:
        getCssMetaData in interface javafx.css.Styleable
        Overrides:
        getCssMetaData in class javafx.scene.layout.Region
      • getClassCssMetaData

        public static java.util.List<javafx.css.CssMetaData<? extends javafx.css.Styleable,​?>> getClassCssMetaData()