Skip to content

Commit 40e3e03

Browse files
committed
Merge pull request #83 from UzielSilva/SetLineStyleSheet
Change stylesheet management for line numbers.
2 parents 0bf74d5 + aa31d64 commit 40e3e03

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/JavaKeywords.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ public static void main(String[] args) {
8484
@Override
8585
public void start(Stage primaryStage) {
8686
CodeArea codeArea = new CodeArea();
87-
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
87+
String stylesheet = JavaKeywords.class.getResource("java-keywords.css").toExternalForm();
88+
89+
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea,stylesheet));
8890
codeArea.textProperty().addListener((obs, oldText, newText) -> {
8991
codeArea.setStyleSpans(0, computeHighlighting(newText));
9092
});
9193
codeArea.replaceText(0, 0, sampleCode);
9294

9395
Scene scene = new Scene(new StackPane(codeArea), 600, 400);
94-
scene.getStylesheets().add(JavaKeywords.class.getResource("java-keywords.css").toExternalForm());
96+
scene.getStylesheets().add(stylesheet);
9597
primaryStage.setScene(scene);
9698
primaryStage.setTitle("Java Keywords Demo");
9799
primaryStage.show();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
.keyword {
2-
-fx-fill: brown;
2+
-fx-fill: #8a6;
33
-fx-font-weight: bold;
4+
}
5+
.default {
6+
-fx-fill: #666;
7+
}
8+
.lineno {
9+
-fx-font-family: monospace;
10+
-fx-background-color: #eee;
11+
-fx-text-fill: #666;
12+
-fx-padding: 0 5px;
13+
}
14+
.code-area {
15+
-fx-font-family: monospace;
16+
-fx-background-color: #eee;
417
}

richtextfx/src/main/java/org/fxmisc/richtext/LineNumberFactory.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.fxmisc.richtext;
22

33
import java.util.function.IntFunction;
4+
import java.util.function.Supplier;
45

56
import javafx.scene.Node;
67
import javafx.scene.control.Label;
@@ -12,21 +13,27 @@ public class LineNumberFactory implements IntFunction<Node> {
1213

1314
private static final String STYLESHEET = LineNumberFactory.class.getResource("lineno.css").toExternalForm();
1415

16+
public static IntFunction<Node> get(StyledTextArea<?> area,String customStylesheet) {
17+
return new LineNumberFactory(area,customStylesheet);
18+
}
1519
public static IntFunction<Node> get(StyledTextArea<?> area) {
16-
return new LineNumberFactory(area);
20+
return new LineNumberFactory(area,STYLESHEET);
1721
}
1822

1923
private final EventStream<Integer> nParagraphs;
2024

21-
private LineNumberFactory(StyledTextArea<?> area) {
25+
private LineNumberFactory(StyledTextArea<?> area,String Stylesheet) {
2226
nParagraphs = EventStreams.sizeOf(area.getParagraphs());
27+
this.Stylesheet = Stylesheet;
2328
}
2429

30+
private final String Stylesheet;
31+
2532
@Override
2633
public Node apply(int idx) {
2734
Label lineNo = new Label();
2835
lineNo.getStyleClass().add("lineno");
29-
lineNo.getStylesheets().add(STYLESHEET);
36+
lineNo.getStylesheets().add(Stylesheet);
3037

3138
// When removed from the scene, stay subscribed to never(), which is
3239
// a fake subscription that consumes no resources, instead of staying

0 commit comments

Comments
 (0)