org.fxmisc.richtext.CodeArea Java Examples
The following examples show how to use
org.fxmisc.richtext.CodeArea.
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: VariableHighlighter.java From milkman with MIT License | 7 votes |
public HighLightRectangle(Node node) { if (node instanceof Text){ Text text = (Text) node; listener = observable -> clear(node); text.textProperty().addListener(new WeakInvalidationListener(listener)); text.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener)); } if (node instanceof CodeArea){ CodeArea codeArea = (CodeArea) node; listener = observable -> clear(node); codeArea.addEventFilter(ScrollEvent.ANY, evt -> listener.invalidated(null)); codeArea.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener)); codeArea.textProperty().addListener(new WeakInvalidationListener(listener)); // codeArea.textProperty().addListener((obs, o, n) -> System.out.println("test")); // var parent = (VirtualizedScrollPane) codeArea.getParent(); // parent.onScrollProperty().addListener(new WeakInvalidationListener(listener)); // parent.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener)); // parent.addEventFilter(ScrollEvent.ANY, evt -> listener.invalidated(null)); } }
Example #2
Source File: RFXCodeAreaTest.java From marathonv5 with Apache License 2.0 | 6 votes |
@Test public void getText() { final CodeArea textArea = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-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 #3
Source File: XMLEditorDemo.java From RichTextFX with BSD 2-Clause "Simplified" License | 6 votes |
@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 #4
Source File: RFXCodeAreaTest.java From marathonv5 with Apache License 2.0 | 6 votes |
@Test public void selectWithSpecialChars() throws InterruptedException { final CodeArea codeArea = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-area"); Platform.runLater(new Runnable() { @Override public void run() { codeArea.appendText("Hello\n World'\""); } }); LoggingRecorder lr = new LoggingRecorder(); RFXComponent rTextField = new RFXGenericStyledArea(codeArea, 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 #5
Source File: LineIndicatorDemo.java From RichTextFX with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void start(Stage primaryStage) { CodeArea codeArea = new CodeArea(); IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea); IntFunction<Node> arrowFactory = new ArrowFactory(codeArea.currentParagraphProperty()); IntFunction<Node> graphicFactory = line -> { HBox hbox = new HBox( numberFactory.apply(line), arrowFactory.apply(line)); hbox.setAlignment(Pos.CENTER_LEFT); return hbox; }; codeArea.setParagraphGraphicFactory(graphicFactory); codeArea.replaceText("The green arrow will only be on the line where the caret appears.\n\nTry it."); codeArea.moveTo(0, 0); primaryStage.setScene(new Scene(new StackPane(codeArea), 600, 400)); primaryStage.show(); }
Example #6
Source File: RFXCodeAreaTest.java From marathonv5 with Apache License 2.0 | 6 votes |
@Test public void selectWithUtf8Chars() throws InterruptedException { final CodeArea codeArea = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-area"); Platform.runLater(new Runnable() { @Override public void run() { codeArea.appendText("å∫ç∂´ƒ©˙ˆ∆"); } }); LoggingRecorder lr = new LoggingRecorder(); RFXComponent rTextField = new RFXGenericStyledArea(codeArea, 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 #7
Source File: RichTextFXCodeAreaElementTest.java From marathonv5 with Apache License 2.0 | 6 votes |
@Test public void clear() { CodeArea codeAreaNode = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-area"); Platform.runLater(() -> { codeArea.marathon_select("Hello World"); }); new Wait("Waiting for the text area value to be set") { @Override public boolean until() { return "Hello World".equals(codeAreaNode.getText()); } }; codeArea.clear(); new Wait("Waiting for the text area value to be cleared") { @Override public boolean until() { return "".equals(codeAreaNode.getText()); } }; }
Example #8
Source File: ContextHandling.java From Recaf with MIT License | 6 votes |
/** * @param controller * Controller to use. * @param codeArea * Text editor events originate from. */ public ContextHandling(GuiController controller, CodeArea codeArea) { this.codeArea = codeArea; this.controller = controller; codeArea.setOnMousePressed(e -> { // Only accept right-click presses if (e.getButton() != MouseButton.SECONDARY) return; // Reset codeArea.setContextMenu(null); // Mouse to location CharacterHit hit = codeArea.hit(e.getX(), e.getY()); int charPos = hit.getInsertionIndex(); codeArea.getCaretSelectionBind().displaceCaret(charPos); TwoDimensional.Position pos = codeArea.offsetToPosition(charPos, TwoDimensional.Bias.Backward); // Get selection Object selection = getSelection(pos); if (selection == null) return; if (consumer != null) consumer.accept(selection); }); }
Example #9
Source File: JavaContextHandling.java From Recaf with MIT License | 6 votes |
/** * @param controller * Controller to pull info from. * @param codeArea * Text editor events originate from. */ public JavaContextHandling(GuiController controller, CodeArea codeArea) { super(controller, codeArea); // Fetch the solver so we can call it manually (see below for why) Optional<SymbolResolver> optSolver = controller.getWorkspace().getSourceParseConfig().getSymbolResolver(); if (!optSolver.isPresent()) throw new IllegalStateException(""); this.solver = optSolver.get(); // Set context selection action onContextRequest(selection -> { if (selection instanceof ClassSelection) { handleClassType((ClassSelection) selection); } else if (selection instanceof MemberSelection){ handleMemberType((MemberSelection) selection); } }); }
Example #10
Source File: BytecodeContextHandling.java From Recaf with MIT License | 6 votes |
/** * @param controller * Controller to use. * @param codeArea * Controller to pull info from. */ public BytecodeContextHandling(GuiController controller, CodeArea codeArea) { super(controller, codeArea); // Set context selection action onContextRequest(selection -> { if(selection instanceof ClassSelection) { handleClassType((ClassSelection) selection); } else if(selection instanceof MemberSelection) { handleMemberType((MemberSelection) selection); } else if(selection instanceof LabelSelection) { handleLabelType((LabelSelection) selection); } else if(selection instanceof JumpSelection) { handleJumpType((JumpSelection) selection); } else if(selection instanceof SwitchSelection) { handleSwitchType((SwitchSelection) selection); } else if(selection instanceof VariableSelection) { handleVariableType((VariableSelection) selection); } }); }
Example #11
Source File: GroovyEditorComponent.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Instantiates a new Groovy editor component. * * @param editable the editable */ public GroovyEditorComponent(final boolean editable) { codeArea = new CodeArea(); codeArea.richChanges() .filter(ch -> !ch.getInserted().equals(ch.getRemoved())) .subscribe(change -> codeArea.setStyleSpans(0, getStyleSpans(codeArea.getText()))); codeArea.prefHeightProperty().bind(heightProperty()); codeArea.prefWidthProperty().bind(widthProperty()); codeArea.setEditable(editable); codeArea.setOnKeyReleased(UiUtils::consumeIfIsNotHotKey); codeArea.setOnKeyPressed(UiUtils::consumeIfIsNotHotKey); FXUtils.addToPane(codeArea, this); FXUtils.addClassesTo(this, CssClasses.TEXT_EDITOR_TEXT_AREA, CssClasses.GROOVY_EDITOR_COMPONENT); }
Example #12
Source File: CodeAreaFileEditor.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @BackgroundThread public void doSave(@NotNull final Path toStore) throws IOException { super.doSave(toStore); final CodeArea codeArea = getCodeArea(); final String newContent = codeArea.getText(); try (final PrintWriter out = new PrintWriter(Files.newOutputStream(toStore))) { out.print(newContent); } }
Example #13
Source File: EditorPane.java From Recaf with MIT License | 5 votes |
/** * @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 #14
Source File: CutCopyPasteTests.java From RichTextFX with BSD 2-Clause "Simplified" License | 5 votes |
@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 #15
Source File: CodeAreaFileEditor.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void postSave() { super.postSave(); final CodeArea codeArea = getCodeArea(); final String newContent = codeArea.getText(); setOriginalContent(newContent); updateDirty(newContent); }
Example #16
Source File: DisassemblerView.java From standalone-app with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<byte[]> save(Node node) { if (!(node instanceof CodeArea)) { return CompletableFuture.completedFuture(new byte[0]); } String assembledCode = ((CodeArea) node).getText(); CompletableFuture<byte[]> future = new CompletableFuture<>(); backgroundTaskHelper.submit(new BackgroundTask(Message.TASK_ASSEMBLE_FILE.format(node.getProperties().get("path").toString()), true, () -> { if (controller instanceof KrakatauDisassemblerController) { KrakatauAssemblerSettings settings = new KrakatauAssemblerSettings(); settings.setPythonExecutable(new File(configuration.getString(Settings.PYTHON2_KEY))); settings.setProcessCreator(processController::launchProcess); try { TransformationResult<byte[]> result = StandardTransformers.Assemblers.KRAKATAU.assemble(assembledCode, settings); if (result.getTransformationData().size() == 1) { future.complete(result.getTransformationData().values().iterator().next()); } else { future.completeExceptionally(new KrakatauException(KrakatauException.Reason.UNKNOWN, result.getStdout(), result.getStderr())); } } catch (TransformationException e) { future.completeExceptionally(e); } } else { future.complete(new byte[0]); } })); return future; }
Example #17
Source File: DisassemblerView.java From standalone-app with Apache License 2.0 | 5 votes |
private Task<StyleSpans<Collection<String>>> computeHighlightingAsync(CodeArea codeArea) { String text = codeArea.getText(); Task<StyleSpans<Collection<String>>> task = new Task<StyleSpans<Collection<String>>>() { @Override protected StyleSpans<Collection<String>> call() throws Exception { return computeHighlighting(text); } }; Executors.newSingleThreadExecutor().execute(task); return task; }
Example #18
Source File: DecompilerView.java From standalone-app with Apache License 2.0 | 5 votes |
private Task<StyleSpans<Collection<String>>> computeHighlightingAsync(CodeArea codeArea) { String text = codeArea.getText(); Task<StyleSpans<Collection<String>>> task = new Task<StyleSpans<Collection<String>>>() { @Override protected StyleSpans<Collection<String>> call() throws Exception { return computeHighlighting(text); } }; Executors.newSingleThreadExecutor().execute(task); return task; }
Example #19
Source File: JavaKeywordsAsyncDemo.java From RichTextFX with BSD 2-Clause "Simplified" License | 5 votes |
@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 #20
Source File: PmdCoordinatesSystem.java From pmd-designer with BSD 2-Clause "Simplified" License | 5 votes |
/** * Inverse of {@link #getOffsetFromPmdPosition(CodeArea, int, int)}. Converts an absolute offset * obtained from the given code area into the line and column a PMD parser would have assigned to * it. */ public static TextPos2D getPmdLineAndColumnFromOffset(CodeArea codeArea, int absoluteOffset) { Position pos = codeArea.offsetToPosition(absoluteOffset, Bias.Forward); return new TextPos2D(getPmdLineFromRtfxParIndex(pos.getMajor()), getPmdColumnIndexFromRtfxColumn(codeArea, pos.getMajor(), pos.getMinor())); }
Example #21
Source File: RichTextFXCodeAreaElementTest.java From marathonv5 with Apache License 2.0 | 5 votes |
@Test public void getText() { CodeArea codeAreaNode = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-area"); AssertJUnit.assertEquals("", codeArea.getText()); Platform.runLater(() -> { codeArea.marathon_select("Hello World"); }); new Wait("Waiting for the text area value to be set") { @Override public boolean until() { return "Hello World".equals(codeAreaNode.getText()); } }; AssertJUnit.assertEquals("Hello World", codeArea.getText()); }
Example #22
Source File: PmdCoordinatesSystem.java From pmd-designer with BSD 2-Clause "Simplified" License | 5 votes |
private static int getRtfxColumnIndexFromPmdColumn(CodeArea codeArea, int parIdx, int column) { String parTxt = codeArea.getParagraph(parIdx).getText(); int end = column - 1; for (int i = 0; i < end && end > 0; i++) { char c = parTxt.charAt(i); if (c == '\t') { end = max(end - 7, 0); } } return end; }
Example #23
Source File: PmdCoordinatesSystem.java From pmd-designer with BSD 2-Clause "Simplified" License | 5 votes |
private static int getPmdColumnIndexFromRtfxColumn(CodeArea codeArea, int parIdx, int rtfxCol) { String parTxt = codeArea.getParagraph(parIdx).getText(); int mapped = rtfxCol; for (int i = 0; i < rtfxCol && i < parTxt.length(); i++) { char c = parTxt.charAt(i); if (c == '\t') { mapped += 7; } } return mapped + 1; }
Example #24
Source File: PmdCoordinatesSystem.java From pmd-designer with BSD 2-Clause "Simplified" License | 5 votes |
/** * Returns a {@link TextPos2D} that uses its coordinates as begin * and end offset of the [node] in the [area]. */ public static TextPos2D rtfxRangeOf(Node node, CodeArea area) { return new TextPos2D( getOffsetFromPmdPosition(area, node.getBeginLine(), node.getBeginColumn()), getOffsetFromPmdPosition(area, node.getEndLine(), node.getEndColumn()) ); }
Example #25
Source File: GroovyCodeAreaConfigurator.java From kafka-message-tool with MIT License | 5 votes |
public static void configure(CodeArea codeArea, Executor executor) { CodeAreaConfigurator.configureCodeArea(codeArea, PATTERN, GroovyCodeAreaConfigurator::getStyleClass, executor); }
Example #26
Source File: CodeAreaConfigurator.java From kafka-message-tool with MIT License | 5 votes |
public static void configureCodeArea(CodeArea codeArea, Pattern pattern, Function<Matcher, String> getStyleClassFunction, Executor executor ) { codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea)); codeArea.richChanges() .filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX .successionEnds(Duration.ofMillis(WAIT_PERIOD_TO_START_HIGHLIGHTING_AFTER_LAST_KEY_PRESSED)) .supplyTask(() -> CodeAreaConfigurator.computeHighlightingAsync(codeArea, pattern, getStyleClassFunction, executor)) .awaitLatest(codeArea.richChanges()) .filterMap(t -> { if (t.isSuccess()) { return Optional.of(t.get()); } else { t.getFailure().printStackTrace(); return Optional.empty(); } }) .subscribe(highlighting -> codeArea.setStyleSpans(0, highlighting)); }
Example #27
Source File: CodeAreaConfigurator.java From kafka-message-tool with MIT License | 5 votes |
private static Task<StyleSpans<Collection<String>>> computeHighlightingAsync(CodeArea codeArea, Pattern pattern, Function<Matcher, String> getStyleClassFunction, Executor executor) { String text = codeArea.getText(); Task<StyleSpans<Collection<String>>> task = new Task<StyleSpans<Collection<String>>>() { @Override protected StyleSpans<Collection<String>> call() throws Exception { return computeHighlighting(text, pattern, getStyleClassFunction); } }; executor.execute(task); return task; }
Example #28
Source File: RichTextFXCodeAreaElementTest.java From marathonv5 with Apache License 2.0 | 5 votes |
@Test public void marathon_select() { CodeArea codeAreaNode = (CodeArea) getPrimaryStage().getScene().getRoot().lookup(".code-area"); Platform.runLater(() -> { codeArea.marathon_select("Hello World"); }); new Wait("Waiting for the text area value to be set") { @Override public boolean until() { return "Hello World".equals(codeAreaNode.getText()); } }; }
Example #29
Source File: CodeAreaSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public CodeAreaSample() { CodeArea codeArea = new CodeArea(); codeArea.setId("codeArea"); codeArea.setMaxSize(250, 250); VBox root = new VBox(); root.getChildren().addAll(codeArea, new Button("Click Me!!")); getChildren().add(root); }
Example #30
Source File: DefaultControllerProvider.java From kafka-message-tool with MIT License | 4 votes |
@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; } }); }