org.fxmisc.richtext.StyleClassedTextArea Java Examples

The following examples show how to use org.fxmisc.richtext.StyleClassedTextArea. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FxmlTests.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void test_fxml_construction_of_area() throws IOException {
    // FxmlTest-Controller.fxml is located in resources folder: src/integrationTest/resources/org/fxmisc/richtext/api/
    FXMLLoader fxml = new FXMLLoader(getClass().getResource("FxmlTest-Controller.fxml"));
    StyleClassedTextArea area = 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.
    assertNotNull(area);
    
    FxmlController 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.
    assertNotNull(ctrl);
    ctrl.testWithMouseEvent(null);
    ctrl.testWithOutMouseEvent();
}
 
Example #2
Source File: ExtensionLoggerController.java    From G-Earth with MIT License 6 votes vote down vote up
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    area = new StyleClassedTextArea();
    area.getStyleClass().add("white");
    area.setWrapText(true);
    area.setEditable(false);

    VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
    borderPane.setCenter(vsPane);

    synchronized (appendOnLoad) {
        initialized = true;
        if (!appendOnLoad.isEmpty()) {
            appendLog(appendOnLoad);
            appendOnLoad.clear();
        }
    }
}
 
Example #3
Source File: UiLoggerController.java    From G-Earth with MIT License 6 votes vote down vote up
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    area = new StyleClassedTextArea();
    area.getStyleClass().add("dark");
    area.setWrapText(true);

    VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
    borderPane.setCenter(vsPane);

    synchronized (appendLater) {
        initialized = true;
        if (!appendLater.isEmpty()) {
            appendLog(appendLater);
            appendLater.clear();
        }
    }
}
 
Example #4
Source File: ManualHighlightingDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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(ManualHighlightingDemo.class.getResource("manual-highlighting.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.setTitle("Manual Highlighting Demo");
    primaryStage.show();

    area.requestFocus();
}
 
Example #5
Source File: RichTextFXStyleClassedTextAreaElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void clear() {
    StyleClassedTextArea styleClassedTextAreaNode = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    Platform.runLater(() -> {
        styleClassedTextArea.marathon_select("Hello World");
    });
    new Wait("Waiting for the text area value to be set") {
        @Override
        public boolean until() {
            return "Hello World".equals(styleClassedTextAreaNode.getText());
        }
    };
    styleClassedTextArea.clear();
    new Wait("Waiting for the text area value to be cleared") {
        @Override
        public boolean until() {
            return "".equals(styleClassedTextAreaNode.getText());
        }
    };
}
 
Example #6
Source File: RichTextFXStyleClassedTextAreaElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void getText() {
    StyleClassedTextArea styleClassedTextAreaNode = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    AssertJUnit.assertEquals("", styleClassedTextArea.getText());
    Platform.runLater(() -> {
        styleClassedTextArea.marathon_select("Hello World");
    });
    new Wait("Waiting for the text area value to be set") {
        @Override
        public boolean until() {
            return "Hello World".equals(styleClassedTextAreaNode.getText());
        }
    };
    AssertJUnit.assertEquals("Hello World", styleClassedTextArea.getText());
}
 
Example #7
Source File: RFXStyleClassedTextAreaTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void getText() {
    final StyleClassedTextArea textArea = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    LoggingRecorder lr = new LoggingRecorder();
    List<Object> text = new ArrayList<>();
    Platform.runLater(() -> {
        RFXComponent rca = new RFXGenericStyledArea(textArea, null, null, lr);
        textArea.appendText("Hello World");
        rca.focusLost(null);
        text.add(rca.getAttribute("text"));
    });
    new Wait("Waiting for text area text.") {
        @Override
        public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("Hello World", text.get(0));
}
 
Example #8
Source File: RFXStyleClassedTextAreaTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void selectWithSpecialChars() throws InterruptedException {
    final StyleClassedTextArea styleClassedTextAreaNode = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            styleClassedTextAreaNode.appendText("Hello\n World'\"");
        }
    });
    LoggingRecorder lr = new LoggingRecorder();
    RFXComponent rTextField = new RFXGenericStyledArea(styleClassedTextAreaNode, null, null, lr);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            rTextField.focusLost(null);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording select = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", select.getCall());
    AssertJUnit.assertEquals("Hello\n World'\"", select.getParameters()[0]);
}
 
Example #9
Source File: RFXStyleClassedTextAreaTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void selectWithUtf8Chars() throws InterruptedException {
    final StyleClassedTextArea styleClassedTextAreaNode = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            styleClassedTextAreaNode.appendText("å∫ç∂´ƒ©˙ˆ∆");
        }
    });
    LoggingRecorder lr = new LoggingRecorder();
    RFXComponent rTextField = new RFXGenericStyledArea(styleClassedTextAreaNode, null, null, lr);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            rTextField.focusLost(null);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording select = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", select.getCall());
    AssertJUnit.assertEquals("å∫ç∂´ƒ©˙ˆ∆", select.getParameters()[0]);
}
 
Example #10
Source File: FontSizeSwitcherDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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();
}
 
Example #11
Source File: MdTextController.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
public void initKeyMapping(StyleClassedTextArea sourceText) {
    Platform.runLater(() -> {
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.S, SHORTCUT_DOWN), e -> handleSaveButtonAction())));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.G, SHORTCUT_DOWN), e -> handleBoldButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.I, SHORTCUT_DOWN), e -> handleItalicButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.B, SHORTCUT_DOWN), e -> handleBarredButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.K, SHORTCUT_DOWN), e -> handleTouchButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.PLUS, SHORTCUT_DOWN), e -> handleExpButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.EQUALS, SHORTCUT_DOWN), e -> handleIndButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.E, SHORTCUT_DOWN), e -> handleCenterButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.D, SHIFT_DOWN, SHORTCUT_DOWN), e -> handleRightButtonAction(null))));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.SPACE, SHORTCUT_DOWN), e -> handleUnbreakableAction())));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.L, SHORTCUT_DOWN), e -> handleGoToLineAction())));
        Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.F, SHORTCUT_DOWN), e -> handleFindReplaceDialog())));
        if (FunctionTreeFactory.isMacOs()) {
            Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.Q, SHORTCUT_DOWN), e -> currentSourceText.selectAll())));
        }
        if (MainApp.getConfig().isEditorSmart()) {
            //Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.TAB), e -> handleSmartTab())));
            //Nodes.addInputMap(sourceText, sequence(consume(keyPressed(KeyCode.ENTER), e -> handleSmartEnter())));
        }
    });
}
 
Example #12
Source File: MenuController.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
@FXML private void handleFindReplaceAction(ActionEvent event){
    SplitPane sPane = (SplitPane) mainApp.getIndex().getEditorList().getTabs().stream()
            .filter(t ->t.isSelected())
            .findFirst()
            .get()
            .getContent();
    BorderPane bPane = (BorderPane) sPane.getItems().get(0);
    StyleClassedTextArea source = (StyleClassedTextArea) bPane.getCenter();
    FunctionTreeFactory.openFindReplaceDialog(source);
}
 
Example #13
Source File: TooltipDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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();
}
 
Example #14
Source File: SpellCheckingDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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()));
            });

    // call when no longer need it: `cleanupWhenFinished.unsubscribe();`

    // 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();
}
 
Example #15
Source File: ImageInputDialog.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
public void setSourceText(StyleClassedTextArea sourceText, ZdsHttp zdsUtils, MenuController menuManager, Content content){
    this.sourceText = sourceText;
    this.zdsUtils = zdsUtils;
    this.menuManager = menuManager;
    this.content = content;
    if(content == null ) {
        selectButton.setDisable(true);
    }
    title.setText(sourceText.getSelectedText());
}
 
Example #16
Source File: FunctionTreeFactory.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
public static void openFindReplaceDialog(StyleClassedTextArea sourceText) {
    FXMLLoader loader = new CustomFXMLLoader(MainApp.class.getResource("fxml/FindReplaceDialog.fxml"));

    Stage dialogStage = new CustomStage(loader, Configuration.getBundle().getString("ui.dialog.find.title"));
    dialogStage.setAlwaysOnTop(true);
    dialogStage.initModality(Modality.NONE);
    dialogStage.setTitle(Configuration.getBundle().getString("ui.dialog.find.title"));
    dialogStage.setResizable(false);

    FindReplaceDialog findReplaceDialog = loader.getController();
    findReplaceDialog.setSourceText(sourceText);

    dialogStage.show();
}
 
Example #17
Source File: RichTextFXStyleClassedTextAreaElementTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Test
public void marathon_select() {
    StyleClassedTextArea styleClassedTextAreaNode = (StyleClassedTextArea) getPrimaryStage().getScene().getRoot()
            .lookup(".styled-text-area");
    Platform.runLater(() -> {
        styleClassedTextArea.marathon_select("Hello World");
    });
    new Wait("Waiting for the text area value to be set") {
        @Override
        public boolean until() {
            return "Hello World".equals(styleClassedTextAreaNode.getText());
        }
    };
}
 
Example #18
Source File: StyleClassedTextAreaSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public StyleClassedTextAreaSample() {
    StyleClassedTextArea codeArea = new StyleClassedTextArea();
    codeArea.setId("styleClassedTextArea");
    codeArea.setMaxSize(250, 250);
    VBox root = new VBox();
    root.getChildren().addAll(codeArea, new Button("Click Me!!"));
    getChildren().add(root);
}
 
Example #19
Source File: FindReplaceDialog.java    From zest-writer with GNU General Public License v3.0 4 votes vote down vote up
public void setSourceText(StyleClassedTextArea sourceText){
    this.sourceText = sourceText;
}
 
Example #20
Source File: MdConvertController.java    From zest-writer with GNU General Public License v3.0 4 votes vote down vote up
public MdConvertController() {
    sourceText = new StyleClassedTextArea();
    sourceText.setStyle("markdown-editor");
    sourceText.setWrapText(true);
    vsPane = new VirtualizedScrollPane<>(sourceText);
}
 
Example #21
Source File: DefaultControllerProvider.java    From kafka-message-tool with MIT License 4 votes vote down vote up
@Override
public SenderConfigView getSenderConfigGuiController(KafkaSenderConfig config,
                                                     AnchorPane parentPane,
                                                     KafkaMessageSender sender,
                                                     Runnable refreshCallback,
                                                     ObservableList<KafkaTopicConfig> topicConfigs) {

    return getControllerFor(config, messageControllers, () -> {
        try {
            final MessageTemplateSender msgTemplateEvaluator = new MessageTemplateSender(sender,
                                                                                         new GroovyScriptEvaluator());

            final CodeArea beforeAllCodeAreaShared = new CodeArea();
            final VirtualizedScrollPane<StyleClassedTextArea> beforeAllMessagesSharedScriptScrollPane =
                    new VirtualizedScrollPane<>(beforeAllCodeAreaShared);

            final CodeArea beforeAllCodeArea = new CodeArea();
            final VirtualizedScrollPane<StyleClassedTextArea> beforeAllMessagesScriptScrollPane =
                new VirtualizedScrollPane<>(beforeAllCodeArea);


            final CodeArea beforeEachCodeArea = new CodeArea();
            final VirtualizedScrollPane<StyleClassedTextArea> beforeEachMessageScriptScrollPane =
                new VirtualizedScrollPane<>(beforeEachCodeArea);

            final CodeArea messageContentCodeArea = new CodeArea();
            final VirtualizedScrollPane<StyleClassedTextArea> messageContentScrollPane =
                new VirtualizedScrollPane<>(messageContentCodeArea);

            syntaxHighlightConfigurator.configureGroovySyntaxHighlighting(beforeAllCodeAreaShared);
            syntaxHighlightConfigurator.configureGroovySyntaxHighlighting(beforeAllCodeArea);
            syntaxHighlightConfigurator.configureGroovySyntaxHighlighting(beforeEachCodeArea);
            syntaxHighlightConfigurator.configureJsonSyntaxHighlighting(messageContentCodeArea);

            return new SenderConfigView(config,
                                        parentPane,
                                        guiInformer,
                                        refreshCallback,
                                        topicConfigs,
                                        msgTemplateEvaluator,
                                        beforeAllMessagesSharedScriptScrollPane,
                                        beforeAllMessagesScriptScrollPane,
                                        beforeEachMessageScriptScrollPane,
                                        messageContentScrollPane,
                                        kafkaClusterProxies,
                                        applicationSettings);
        } catch (IOException e) {
            Logger.error(e);
            return null;
        }
    });
}
 
Example #22
Source File: SenderConfigView.java    From kafka-message-tool with MIT License 4 votes vote down vote up
public SenderConfigView(KafkaSenderConfig config,
                        AnchorPane parentPane,
                        ModelConfigObjectsGuiInformer guiInformer,
                        Runnable refreshCallback,
                        ObservableList<KafkaTopicConfig> topicConfigs,
                        MessageTemplateSender msgTemplateSender,
                        VirtualizedScrollPane<StyleClassedTextArea> beforeAllMessagesSharedScriptScrollPane,
                        VirtualizedScrollPane<StyleClassedTextArea> beforeAllMessagesScriptScrollPane,
                        VirtualizedScrollPane<StyleClassedTextArea> beforeEachMessageScriptScrollPane,
                        VirtualizedScrollPane<StyleClassedTextArea> messageContentScrollPane,
                        KafkaClusterProxies kafkaClusterProxies,
                        ApplicationSettings applicationSettings) throws IOException {
    this.msgTemplateSender = msgTemplateSender;

    this.beforeAllMessagesSharedScriptScrollPane = beforeAllMessagesSharedScriptScrollPane;
    this.beforeAllMessagesScriptScrollPane = beforeAllMessagesScriptScrollPane;
    this.beforeEachMessageScriptScrollPane = beforeEachMessageScriptScrollPane;

    this.kafkaClusterProxies = kafkaClusterProxies;
    this.applicationSettings = applicationSettings;

    beforeAllmessagesSharedScriptCodeArea = this.beforeAllMessagesSharedScriptScrollPane.getContent();
    beforeAllMessagesScriptCodeArea = this.beforeAllMessagesScriptScrollPane.getContent();
    beforeEachMessagesScriptCodeArea = this.beforeEachMessageScriptScrollPane.getContent();


    this.messageContentScrollPane = messageContentScrollPane;
    messageContentTextArea = this.messageContentScrollPane.getContent();


    CustomFxWidgetsLoader.loadAnchorPane(this, FXML_FILE);

    this.config = config;
    this.refreshCallback = refreshCallback;
    this.topicConfigs = topicConfigs;

    final StringExpression windowTitle = new ReadOnlyStringWrapper("Message sender configuration");
    displayBehaviour = new DetachableDisplayBehaviour(parentPane,
                                                      windowTitle,
                                                      this,
                                                      detachPaneButton.selectedProperty(),
                                                      config,
                                                      guiInformer);

    configureMessageNameTextField();
    configureMessageContentTextArea();
    configureTopicComboBox();
    configureRepeatCountSpinner();
    configureMessageKeyCheckbox();
    configureScriptsTextAreas();
    configureMessageKeyTextField();
    configureSimulationSendingCheckBox();
    createProgressNotifier();
    GuiUtils.configureComboBoxToClearSelectedValueIfItsPreviousValueWasRemoved(topicConfigComboBox);
    comboBoxConfigurator = new TopicConfigComboBoxConfigurator<>(topicConfigComboBox, config);
    comboBoxConfigurator.configure();
    taskExecutor = new MessageSenderTaskExecutor(sendMsgPushButton.disableProperty(),
                                                 stopSendingButton.disableProperty());
}