You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-53Lines changed: 45 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,22 @@
1
1
RichTextFX
2
2
==========
3
3
4
-
RichTextFX provides a text area for JavaFX with API to style ranges of text. It is intended as a base for rich-text editors and code editors with syntax highlighting.
4
+
RichTextFX provides a memory-efficient text area for JavaFX that allows the developer to style ranges of text, display custom objects in-line (no more HTMLEditor), and override the default behavior only where necessary without overriding any other part of the behavior.
5
+
6
+
It does not follow the MVC paradigm as this prevented access to view-specific API (e.g., getting the bounds of the caret/selection/characters, scrolling by some amount, .
7
+
8
+
It is intended as a base for rich-text editors and code editors with syntax highlighting. Since it is a base, a number of suggested features (specific syntax highlighters, search-and-replace, specific support for hyperlinks, etc.) will not be implemented directly in this project. Rather, developers can implement these on top of RichTextFX and submit their work as a PR to the `richtextfx-demos` package.
9
+
10
+
For a greater explanation of RichTextFX, its design principles, how it works, and how to style its areas via CSS, please [see the wiki](https://github.com/TomasMikula/RichTextFX/wiki)
5
11
6
12
*[Who uses RichTextFX?](#who-uses-richtextfx)
7
13
*[Features](#features)
8
14
*[Flavors](#flavors)
9
-
*[StyleClassedTextArea](#styleclassedtextarea)
10
-
*[CodeArea](#codearea)
11
-
*[InlineCssTextArea](#inlinecsstextarea)
12
-
*[InlineStyleTextArea](#inlinestyletextarea)
15
+
*[GenericStyledArea (Base area class requiring customization)](#genericstyledarea)
*[Highlighting of Java keywords](#automatic-highlighting-of-java-keywords)
@@ -45,88 +52,73 @@ If you use RichTextFX in an interesting project, I would like to know!
45
52
Features
46
53
--------
47
54
48
-
* Assign arbitrary styles to arbitrary ranges of text.
55
+
* Assign arbitrary styles to arbitrary ranges of text. A style can be an object, a CSS string, or a style class string.
49
56
* Display line numbers or, more generally, any graphic in front of each paragraph. Can be used to show breakpoint toggles on each line of code.
57
+
* Support for displaying other `Node`s in-line
50
58
* Positioning a popup window relative to the caret or selection. Useful e.g. to position an autocompletion box.
51
59
* Getting the character index under the mouse when the mouse stays still over the text for a specified period of time. Useful for displaying tooltips depending on the word under the mouse.
60
+
* Overriding the default behavior only where necessary without overriding any other part.
52
61
53
62
54
63
Flavors
55
64
-------
56
65
57
-
### StyleClassedTextArea
66
+
The following explains the different rich text area classes. The first one is the base class from which all others extend: it needs further customization before it can be used but provides all aspects of the project's features. The later ones extend this base class in various ways to provide out-of-box functionality for specific use cases. **Most will use one of these subclasses.**
58
67
59
-
`StyleClassedTextArea` lets you assign style classes to ranges of text. You can define the style classes in your stylesheet.
68
+
### GenericStyledArea
60
69
61
-
Example.java:
70
+
`GenericStyledArea` allows one to inline custom objects into the area alongside of text. As such, it uses generics and functional programming to accomplish this task in a completely type-safe way.
62
71
63
-
```java
64
-
area.setStyleClass(from, to, "red");
65
-
```
72
+
It has three parameter types:
73
+
-`PS`, the paragraph style. This can be used for text alignment or setting the background color for the entire paragraph. A paragraph is either one line when text wrap is off or a long text displayed over multiple lines in a narrow viewport when text wrap is on,
74
+
-`SEG`, the segment object. This specifies what immutable object to store in the model part of the area: text, hyperlinks, images, emojis, or any combination thereof.
75
+
-`S`, the segment style. This can be used for text and object styling. Usually, this will be a CSS style or CSS style class.
66
76
67
-
example.css:
77
+
Functional programming via lambdas specify how to apply styles, how to create a `Node` for a given segment, and how to operate on a given segment (e.g., getting its length, combining it with another segment, etc.).
68
78
69
-
```css
70
-
.red { -fx-fill: red; }
71
-
```
79
+
`GenericStyledArea` is used in the [Rich-text demo](#rich-text-editor) below.
72
80
73
-
This renders the text in the range `[from, to)` in red.
81
+
See the wiki for a basic pattern that one must follow to implement custom objects correctly.
74
82
75
-
Note that the style classes are assigned to instances of [Text](http://download.java.net/jdk8/jfxdocs/javafx/scene/text/Text.html), so you can specify any [CSS properties applicable to a Text node](http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#text).
83
+
### StyledTextArea
76
84
77
-
#### CodeArea
85
+
`StyledTextArea<PS, S>`, or one of its subclasses below, is the area you will most likely use if you don't need to display custom objects in your area.
78
86
79
-
`CodeArea` is a variant of `StyleClassedTextArea` that uses a fixed width font by default, making it a convenient base for source code editors. `CodeArea` is used in the [Java Keywords demo](#automatic-highlighting-of-java-keywords) below.
87
+
It extends `GenericStyledArea<PS, StyledText<S>, S>>`. `StyledText` is simply a text (`String`) and a style object (`S`). A slightly-enhanced [JavaFX `Text`](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/text/Text.html) node is used to display the `StyledText<S>`, so you can style it using [its CSS properties](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#text) and additional RichTextFX-specific CSS (see the wiki for more details).
88
+
89
+
It properly handles the aforementioned functional programming to properly display and operate on `StyledText<S>` objects.
80
90
91
+
The style object (`S`) can either be a CSS String (`-fx-fill: red;`), a CSS styleclass (`.red { -fx-fill: red; }`), or an object that handles this in a different way. Since most will use either the CSS String or CSS style class approach, there are two subclasses that already handle this correctly.
81
92
82
93
### InlineCssTextArea
83
94
84
-
`InlineCssTextArea`lets you specify inline CSS for a range of text.
95
+
`InlineCssTextArea`uses the `Node#setStyle(String cssStyle)` method to style `Text` objects:
85
96
86
97
```java
87
98
area.setStyle(from, to, "-fx-font-weight: bold;");
88
99
```
89
100
90
-
Again, you can use any CSS properties applicable to a `Text` node.
91
-
92
-
93
-
### InlineStyleTextArea
101
+
### StyleClassedTextArea
94
102
95
-
`InlineStyleTextArea<S>` is a more general version of `InlineCssTextArea`. In the end, there is still inline CSS assigned to `Text`nodes, but instead of using the CSS string directly, you use an instance of your custom style representation `S` and provide a way (function) to convert `S` to CSS string in `InlineStyleTextArea` constructor.
103
+
`StyleClassedTextArea` uses the `Node#setStyleClass(String styleClass) method to style `Text` objects. You can define the style classes in your stylesheet.
The first constructor argument is the default style to use for ranges of text where you don't set the style explicitly. The second constructor argument is the function to convert the custom style representation to CSS.
113
-
114
-
You then assign an instance of your custom style representation to a range of text.
111
+
Example.java:
115
112
116
113
```java
117
-
MyStyleInfo styleInfo =...;
118
-
119
-
area.setStyle(from, to, styleInfo);
114
+
area.setStyleClass(from, to, "red");
120
115
```
121
116
122
-
You appreciate the benefits of this approach over `InlineCssTextArea` when you need to query the style used at a given position in text - you get back an instance of your style representation instead of a CSS string.
This renders the text in the range `[from, to)` in red.
127
118
128
-
`InlineStyleTextArea` is used in the [Rich-text demo](#rich-text-editor) below.
119
+
#### CodeArea
129
120
121
+
`CodeArea` is a variant of `StyleClassedTextArea` that uses a fixed width font by default, making it a convenient base for source code editors. `CodeArea` is used in the [Java Keywords demo](#automatic-highlighting-of-java-keywords) below.
130
122
131
123
Requirements
132
124
------------
@@ -141,7 +133,7 @@ Demos
141
133
142
134
### Automatic highlighting of Java keywords
143
135
144
-

136
+

145
137
146
138
#### Run using the pre-built JAR
147
139
@@ -191,7 +183,7 @@ Similar to the [Java Keywords](#automatic-highlighting-of-java-keywords) demo ab
191
183
192
184
### Rich-text editor
193
185
194
-

186
+

195
187
196
188
#### Run using the pre-built JAR
197
189
[Download](https://github.com/TomasMikula/RichTextFX/releases/download/v0.6.10/richtextfx-demos-fat-0.6.10.jar) the pre-built "fat" JAR file and run
@@ -211,7 +203,7 @@ Similar to the [Java Keywords](#automatic-highlighting-of-java-keywords) demo ab
211
203
212
204
When the mouse pauses over the text area, you can get index of the character under the mouse. This allows you to implement, for example, custom tooltips whose content depends on the text under the mouse.
213
205
214
-

206
+

215
207
216
208
#### Run using the pre-built JAR
217
209
[Download](https://github.com/TomasMikula/RichTextFX/releases/download/v0.6.10/richtextfx-demos-fat-0.6.10.jar) the pre-built "fat" JAR file and run
0 commit comments