Remove HBoxes and VBoxes from TreeVisualizer and add new abstract Visualizer class

This commit is contained in:
Rohit Awate 2018-08-09 11:34:55 +05:30
parent 56fab0d48d
commit f735667d42
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
4 changed files with 41 additions and 49 deletions

View file

@ -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.ComposerState;
import com.rohitawate.everest.controllers.state.DashboardState; import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.controllers.state.FieldState; 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.RedirectException;
import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.exceptions.UnreliableResponseException;
import com.rohitawate.everest.format.FormatterFactory; import com.rohitawate.everest.format.FormatterFactory;
@ -191,7 +193,7 @@ public class DashboardController implements Initializable {
responseArea.setHighlighter(HighlighterFactory.getHighlighter(type)); responseArea.setHighlighter(HighlighterFactory.getHighlighter(type));
}); });
visualizer = new Visualizer(); visualizer = new TreeVisualizer();
visualizerTab.setContent(visualizer); visualizerTab.setContent(visualizer);
responseArea = new EverestCodeArea(); responseArea = new EverestCodeArea();

View file

@ -14,50 +14,42 @@
* limitations under the License. * limitations under the License.
*/ */
package com.rohitawate.everest.controllers; package com.rohitawate.everest.controllers.visualizers;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.EverestUtilities;
import javafx.scene.control.*; import javafx.scene.control.TreeItem;
import javafx.scene.layout.HBox; import javafx.scene.control.TreeView;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
class Visualizer extends ScrollPane { public class TreeVisualizer extends Visualizer {
private TreeView<HBox> visualizer; private TreeView<String> visualizer;
Visualizer() { public TreeVisualizer() {
visualizer = new TreeView<>(); visualizer = new TreeView<>();
visualizer.setShowRoot(false); visualizer.setShowRoot(false);
setContent(this.visualizer); setContent(visualizer);
setFitToHeight(true);
setFitToWidth(true);
} }
void populate(String body) throws IOException { public void populate(String body) throws IOException {
JsonNode tree = EverestUtilities.jsonMapper.readTree(body); JsonNode tree = EverestUtilities.jsonMapper.readTree(body);
this.populate(new TreeItem<>(), "root", tree); this.populate(new TreeItem<>(), "root", tree);
} }
private void populate(TreeItem<HBox> rootItem, String rootName, JsonNode root) { private void populate(TreeItem<String> rootItem, String rootName, JsonNode root) {
if (rootName.equals("root")) { if (rootName.equals("root")) {
visualizer.setRoot(rootItem); visualizer.setRoot(rootItem);
} }
Label rootLabel = new Label(rootName); rootItem.setValue(rootName);
rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
rootItem.setValue(new HBox(rootLabel));
JsonNode currentNode; JsonNode currentNode;
Label valueLabel; List<TreeItem<String>> items = new ArrayList<>();
HBox valueContainer;
List<TreeItem<HBox>> items = new LinkedList<>();
Tooltip valueTooltip;
if (root.isArray()) { if (root.isArray()) {
Iterator<JsonNode> iterator = root.elements(); Iterator<JsonNode> iterator = root.elements();
@ -67,16 +59,9 @@ class Visualizer extends ScrollPane {
currentNode = iterator.next(); currentNode = iterator.next();
if (currentNode.isValueNode()) { if (currentNode.isValueNode()) {
valueLabel = new Label(i++ + ": " + currentNode.toString()); items.add(new TreeItem<>(i++ + ": " + EverestUtilities.trimString(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));
} else if (currentNode.isObject()) { } else if (currentNode.isObject()) {
TreeItem<HBox> newRoot = new TreeItem<>(); TreeItem<String> newRoot = new TreeItem<>();
items.add(newRoot); items.add(newRoot);
populate(newRoot, i++ + ": [Anonymous Object]", currentNode); populate(newRoot, i++ + ": [Anonymous Object]", currentNode);
} }
@ -84,29 +69,16 @@ class Visualizer extends ScrollPane {
} else { } else {
Iterator<Map.Entry<String, JsonNode>> iterator = root.fields(); Iterator<Map.Entry<String, JsonNode>> iterator = root.fields();
Map.Entry<String, JsonNode> currentEntry; Map.Entry<String, JsonNode> currentEntry;
Label keyLabel;
Tooltip keyTooltip;
while (iterator.hasNext()) { while (iterator.hasNext()) {
currentEntry = iterator.next(); currentEntry = iterator.next();
currentNode = currentEntry.getValue(); currentNode = currentEntry.getValue();
if (currentNode.isValueNode()) { if (currentNode.isValueNode()) {
keyLabel = new Label(currentEntry.getKey() + ": "); items.add(new TreeItem<>(currentEntry.getKey() + ": "
keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel"); + EverestUtilities.trimString(currentNode.toString())));
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));
} else if (currentNode.isArray() || currentNode.isObject()) { } else if (currentNode.isArray() || currentNode.isObject()) {
TreeItem<HBox> newRoot = new TreeItem<>(); TreeItem<String> newRoot = new TreeItem<>();
items.add(newRoot); items.add(newRoot);
populate(newRoot, currentEntry.getKey(), currentNode); populate(newRoot, currentEntry.getKey(), currentNode);
} }

View file

@ -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();
}

View file

@ -294,7 +294,7 @@
-fx-font-size: 15px; -fx-font-size: 15px;
} }
/* Response Visualizer */ /* ---------------------------- TreeVisualizer ------------------------- */
#responseTabPane:bottom .tab-header-area .tab-header-background, #responseTabPane:bottom .tab-header-area .tab-header-background,
#responseTabPane:bottom .tab-header-area .headers-region .tab:bottom { #responseTabPane:bottom .tab-header-area .headers-region .tab:bottom {
-fx-background-color: #282828; -fx-background-color: #282828;
@ -338,8 +338,8 @@
-fx-text-fill: #959595; -fx-text-fill: #959595;
} }
/* Visualizer tree */
.tree-view { .tree-view {
-fx-padding: 5px;
-fx-background-color: #353535; -fx-background-color: #353535;
} }
@ -354,6 +354,9 @@
.tree-cell { .tree-cell {
-fx-background-color: #282828; -fx-background-color: #282828;
-fx-text-fill: azure;
-fx-font-size: 15px;
-fx-font-family: "Liberation Mono", monospace;
-fx-border-width: 0px; -fx-border-width: 0px;
} }
@ -377,7 +380,7 @@
-fx-padding: 0; -fx-padding: 0;
} }
/* SnackBar */ /* Snackbar */
.jfx-snackbar-content { .jfx-snackbar-content {
-fx-background-color: black; -fx-background-color: black;
} }