diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index 57f8ba3..fb277df 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -23,6 +23,8 @@ import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFacto import com.rohitawate.everest.controllers.state.ComposerState; import com.rohitawate.everest.controllers.state.DashboardState; import com.rohitawate.everest.controllers.state.FieldState; +import com.rohitawate.everest.controllers.visualizers.TreeVisualizer; +import com.rohitawate.everest.controllers.visualizers.Visualizer; import com.rohitawate.everest.exceptions.RedirectException; import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.format.FormatterFactory; @@ -191,7 +193,7 @@ public class DashboardController implements Initializable { responseArea.setHighlighter(HighlighterFactory.getHighlighter(type)); }); - visualizer = new Visualizer(); + visualizer = new TreeVisualizer(); visualizerTab.setContent(visualizer); responseArea = new EverestCodeArea(); diff --git a/src/main/java/com/rohitawate/everest/controllers/Visualizer.java b/src/main/java/com/rohitawate/everest/controllers/visualizers/TreeVisualizer.java similarity index 50% rename from src/main/java/com/rohitawate/everest/controllers/Visualizer.java rename to src/main/java/com/rohitawate/everest/controllers/visualizers/TreeVisualizer.java index 9512d02..68e72db 100644 --- a/src/main/java/com/rohitawate/everest/controllers/Visualizer.java +++ b/src/main/java/com/rohitawate/everest/controllers/visualizers/TreeVisualizer.java @@ -14,50 +14,42 @@ * limitations under the License. */ -package com.rohitawate.everest.controllers; +package com.rohitawate.everest.controllers.visualizers; import com.fasterxml.jackson.databind.JsonNode; import com.rohitawate.everest.misc.EverestUtilities; -import javafx.scene.control.*; -import javafx.scene.layout.HBox; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeView; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; -class Visualizer extends ScrollPane { - private TreeView visualizer; +public class TreeVisualizer extends Visualizer { + private TreeView visualizer; - Visualizer() { + public TreeVisualizer() { visualizer = new TreeView<>(); visualizer.setShowRoot(false); - setContent(this.visualizer); - - setFitToHeight(true); - setFitToWidth(true); + setContent(visualizer); } - void populate(String body) throws IOException { + public void populate(String body) throws IOException { JsonNode tree = EverestUtilities.jsonMapper.readTree(body); this.populate(new TreeItem<>(), "root", tree); } - private void populate(TreeItem rootItem, String rootName, JsonNode root) { + private void populate(TreeItem rootItem, String rootName, JsonNode root) { if (rootName.equals("root")) { visualizer.setRoot(rootItem); } - Label rootLabel = new Label(rootName); - rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel"); - rootItem.setValue(new HBox(rootLabel)); + rootItem.setValue(rootName); JsonNode currentNode; - Label valueLabel; - HBox valueContainer; - List> items = new LinkedList<>(); - Tooltip valueTooltip; + List> items = new ArrayList<>(); if (root.isArray()) { Iterator iterator = root.elements(); @@ -67,16 +59,9 @@ class Visualizer extends ScrollPane { currentNode = iterator.next(); if (currentNode.isValueNode()) { - valueLabel = new Label(i++ + ": " + currentNode.toString()); - valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel"); - valueLabel.setWrapText(true); - valueTooltip = new Tooltip(currentNode.toString()); - valueLabel.setTooltip(valueTooltip); - - valueContainer = new HBox(valueLabel); - items.add(new TreeItem<>(valueContainer)); + items.add(new TreeItem<>(i++ + ": " + EverestUtilities.trimString(currentNode.toString()))); } else if (currentNode.isObject()) { - TreeItem newRoot = new TreeItem<>(); + TreeItem newRoot = new TreeItem<>(); items.add(newRoot); populate(newRoot, i++ + ": [Anonymous Object]", currentNode); } @@ -84,29 +69,16 @@ class Visualizer extends ScrollPane { } else { Iterator> iterator = root.fields(); Map.Entry currentEntry; - Label keyLabel; - Tooltip keyTooltip; while (iterator.hasNext()) { currentEntry = iterator.next(); currentNode = currentEntry.getValue(); if (currentNode.isValueNode()) { - keyLabel = new Label(currentEntry.getKey() + ": "); - keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel"); - keyTooltip = new Tooltip(currentEntry.getKey()); - keyLabel.setTooltip(keyTooltip); - - valueLabel = new Label(currentNode.toString()); - valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel"); - valueLabel.setWrapText(true); - valueTooltip = new Tooltip(currentNode.toString()); - valueLabel.setTooltip(valueTooltip); - - valueContainer = new HBox(keyLabel, valueLabel); - items.add(new TreeItem<>(valueContainer)); + items.add(new TreeItem<>(currentEntry.getKey() + ": " + + EverestUtilities.trimString(currentNode.toString()))); } else if (currentNode.isArray() || currentNode.isObject()) { - TreeItem newRoot = new TreeItem<>(); + TreeItem newRoot = new TreeItem<>(); items.add(newRoot); populate(newRoot, currentEntry.getKey(), currentNode); } diff --git a/src/main/java/com/rohitawate/everest/controllers/visualizers/Visualizer.java b/src/main/java/com/rohitawate/everest/controllers/visualizers/Visualizer.java new file mode 100644 index 0000000..bec9997 --- /dev/null +++ b/src/main/java/com/rohitawate/everest/controllers/visualizers/Visualizer.java @@ -0,0 +1,15 @@ +package com.rohitawate.everest.controllers.visualizers; + +import javafx.scene.control.ScrollPane; + +public abstract class Visualizer extends ScrollPane { + + Visualizer() { + setFitToHeight(true); + setFitToWidth(true); + } + + public abstract void populate(String body) throws Exception; + + public abstract void clear(); +} diff --git a/src/main/resources/css/Adreana.css b/src/main/resources/css/Adreana.css index 7e2646d..74b6334 100644 --- a/src/main/resources/css/Adreana.css +++ b/src/main/resources/css/Adreana.css @@ -294,7 +294,7 @@ -fx-font-size: 15px; } -/* Response Visualizer */ +/* ---------------------------- TreeVisualizer ------------------------- */ #responseTabPane:bottom .tab-header-area .tab-header-background, #responseTabPane:bottom .tab-header-area .headers-region .tab:bottom { -fx-background-color: #282828; @@ -338,8 +338,8 @@ -fx-text-fill: #959595; } -/* Visualizer tree */ .tree-view { + -fx-padding: 5px; -fx-background-color: #353535; } @@ -354,6 +354,9 @@ .tree-cell { -fx-background-color: #282828; + -fx-text-fill: azure; + -fx-font-size: 15px; + -fx-font-family: "Liberation Mono", monospace; -fx-border-width: 0px; } @@ -377,7 +380,7 @@ -fx-padding: 0; } -/* SnackBar */ +/* Snackbar */ .jfx-snackbar-content { -fx-background-color: black; }