diff --git a/.gitignore b/.gitignore index 1ac65c4..d3c9b53 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ dependency-reduced-pom.xml /BugReporter/src/META-INF/ BugReporter/src/META-INF/ +Everest/ out/ \ No newline at end of file diff --git a/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java b/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java index 21cb390..b4cde5c 100644 --- a/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java +++ b/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java @@ -16,6 +16,8 @@ package com.rohitawate.everest.controllers; +import com.rohitawate.everest.controllers.responsearea.EverestCodeArea; +import com.rohitawate.everest.controllers.responsearea.EverestCodeArea.HighlightMode; import com.rohitawate.everest.models.DashboardState; import com.rohitawate.everest.models.requests.DataDispatchRequest; import com.rohitawate.everest.util.Services; @@ -24,9 +26,14 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; -import javafx.scene.control.*; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Tab; +import javafx.scene.control.TabPane; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; import javafx.stage.FileChooser; import javafx.stage.Window; +import org.fxmisc.flowless.VirtualizedScrollPane; import javax.ws.rs.core.MediaType; import java.io.IOException; @@ -46,12 +53,13 @@ public class BodyTabController implements Initializable { @FXML ComboBox rawInputTypeBox; @FXML - TextArea rawInputArea; - @FXML Tab rawTab, binaryTab, formTab, urlTab; @FXML TextField filePathField; + @FXML + private VBox rawVBox; + EverestCodeArea rawInputArea; FormDataTabController formDataTabController; URLTabController urlTabController; @@ -60,6 +68,29 @@ public class BodyTabController implements Initializable { rawInputTypeBox.getItems().addAll("PLAIN TEXT", "JSON", "XML", "HTML"); rawInputTypeBox.getSelectionModel().select(0); + rawInputArea = new EverestCodeArea(); + rawInputArea.setPrefHeight(1500); // Hack to make the EverestCodeArea stretch with the Composer + rawVBox.getChildren().add(new VirtualizedScrollPane<>(rawInputArea)); + + rawInputTypeBox.valueProperty().addListener(change -> { + String type = rawInputTypeBox.getValue(); + HighlightMode mode; + switch (type) { + case "JSON": + mode = HighlightMode.JSON; + break; + case "XML": + mode = HighlightMode.XML; + break; + case "HTML": + mode = HighlightMode.HTML; + break; + default: + mode = HighlightMode.NONE; + } + rawInputArea.setMode(mode); + }); + try { FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/homewindow/FormDataTab.fxml")); formTab.setContent(loader.load()); @@ -172,7 +203,23 @@ public class BodyTabController implements Initializable { } private void setRawTab(DashboardState dashboardState, String contentType) { - rawInputArea.setText(dashboardState.getBody()); + HighlightMode mode; + + switch (contentType) { + case MediaType.APPLICATION_JSON: + mode = HighlightMode.JSON; + break; + case MediaType.APPLICATION_XML: + mode = HighlightMode.XML; + break; + case MediaType.TEXT_HTML: + mode = HighlightMode.HTML; + break; + default: + mode = HighlightMode.NONE; + } + + rawInputArea.setText(dashboardState.getBody(), mode); rawInputTypeBox.getSelectionModel().select(contentType); bodyTabPane.getSelectionModel().select(rawTab); } diff --git a/src/main/java/com/rohitawate/everest/controllers/responsearea/EverestCodeArea.java b/src/main/java/com/rohitawate/everest/controllers/responsearea/EverestCodeArea.java index 314d8c9..dad5b15 100644 --- a/src/main/java/com/rohitawate/everest/controllers/responsearea/EverestCodeArea.java +++ b/src/main/java/com/rohitawate/everest/controllers/responsearea/EverestCodeArea.java @@ -8,27 +8,30 @@ import java.time.Duration; public class EverestCodeArea extends CodeArea { public enum HighlightMode { - JSON, XML, NONE + JSON, XML, HTML, NONE } private Highlighter highlighter; private JSONHighlighter jsonHighlighter; public EverestCodeArea() { - this.getStylesheets().add(getClass().getResource("/css/syntax/Ganges.css").toString()); + this.getStylesheets().add(getClass().getResource("/css/syntax/Moondust.css").toString()); this.getStyleClass().add("everest-code-area"); + jsonHighlighter = new JSONHighlighter(); + this.multiPlainChanges() .successionEnds(Duration.ofMillis(1)) .subscribe(ignore -> this.setStyleSpans(0, highlighter.computeHighlighting(getText()))); + } - jsonHighlighter = new JSONHighlighter(); + public void setMode(HighlightMode mode) { + highlighter = mode == HighlightMode.JSON ? jsonHighlighter : jsonHighlighter; } public void setText(String text, HighlightMode mode) { clear(); appendText(text); - - highlighter = mode == HighlightMode.JSON ? jsonHighlighter : jsonHighlighter; + setMode(mode); } } diff --git a/src/main/resources/css/syntax/Ganges.css b/src/main/resources/css/syntax/Moondust.css similarity index 99% rename from src/main/resources/css/syntax/Ganges.css rename to src/main/resources/css/syntax/Moondust.css index 9a3311f..9e994c0 100644 --- a/src/main/resources/css/syntax/Ganges.css +++ b/src/main/resources/css/syntax/Moondust.css @@ -1,3 +1,17 @@ +.everest-code-area { + -fx-background-color: #282828; +} + +.everest-code-area .text { + -fx-fill: azure; + -fx-font-family: "Liberation Mono"; + -fx-font-size: 17px; +} + +.everest-code-area .caret { + -fx-stroke: white; +} + .json_curly { -fx-fill: coral !important; } @@ -24,17 +38,3 @@ -fx-fill: greenyellow !important; -fx-font-weight: bold; } - -.everest-code-area { - -fx-background-color: #282828; -} - -.everest-code-area .text { - -fx-fill: azure; - -fx-font-family: "Liberation Mono"; - -fx-font-size: 17px; -} - -.everest-code-area .caret { - -fx-stroke: white; -} \ No newline at end of file diff --git a/src/main/resources/fxml/homewindow/BodyTab.fxml b/src/main/resources/fxml/homewindow/BodyTab.fxml index 67c457a..862229c 100644 --- a/src/main/resources/fxml/homewindow/BodyTab.fxml +++ b/src/main/resources/fxml/homewindow/BodyTab.fxml @@ -28,32 +28,15 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + +