Java Code Examples for org.fxmisc.flowless.VirtualizedScrollPane

The following examples show how to use org.fxmisc.flowless.VirtualizedScrollPane. These examples are extracted from open source projects. 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 Project: milkman   Source File: ContentEditor.java    License: MIT License 6 votes vote down vote up
public ContentEditor() {
	getStyleClass().add("contentEditor");

	setupHeader();
	setupCodeArea();
	setupSearch();

	StackPane.setAlignment(search, Pos.TOP_RIGHT);
	// bug: scrollPane has some issue if it is rendered within a tab that
	// is not yet shown with content that needs a scrollbar
	// this leads to e.g. tabs not being updated, if triggered programmatically
	// switching to ALWAYS for scrollbars fixes this issue
	scrollPane = new VirtualizedScrollPane(codeArea, ScrollBarPolicy.ALWAYS,
			ScrollBarPolicy.ALWAYS);

	StackPane contentPane = new StackPane(scrollPane, search);
	VBox.setVgrow(contentPane, Priority.ALWAYS);

	getChildren().add(contentPane);
}
 
Example 2
Source Project: Quelea   Source File: LyricsTextArea.java    License: GNU General Public License v3.0 6 votes vote down vote up
public LyricsTextArea() {
    textArea = new InlineCssTextArea();
    ContextMenu contextMenu = new ContextMenu();
    Clipboard systemClipboard = Clipboard.getSystemClipboard();
    MenuItem paste = new MenuItem(LabelGrabber.INSTANCE.getLabel("paste.label"));
    contextMenu.setOnShown(e -> {
        paste.setDisable(!systemClipboard.hasContent(DataFormat.PLAIN_TEXT));
    });

    paste.setOnAction(e -> {
        String clipboardText = systemClipboard.getString();
        textArea.insertText(textArea.getCaretPosition(), clipboardText);
    });

    contextMenu.getItems().add(paste);
    textArea.setContextMenu(contextMenu);
    textArea.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
        Platform.runLater(this::refreshStyle);
    });

    textArea.setStyle("-fx-font-family: monospace; -fx-font-size: 10pt;");
    textArea.setUndoManager(UndoManagerFactory.zeroHistorySingleChangeUM(textArea.richChanges()));
    getChildren().add(new VirtualizedScrollPane<>(textArea));
    textArea.getStyleClass().add("text-area");
}
 
Example 3
Source Project: G-Earth   Source File: ExtensionLoggerController.java    License: 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 4
Source Project: G-Earth   Source File: UiLoggerController.java    License: 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 5
Source Project: MSPaintIDE   Source File: FormattedAppender.java    License: MIT License 6 votes vote down vote up
public static void activate(InlineCssTextArea output, VirtualizedScrollPane virtualScrollPane) {
    FormattedAppender.output = output;
    FormattedAppender.virtualScrollPane = virtualScrollPane;
    output.getStyleClass().add("output-theme");

    PRE_STYLES.forEach((level, style) -> STYLE_MAP.put(level, style + "-fx-font-family: Monospace;"));

    Platform.runLater(() -> {
        var instance = getInstance();
        if (instance == null) return;

        synchronized (eventBuffer) {
            eventBuffer.forEach(instance::processEvent);
            eventBuffer.clear();
        }

        virtualScrollPane.scrollYBy(10000);
    });
}
 
Example 6
Source Project: RichTextFX   Source File: HyperlinkDemo.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    Consumer<String> showLink = (string) -> {
        try
        {
            Desktop.getDesktop().browse(new URI(string));
        }
        catch (IOException | URISyntaxException e)
        {
            throw new RuntimeException(e);
        }
    };
    TextHyperlinkArea area = new TextHyperlinkArea(showLink);

    area.appendText("Some text in the area\n");
    area.appendWithLink("Google.com", "http://www.google.com");

    VirtualizedScrollPane<TextHyperlinkArea> vsPane = new VirtualizedScrollPane<>(area);

    Scene scene = new Scene(vsPane, 500, 500);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 7
@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 8
Source Project: RichTextFX   Source File: XMLEditorDemo.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
  public void start(Stage primaryStage) {
      CodeArea codeArea = new CodeArea();
      codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));

      codeArea.textProperty().addListener((obs, oldText, newText) -> {
          codeArea.setStyleSpans(0, computeHighlighting(newText));
      });
      codeArea.replaceText(0, 0, sampleCode);

Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(codeArea)), 600, 400);
      scene.getStylesheets().add(XMLEditorDemo.class.getResource("xml-highlighting.css").toExternalForm());
      primaryStage.setScene(scene);
      primaryStage.setTitle("XML Editor Demo");
      primaryStage.show();
  }
 
Example 9
@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 10
Source Project: Jupiter   Source File: EditorTab.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new titled tab from the given file path.
 *
 * @throws IOException if an I/O error occurs
 */
public EditorTab(File file) throws IOException {
  super();
  this.file = file;
  closed = false;
  untitled = -1;
  name = file.getName();
  setText(name);
  // create new text editor
  textEditor = new TextEditor(FS.read(file));
  // set tab content
  setContent(new VirtualizedScrollPane<>(textEditor));
  // add listeners
  textEditor.textProperty().addListener((e, o, n) -> handleChanges());
}
 
Example 11
Source Project: Jupiter   Source File: EditorTab.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Creates a new untitled tab. */
public EditorTab() {
  super();
  closed = false;
  file = null;
  untitled = UNTITLED++;
  name = String.format("riscv%d.s", untitled);
  setText(name);
  textEditor = new TextEditor();
  setContent(new VirtualizedScrollPane<>(textEditor));
  // add listeners
  textEditor.textProperty().addListener((e, o, n) -> handleChanges());
}
 
Example 12
Source Project: Recaf   Source File: EditorPane.java    License: MIT License 5 votes vote down vote up
/**
 * @param controller
 * 		Controller to act on.
 * @param language
 * 		Type of text content.
 * @param handlerFunc
 * 		Function to supply the context handler.
 */
public EditorPane(GuiController controller, Language language, BiFunction<GuiController, CodeArea, C> handlerFunc) {
	this.controller = controller;
	this.contextHandler = handlerFunc.apply(controller, codeArea);
	getStyleClass().add("editor-pane");
	setupCodeArea(language);
	setupSearch();
	VirtualizedScrollPane<CodeArea> scroll = new VirtualizedScrollPane<>(codeArea);
	split = new SplitPane(scroll, bottomContent);
	split.setOrientation(Orientation.VERTICAL);
	split.setDividerPositions(1);
	split.getStyleClass().add("no-border");
	setupBottomContent();
	setCenter(split);
}
 
Example 13
Source Project: JRemapper   Source File: CodePane.java    License: MIT License 5 votes vote down vote up
/**
 * Setup everything else that isn't the code-area.
 */
private void setupTheRest() {
	info.setPrefHeight(95);
	info.getStyleClass().add("infopane");
	ColumnConstraints colInfo = new ColumnConstraints();
	ColumnConstraints colEdit = new ColumnConstraints();
	colInfo.setPercentWidth(15);
	colEdit.setPercentWidth(85);
	info.getColumnConstraints().addAll(colInfo, colEdit);
	setTop(info);
	pane.animationDurationProperty().setValue(Duration.millis(50));
	pane.setContent(new VirtualizedScrollPane<>(code));
	setCenter(pane);
}
 
Example 14
private void createNodes() {
	textArea = new PreviewStyledTextArea();
	textArea.setWrapText(true);
	textArea.getStylesheets().add("org/markdownwriterfx/prism.css");

	scrollPane = new VirtualizedScrollPane<>(textArea);
}
 
Example 15
private void createNodes() {
	textArea = new PreviewStyledTextArea();
	textArea.getStyleClass().add("ast-preview");
	textArea.getStylesheets().add("org/markdownwriterfx/prism.css");

	scrollPane = new VirtualizedScrollPane<>(textArea);
}
 
Example 16
@Override
public void start(Stage primaryStage) {
    executor = Executors.newSingleThreadExecutor();
    codeArea = new CodeArea();
    codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
    Subscription cleanupWhenDone = codeArea.multiPlainChanges()
            .successionEnds(Duration.ofMillis(500))
            .supplyTask(this::computeHighlightingAsync)
            .awaitLatest(codeArea.multiPlainChanges())
            .filterMap(t -> {
                if(t.isSuccess()) {
                    return Optional.of(t.get());
                } else {
                    t.getFailure().printStackTrace();
                    return Optional.empty();
                }
            })
            .subscribe(this::applyHighlighting);

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

    codeArea.replaceText(0, 0, sampleCode);

    Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(codeArea)), 600, 400);
    scene.getStylesheets().add(JavaKeywordsAsyncDemo.class.getResource("java-keywords.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.setTitle("Java Keywords Async Demo");
    primaryStage.show();
}
 
Example 17
@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 18
Source Project: RichTextFX   Source File: ShowLineDemo.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    StringBuilder sb = new StringBuilder();
    int max = 100;
    for (int i = 0; i < max; i++) {
        sb.append("Line Index: ").append(i).append("\n");
    }
    sb.append("Line Index: ").append(max);
    InlineCssTextArea area = new InlineCssTextArea(sb.toString());
    VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);

    Function<Integer, Integer> clamp = i -> Math.max(0, Math.min(i, area.getLength() - 1));
    Button showInViewportButton = createButton("Show line somewhere in Viewport", ae -> {
        area.showParagraphInViewport(clamp.apply(field.getTextAsInt()));
    });
    Button showAtViewportTopButton = createButton("Show line at top of viewport", ae -> {
        area.showParagraphAtTop(clamp.apply(field.getTextAsInt()));
    });
    Button showAtViewportBottomButton = createButton("Show line at bottom of viewport", ae -> {
        area.showParagraphAtBottom(clamp.apply(field.getTextAsInt()));
    });

    VBox vbox = new VBox(field, showInViewportButton, showAtViewportTopButton, showAtViewportBottomButton);
    vbox.setAlignment(Pos.CENTER);

    BorderPane root = new BorderPane();
    root.setCenter(vsPane);
    root.setBottom(vbox);

    Scene scene = new Scene(root, 700, 500);
    primaryStage.setScene(scene);
    primaryStage.show();

}
 
Example 19
@Override
public void start(Stage primaryStage) throws Exception {
    area = new CodeArea("abc\ndef\nghi");
    VirtualizedScrollPane<CodeArea> vsPane = new VirtualizedScrollPane<>(area);

    Scene scene = new Scene(vsPane, 400, 400);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 20
Source Project: kafka-message-tool   Source File: DefaultControllerProvider.java    License: 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 21
Source Project: kafka-message-tool   Source File: SenderConfigView.java    License: 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());
}
 
Example 22
Source Project: Everest   Source File: DashboardController.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(URL url, ResourceBundle rb) {
    try {
        // Loading the auth tab
        FXMLLoader authTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/auth/AuthTab.fxml"));
        Parent authTabFXML = authTabLoader.load();
        ThemeManager.setTheme(authTabFXML);
        authTabController = authTabLoader.getController();
        authTabController.setDashboard(this);
        authTab.setContent(authTabFXML);

        // Loading the headers tab
        FXMLLoader headerTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HeaderTab.fxml"));
        Parent headerTabFXML = headerTabLoader.load();
        ThemeManager.setTheme(headerTabFXML);
        headerTabController = headerTabLoader.getController();
        headersTab.setContent(headerTabFXML);

        // Loading the body tab
        FXMLLoader bodyTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/BodyTab.fxml"));
        Parent bodyTabFXML = bodyTabLoader.load();
        ThemeManager.setTheme(bodyTabFXML);
        bodyTabController = bodyTabLoader.getController();
        bodyTab.setContent(bodyTabFXML);
    } catch (IOException e) {
        LoggingService.logSevere("Could not load headers/body tabs.", e, LocalDateTime.now());
    }

    snackbar = new JFXSnackbar(dashboard);

    showLayer(ResponseLayer.PROMPT);
    httpMethodBox.getItems().addAll(
            HTTPConstants.GET,
            HTTPConstants.POST,
            HTTPConstants.PUT,
            HTTPConstants.PATCH,
            HTTPConstants.DELETE);

    // Select GET by default
    httpMethodBox.getSelectionModel().select(HTTPConstants.GET);

    paramsControllers = new ArrayList<>();
    paramsCountProperty = new SimpleIntegerProperty(0);

    addParamField(); // Adds a blank param field

    bodyTab.disableProperty().bind(
            Bindings.or(httpMethodBox.valueProperty().isEqualTo(HTTPConstants.GET),
                    httpMethodBox.valueProperty().isEqualTo(HTTPConstants.DELETE)));

    // Disabling Ctrl + Tab navigation
    requestOptionsTab.setOnKeyPressed(e -> {
        if (e.getCode() == KeyCode.TAB) {
            e.consume();
        }
    });

    copyBodyButton.setOnAction(e -> {
        responseArea.selectAll();
        responseArea.copy();
        responseArea.deselect();
        snackbar.show("Response body copied to clipboard.", 5000);
    });

    responseTypeBox.getItems().addAll(
            HTTPConstants.JSON,
            HTTPConstants.XML,
            HTTPConstants.HTML,
            HTTPConstants.PLAIN_TEXT);

    responseTypeBox.valueProperty().addListener(change -> {
        String type = responseTypeBox.getValue();

        if (type.equals(HTTPConstants.JSON)) {
            responseArea.setText(responseArea.getText(),
                    FormatterFactory.getHighlighter(type),
                    HighlighterFactory.getHighlighter(type));

            return;
        }

        responseArea.setHighlighter(HighlighterFactory.getHighlighter(type));
    });

    visualizer = new TreeVisualizer();
    visualizerTab.setContent(visualizer);

    responseArea = new EverestCodeArea();
    responseArea.setEditable(false);
    ThemeManager.setSyntaxTheme(responseArea);
    responseBodyTab.setContent(new VirtualizedScrollPane<>(responseArea));

    responseHeadersViewer = new ResponseHeadersViewer();
    responseHeadersTab.setContent(responseHeadersViewer);
}
 
Example 23
public MdConvertController() {
    sourceText = new StyleClassedTextArea();
    sourceText.setStyle("markdown-editor");
    sourceText.setWrapText(true);
    vsPane = new VirtualizedScrollPane<>(sourceText);
}
 
Example 24
public MarkdownEditorPane() {
	textArea = new MarkdownTextArea();
	textArea.setWrapText(true);
	textArea.setUseInitialStyleForInsertion(true);
	textArea.getStyleClass().add("markdown-editor");
	textArea.getStylesheets().add("org/markdownwriterfx/editor/MarkdownEditor.css");
	textArea.getStylesheets().add("org/markdownwriterfx/prism.css");

	textArea.textProperty().addListener((observable, oldText, newText) -> {
		textChanged(newText);
	});

	textArea.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, this::showContextMenu);
	textArea.addEventHandler(MouseEvent.MOUSE_PRESSED, this::hideContextMenu);
	textArea.setOnDragEntered(this::onDragEntered);
	textArea.setOnDragExited(this::onDragExited);
	textArea.setOnDragOver(this::onDragOver);
	textArea.setOnDragDropped(this::onDragDropped);

	smartEdit = new SmartEdit(this, textArea);

	Nodes.addInputMap(textArea, sequence(
		consume(keyPressed(PLUS, SHORTCUT_DOWN),	this::increaseFontSize),
		consume(keyPressed(MINUS, SHORTCUT_DOWN),	this::decreaseFontSize),
		consume(keyPressed(DIGIT0, SHORTCUT_DOWN),	this::resetFontSize),
		consume(keyPressed(W, ALT_DOWN),			this::showWhitespace),
		consume(keyPressed(I, ALT_DOWN),			this::showImagesEmbedded)
	));

	// create scroll pane
	VirtualizedScrollPane<MarkdownTextArea> scrollPane = new VirtualizedScrollPane<>(textArea);

	// create border pane
	borderPane = new BottomSlidePane(scrollPane);

	overlayGraphicFactory = new ParagraphOverlayGraphicFactory(textArea);
	textArea.setParagraphGraphicFactory(overlayGraphicFactory);
	updateFont();
	updateShowLineNo();
	updateShowWhitespace();

	// initialize properties
	markdownText.set("");
	markdownAST.set(parseMarkdown(""));

	// find/replace
	findReplacePane = new FindReplacePane(textArea);
	findHitsChangeListener = this::findHitsChanged;
	findReplacePane.addListener(findHitsChangeListener);
	findReplacePane.visibleProperty().addListener((ov, oldVisible, newVisible) -> {
		if (!newVisible)
			borderPane.setBottom(null);
	});

	// listen to option changes
	optionsListener = e -> {
		if (textArea.getScene() == null)
			return; // editor closed but not yet GCed

		if (e == Options.fontFamilyProperty() || e == Options.fontSizeProperty())
			updateFont();
		else if (e == Options.showLineNoProperty())
			updateShowLineNo();
		else if (e == Options.showWhitespaceProperty())
			updateShowWhitespace();
		else if (e == Options.showImagesEmbeddedProperty())
			updateShowImagesEmbedded();
		else if (e == Options.markdownRendererProperty() || e == Options.markdownExtensionsProperty()) {
			// re-process markdown if markdown extensions option changes
			parser = null;
			textChanged(textArea.getText());
		}
	};
	WeakInvalidationListener weakOptionsListener = new WeakInvalidationListener(optionsListener);
	Options.fontFamilyProperty().addListener(weakOptionsListener);
	Options.fontSizeProperty().addListener(weakOptionsListener);
	Options.markdownRendererProperty().addListener(weakOptionsListener);
	Options.markdownExtensionsProperty().addListener(weakOptionsListener);
	Options.showLineNoProperty().addListener(weakOptionsListener);
	Options.showWhitespaceProperty().addListener(weakOptionsListener);
	Options.showImagesEmbeddedProperty().addListener(weakOptionsListener);

	// workaround a problem with wrong selection after undo:
	//   after undo the selection is 0-0, anchor is 0, but caret position is correct
	//   --> set selection to caret position
	textArea.selectionProperty().addListener((observable,oldSelection,newSelection) -> {
		// use runLater because the wrong selection temporary occurs while edition
		Platform.runLater(() -> {
			IndexRange selection = textArea.getSelection();
			int caretPosition = textArea.getCaretPosition();
			if (selection.getStart() == 0 && selection.getEnd() == 0 && textArea.getAnchor() == 0 && caretPosition > 0)
				textArea.selectRange(caretPosition, caretPosition);
		});
	});
}
 
Example 25
@Override
public void start(Stage primaryStage) {
    CodeArea codeArea = new CodeArea();

    // add line numbers to the left of area
    codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));

    // recompute the syntax highlighting 500 ms after user stops editing area
    Subscription cleanupWhenNoLongerNeedIt = codeArea

            // plain changes = ignore style changes that are emitted when syntax highlighting is reapplied
            // multi plain changes = save computation by not rerunning the code multiple times
            //   when making multiple changes (e.g. renaming a method at multiple parts in file)
            .multiPlainChanges()

            // do not emit an event until 500 ms have passed since the last emission of previous stream
            .successionEnds(Duration.ofMillis(500))

            // run the following code block when previous stream emits an event
            .subscribe(ignore -> codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText())));

    // when no longer need syntax highlighting and wish to clean up memory leaks
    // run: `cleanupWhenNoLongerNeedIt.unsubscribe();`


    // auto-indent: insert previous line's indents on enter
    final Pattern whiteSpace = Pattern.compile( "^\\s+" );
    codeArea.addEventHandler( KeyEvent.KEY_PRESSED, KE ->
    {
        if ( KE.getCode() == KeyCode.ENTER ) {
        	int caretPosition = codeArea.getCaretPosition();
        	int currentParagraph = codeArea.getCurrentParagraph();
            Matcher m0 = whiteSpace.matcher( codeArea.getParagraph( currentParagraph-1 ).getSegments().get( 0 ) );
            if ( m0.find() ) Platform.runLater( () -> codeArea.insertText( caretPosition, m0.group() ) );
        }
    });

    
    codeArea.replaceText(0, 0, sampleCode);

    Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(codeArea)), 600, 400);
    scene.getStylesheets().add(JavaKeywordsAsyncDemo.class.getResource("java-keywords.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.setTitle("Java Keywords Demo");
    primaryStage.show();
}