9090import org .reactfx .value .Var ;
9191
9292/**
93- * Text editing control. Accepts user input (keyboard, mouse) and
94- * provides API to assign style to text ranges. It is suitable for
93+ * Text editing control that renders and edits a {@link EditableStyledDocument}.
94+ *
95+ * Accepts user input (keyboard, mouse) and provides API to assign style to text ranges. It is suitable for
9596 * syntax highlighting and rich-text editors.
9697 *
9798 * <h3>Adding Scrollbars to the Area</h3>
9899 *
99- * <p>The scroll bars no longer appear when the content spans outside
100- * of the viewport. To add scroll bars, the area needs to be wrapped in
101- * a {@link VirtualizedScrollPane}. For example, </p>
102- * <pre>
103- * {@code
100+ * <p>By default, scroll bars do not appear when the content spans outside of the viewport.
101+ * To add scroll bars, the area needs to be wrapped in a {@link VirtualizedScrollPane}. For example, </p>
102+ * <pre><code>
104103 * // shows area without scroll bars
105104 * InlineCssTextArea area = new InlineCssTextArea();
106105 *
107106 * // add scroll bars that will display as needed
108- * VirtualizedScrollPane< InlineCssTextArea> vsPane = new VirtualizedScrollPane(area);
107+ * VirtualizedScrollPane< InlineCssTextArea> vsPane = new VirtualizedScrollPane<> (area);
109108 *
110- * Parent parent = //;
109+ * Parent parent = // creation code
111110 * parent.getChildren().add(vsPane)
112- * }
113- * </pre>
111+ * </code></pre>
114112 *
115113 * <h3>Auto-Scrolling to the Caret</h3>
116114 *
117115 * <p>Every time the underlying {@link EditableStyledDocument} changes via user interaction (e.g. typing) through
118- * the {@code StyledTextArea }, the area will scroll to insure the caret is kept in view. However, this does not
116+ * the {@code GenericStyledArea }, the area will scroll to insure the caret is kept in view. However, this does not
119117 * occur if changes are done programmatically. For example, let's say the area is displaying the bottom part
120118 * of the area's {@link EditableStyledDocument} and some code changes something in the top part of the document
121119 * that is not currently visible. If there is no call to {@link #requestFollowCaret()} at the end of that code,
122120 * the area will not auto-scroll to that section of the document. The change will occur, and the user will continue
123121 * to see the bottom part of the document as before. If such a call is there, then the area will scroll
124122 * to the top of the document and no longer display the bottom part of it.</p>
123+ * <p>For example...</p>
124+ * <pre><code>
125+ * // assuming the user is currently seeing the top of the area
126+ *
127+ * // then changing the bottom, currently not visible part of the area...
128+ * int startParIdx = 40;
129+ * int startColPosition = 2;
130+ * int endParIdx = 42;
131+ * int endColPosition = 10;
132+ *
133+ * // ...by itself will not scroll the viewport to where the change occurs
134+ * area.replaceText(startParIdx, startColPosition, endParIdx, endColPosition, "replacement text");
135+ *
136+ * // adding this line after the last modification to the area will cause the viewport to scroll to that change
137+ * // leaving the following line out will leave the viewport unaffected and the user will not notice any difference
138+ * area.requestFollowCaret();
139+ * </code></pre>
125140 *
126141 * <p>Additionally, when overriding the default user-interaction behavior, remember to include a call
127142 * to {@link #requestFollowCaret()}.</p>
136151 *
137152 * <h3>Overriding default keyboard behavior</h3>
138153 *
139- * {@code StyledTextArea } uses {@code KEY_TYPED} handler to handle ordinary
140- * character input and {@code KEY_PRESSED} handler to handle control key
154+ * {@code GenericStyledArea } uses {@link javafx.scene.input.KeyEvent# KEY_TYPED KEY_TYPED} to handle ordinary
155+ * character input and {@link javafx.scene.input.KeyEvent# KEY_PRESSED KEY_PRESSED} to handle control key
141156 * combinations (including Enter and Tab). To add or override some keyboard
142157 * shortcuts, while keeping the rest in place, you would combine the default
143158 * event handler with a new one that adds or overrides some of the default
144- * key combinations. This is how to bind {@code Ctrl+S} to the {@code save()}
145- * operation:
146- * <pre>
147- * {@code
159+ * key combinations.
160+ * <p>
161+ * For example, this is how to bind {@code Ctrl+S} to the {@code save()} operation:
162+ * </p>
163+ * <pre><code>
148164 * import static javafx.scene.input.KeyCode.*;
149165 * import static javafx.scene.input.KeyCombination.*;
150166 * import static org.fxmisc.wellbehaved.event.EventPattern.*;
151167 * import static org.fxmisc.wellbehaved.event.InputMap.*;
152168 *
153169 * import org.fxmisc.wellbehaved.event.Nodes;
154170 *
155- * Nodes.addInputMap(area, consume(keyPressed(S, CONTROL_DOWN), event -> save()));
156- * }
157- * </pre>
171+ * // installs the following consume InputMap,
172+ * // so that a CTRL+S event saves the document and consumes the event
173+ * Nodes.addInputMap(area, consume(keyPressed(S, CONTROL_DOWN), event -> save()));
174+ * </code></pre>
158175 *
159176 * <h3>Overriding default mouse behavior</h3>
160177 *
161178 * The area's default mouse behavior properly handles auto-scrolling and dragging the selected text to a new location.
162179 * As such, some parts cannot be partially overridden without it affecting other behavior.
163180 *
164- * <p>The following lists either {@link org.fxmisc.wellbehaved.event.EventPattern}s that cannot be overridden without
165- * negatively affecting the default mouse behavior or describe how to safely override things in a special way without
166- * disrupting the auto scroll behavior.</p>
181+ * <p>The following lists either {@link org.fxmisc.wellbehaved.event.EventPattern}s that cannot be
182+ * overridden without negatively affecting the default mouse behavior or describe how to safely override things
183+ * in a special way without disrupting the auto scroll behavior.</p>
167184 * <ul>
168185 * <li>
169186 * <em>First (1 click count) Primary Button Mouse Pressed Events:</em>
227244 * </li>
228245 * </ul>
229246 *
247+ * <h3>CSS, Style Classes, and Pseudo Classes</h3>
248+ * <p>
249+ * Refer to the <a href="https://github.com/FXMisc/RichTextFX/wiki/RichTextFX-CSS-Reference-Guide">
250+ * RichTextFX CSS Reference Guide
251+ * </a>.
252+ * </p>
253+ *
254+ * <h3>Area Actions and Other Operations</h3>
255+ * <p>
256+ * To distinguish the actual operations one can do on this area from the boilerplate methods
257+ * within this area (e.g. properties and their getters/setters, etc.), look at the interfaces
258+ * this area implements. Each lists and documents methods that fall under that category.
259+ * </p>
260+ *
261+ * <h3>Calculating a Position Within the Area</h3>
262+ * <p>
263+ * To calculate a position or index within the area, read through the javadoc of
264+ * {@link org.fxmisc.richtext.model.TwoDimensional} and {@link org.fxmisc.richtext.model.TwoDimensional.Bias}.
265+ * Also, read the difference between "position" and "index" in
266+ * {@link org.fxmisc.richtext.model.StyledDocument#getAbsolutePosition(int, int)}.
267+ * </p>
268+ *
269+ * @see EditableStyledDocument
270+ * @see TwoDimensional
271+ * @see org.fxmisc.richtext.model.TwoDimensional.Bias
272+ * @see VirtualFlow
273+ * @see VirtualizedScrollPane
274+ * @see Caret
275+ * @see Selection
276+ * @see CaretSelectionBind
230277 *
231278 * @param <PS> type of style that can be applied to paragraphs (e.g. {@link TextFlow}.
232279 * @param <SEG> type of segment used in {@link Paragraph}. Can be only text (plain or styled) or
@@ -586,6 +633,20 @@ public GenericStyledArea(@NamedArg("initialParagraphStyle") PS initialParagraphS
586633 this (initialParagraphStyle , applyParagraphStyle , initialTextStyle , segmentOps , true , nodeFactory );
587634 }
588635
636+ /**
637+ * Same as {@link #GenericStyledArea(Object, BiConsumer, Object, TextOps, Function)} but also allows one
638+ * to specify whether the undo manager should be a plain or rich undo manager via {@code preserveStyle}.
639+ *
640+ * @param initialParagraphStyle style to use in places where no other style is specified (yet).
641+ * @param applyParagraphStyle function that, given a {@link TextFlow} node and
642+ * a style, applies the style to the paragraph node. This function is
643+ * used by the default skin to apply style to paragraph nodes.
644+ * @param initialTextStyle style to use in places where no other style is specified (yet).
645+ * @param segmentOps The operations which are defined on the text segment objects.
646+ * @param preserveStyle whether to use an undo manager that can undo/redo {@link RichTextChange}s or
647+ * {@link PlainTextChange}s
648+ * @param nodeFactory A function which is used to create the JavaFX scene node for a particular segment.
649+ */
589650 public GenericStyledArea (@ NamedArg ("initialParagraphStyle" ) PS initialParagraphStyle ,
590651 @ NamedArg ("applyParagraphStyle" ) BiConsumer <TextFlow , PS > applyParagraphStyle ,
591652 @ NamedArg ("initialTextStyle" ) S initialTextStyle ,
@@ -598,8 +659,8 @@ public GenericStyledArea(@NamedArg("initialParagraphStyle") PS initialParagraphS
598659
599660 /**
600661 * The same as {@link #GenericStyledArea(Object, BiConsumer, Object, TextOps, Function)} except that
601- * this constructor can be used to create another {@code GenericStyledArea} object that
602- * shares the same {@link EditableStyledDocument}.
662+ * this constructor can be used to create another {@code GenericStyledArea} that renders and edits the same
663+ * {@link EditableStyledDocument} or when one wants to use a custom {@link EditableStyledDocument} implementation .
603664 */
604665 public GenericStyledArea (
605666 @ NamedArg ("initialParagraphStyle" ) PS initialParagraphStyle ,
@@ -612,6 +673,20 @@ public GenericStyledArea(
612673
613674 }
614675
676+ /**
677+ * Creates an area with flexibility in all of its options.
678+ *
679+ * @param initialParagraphStyle style to use in places where no other style is specified (yet).
680+ * @param applyParagraphStyle function that, given a {@link TextFlow} node and
681+ * a style, applies the style to the paragraph node. This function is
682+ * used by the default skin to apply style to paragraph nodes.
683+ * @param initialTextStyle style to use in places where no other style is specified (yet).
684+ * @param document the document to render and edit
685+ * @param segmentOps The operations which are defined on the text segment objects.
686+ * @param preserveStyle whether to use an undo manager that can undo/redo {@link RichTextChange}s or
687+ * {@link PlainTextChange}s
688+ * @param nodeFactory A function which is used to create the JavaFX scene node for a particular segment.
689+ */
615690 public GenericStyledArea (
616691 @ NamedArg ("initialParagraphStyle" ) PS initialParagraphStyle ,
617692 @ NamedArg ("applyParagraphStyle" ) BiConsumer <TextFlow , PS > applyParagraphStyle ,
@@ -835,9 +910,13 @@ TwoDimensional.Position currentLine() {
835910 return _position (parIdx , lineIdx );
836911 }
837912
838- public final int lineIndex (int paragraphIndex , int column ) {
913+ /**
914+ * Returns 0 if the given paragraph displays its content across only one line, or returns the index
915+ * of the line on which the given column position appears if the paragraph spans multiple lines.
916+ */
917+ public final int lineIndex (int paragraphIndex , int columnPosition ) {
839918 Cell <Paragraph <PS , SEG , S >, ParagraphBox <PS , SEG , S >> cell = virtualFlow .getCell (paragraphIndex );
840- return cell .getNode ().getCurrentLineIndex (column );
919+ return cell .getNode ().getCurrentLineIndex (columnPosition );
841920 }
842921
843922 TwoDimensional .Position _position (int par , int line ) {
@@ -1211,6 +1290,9 @@ public void replace(int start, int end, StyledDocument<PS, SEG, S> replacement)
12111290 * *
12121291 * ********************************************************************** */
12131292
1293+ /**
1294+ * Disposes this area, preventing memory leaks.
1295+ */
12141296 public void dispose () {
12151297 subscriptions .unsubscribe ();
12161298 virtualFlow .dispose ();
0 commit comments