Search in sources :

Example 1 with StyleClassedTextArea

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();
}
Also used : Point2D(javafx.geometry.Point2D) Popup(javafx.stage.Popup) StyleClassedTextArea(org.fxmisc.richtext.StyleClassedTextArea) Label(javafx.scene.control.Label) Scene(javafx.scene.Scene)

Example 2 with StyleClassedTextArea

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();
}
Also used : HBox(javafx.scene.layout.HBox) Button(javafx.scene.control.Button) StyleClassedTextArea(org.fxmisc.richtext.StyleClassedTextArea) Scene(javafx.scene.Scene) VBox(javafx.scene.layout.VBox) VirtualizedScrollPane(org.fxmisc.flowless.VirtualizedScrollPane)

Example 3 with StyleClassedTextArea

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();
}
Also used : HBox(javafx.scene.layout.HBox) Button(javafx.scene.control.Button) StyleClassedTextArea(org.fxmisc.richtext.StyleClassedTextArea) Scene(javafx.scene.Scene) VBox(javafx.scene.layout.VBox) VirtualizedScrollPane(org.fxmisc.flowless.VirtualizedScrollPane)

Example 4 with StyleClassedTextArea

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) Scene(javafx.scene.Scene) StyleClassedTextArea(org.fxmisc.richtext.StyleClassedTextArea) BufferedReader(java.io.BufferedReader) Subscription(org.reactfx.Subscription) StackPane(javafx.scene.layout.StackPane) VirtualizedScrollPane(org.fxmisc.flowless.VirtualizedScrollPane)

Example 5 with StyleClassedTextArea

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();
}
Also used : StyleClassedTextArea(org.fxmisc.richtext.StyleClassedTextArea) FXMLLoader(javafx.fxml.FXMLLoader) Test(org.junit.Test)

Aggregations

StyleClassedTextArea (org.fxmisc.richtext.StyleClassedTextArea)5 Scene (javafx.scene.Scene)4 VirtualizedScrollPane (org.fxmisc.flowless.VirtualizedScrollPane)3 Button (javafx.scene.control.Button)2 HBox (javafx.scene.layout.HBox)2 VBox (javafx.scene.layout.VBox)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Point2D (javafx.geometry.Point2D)1 Label (javafx.scene.control.Label)1 StackPane (javafx.scene.layout.StackPane)1 Popup (javafx.stage.Popup)1 Test (org.junit.Test)1 Subscription (org.reactfx.Subscription)1