use of org.fxmisc.richtext.StyleClassedTextArea in project RichTextFX by FXMisc.
the class TooltipDemo method start.
@Override
public void start(Stage stage) {
StyleClassedTextArea area = new StyleClassedTextArea();
area.setWrapText(true);
area.appendText("Pause the mouse over the text for 1 second.");
Popup popup = new Popup();
Label popupMsg = new Label();
popupMsg.setStyle("-fx-background-color: black;" + "-fx-text-fill: white;" + "-fx-padding: 5;");
popup.getContent().add(popupMsg);
area.setMouseOverTextDelay(Duration.ofSeconds(1));
area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
int chIdx = e.getCharacterIndex();
Point2D pos = e.getScreenPosition();
popupMsg.setText("Character '" + area.getText(chIdx, chIdx + 1) + "' at " + pos);
popup.show(area, pos.getX(), pos.getY() + 10);
});
area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
popup.hide();
});
Scene scene = new Scene(area, 600, 400);
stage.setScene(scene);
stage.setTitle("Tooltip Demo");
stage.show();
}
use of org.fxmisc.richtext.StyleClassedTextArea in project RichTextFX by FXMisc.
the class ManualHighlighting method start.
@Override
public void start(Stage primaryStage) {
Button red = createColorButton(Color.RED, "red");
Button green = createColorButton(Color.GREEN, "green");
Button blue = createColorButton(Color.BLUE, "blue");
Button bold = createBoldButton("bold");
HBox panel = new HBox(red, green, blue, bold);
VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
VBox.setVgrow(vsPane, Priority.ALWAYS);
area.setWrapText(true);
VBox vbox = new VBox(panel, vsPane);
Scene scene = new Scene(vbox, 600, 400);
scene.getStylesheets().add(ManualHighlighting.class.getResource("manual-highlighting.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Manual Highlighting Demo");
primaryStage.show();
area.requestFocus();
}
use of org.fxmisc.richtext.StyleClassedTextArea in project RichTextFX by FXMisc.
the class FontSizeSwitcher method start.
@Override
public void start(Stage primaryStage) {
StyleClassedTextArea area = new StyleClassedTextArea();
area.setWrapText(true);
for (int i = 0; i < 10; ++i) {
area.appendText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n");
}
HBox panel = new HBox();
for (int size : new int[] { 8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72 }) {
Button b = new Button(Integer.toString(size));
b.setOnAction(ae -> area.setStyle("-fx-font-size:" + size));
panel.getChildren().add(b);
}
VBox vbox = new VBox();
VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
VBox.setVgrow(vsPane, Priority.ALWAYS);
vbox.getChildren().addAll(panel, vsPane);
Scene scene = new Scene(vbox, 600, 400);
primaryStage.setScene(scene);
area.requestFocus();
primaryStage.setTitle("Font Size Switching Test");
primaryStage.show();
}
use of org.fxmisc.richtext.StyleClassedTextArea in project RichTextFX by FXMisc.
the class SpellChecking method start.
@Override
public void start(Stage primaryStage) {
StyleClassedTextArea textArea = new StyleClassedTextArea();
textArea.setWrapText(true);
Subscription cleanupWhenFinished = textArea.multiPlainChanges().successionEnds(Duration.ofMillis(500)).subscribe(change -> {
textArea.setStyleSpans(0, computeHighlighting(textArea.getText()));
});
// load the dictionary
try (InputStream input = getClass().getResourceAsStream("spellchecking.dict");
BufferedReader br = new BufferedReader(new InputStreamReader(input))) {
String line;
while ((line = br.readLine()) != null) {
dictionary.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// load the sample document
InputStream input2 = getClass().getResourceAsStream("spellchecking.txt");
try (java.util.Scanner s = new java.util.Scanner(input2)) {
String document = s.useDelimiter("\\A").hasNext() ? s.next() : "";
textArea.replaceText(0, 0, document);
}
Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(textArea)), 600, 400);
scene.getStylesheets().add(getClass().getResource("spellchecking.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Spell Checking Demo");
primaryStage.show();
}
use of org.fxmisc.richtext.StyleClassedTextArea in project RichTextFX by FXMisc.
the class FxmlTester method test_fxml_construction_of_area.
@Test
public void test_fxml_construction_of_area() throws IOException, LoadException {
// FxmlTest.fxml is located in resources folder: src/integrationTest/resources/org/fxmisc/richtext/api/
FXMLLoader fxml = new FXMLLoader(getClass().getResource("FxmlTest.fxml"));
StyleClassedTextArea area = (StyleClassedTextArea) fxml.load();
// fxml.load() will throw a LoadException if any properties failed to be set,
// so if 'area' is not null then all properties are guaranteed to have been set.
org.junit.Assert.assertNotNull(area);
FxmlTest ctrl = fxml.getController();
// Check that the controller was loaded and that it has the relevant
// test methods which are referenced in the loaded fxml file.
org.junit.Assert.assertNotNull(ctrl);
ctrl.testWithMouseEvent(null);
ctrl.testWithOutMouseEvent();
}
Aggregations