From 2a879ce0baabca5925eb94dab53b205aeba932c4 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Thu, 20 Dec 2018 09:22:40 -0800 Subject: [PATCH] corefx - added throughput display toggle --- .../java/com/core/graph/NetworkGraph.java | 23 +++++++++++++++---- .../core/ui/dialogs/GuiPreferencesDialog.java | 15 ++++++++++++ .../java/com/core/utils/Configuration.java | 2 ++ .../main/resources/fxml/gui_preferences.fxml | 20 ++++++++++------ corefx/src/main/resources/fxml/main.fxml | 1 - 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/corefx/src/main/java/com/core/graph/NetworkGraph.java b/corefx/src/main/java/com/core/graph/NetworkGraph.java index 69b8b571..7d55cdb2 100644 --- a/corefx/src/main/java/com/core/graph/NetworkGraph.java +++ b/corefx/src/main/java/com/core/graph/NetworkGraph.java @@ -42,6 +42,7 @@ import java.util.stream.Collectors; public class NetworkGraph { private static final Logger logger = LogManager.getLogger(); private static final int EDGE_LABEL_OFFSET = -5; + private static final int EDGE_WIDTH = 5; private Controller controller; private ObservableGraph graph; private StaticLayout graphLayout; @@ -64,6 +65,8 @@ public class NetworkGraph { // display options private boolean showThroughput = false; + private Double throughputLimit = null; + private int throughputWidth = 10; public NetworkGraph(Controller controller) { this.controller = controller; @@ -90,22 +93,28 @@ public class NetworkGraph { }); // link render properties - renderContext.setEdgeLabelTransformer(link -> { - if (!showThroughput || link == null) { + renderContext.setEdgeLabelTransformer(edge -> { + if (!showThroughput || edge == null) { return null; } - double kbps = link.getThroughput() / 1000.0; + double kbps = edge.getThroughput() / 1000.0; return String.format("%.2f kbps", kbps); }); renderContext.setLabelOffset(EDGE_LABEL_OFFSET); renderContext.setEdgeStrokeTransformer(edge -> { + // determine edge width + int width = EDGE_WIDTH; + if (throughputLimit != null && edge.getThroughput() > throughputLimit) { + width = throughputWidth; + } + LinkTypes linkType = LinkTypes.get(edge.getType()); if (LinkTypes.WIRELESS == linkType) { float[] dash = {15.0f}; - return new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, + return new BasicStroke(width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 0, dash, 0); } else { - return new BasicStroke(5); + return new BasicStroke(width); } }); renderContext.setEdgeShapeTransformer(EdgeShape.line(graph)); @@ -204,6 +213,10 @@ public class NetworkGraph { Color nodeLabelColor = convertJfxColor(configuration.getNodeLabelColor()); Color nodeLabelBackgroundColor = convertJfxColor(configuration.getNodeLabelBackgroundColor()); nodeLabelRenderer.setColors(nodeLabelColor, nodeLabelBackgroundColor); + throughputLimit = configuration.getThroughputLimit(); + if (configuration.getThroughputWidth() != null) { + throughputWidth = configuration.getThroughputWidth(); + } graphViewer.repaint(); } diff --git a/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java b/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java index 68c4132a..d0961125 100644 --- a/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java +++ b/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java @@ -24,6 +24,8 @@ public class GuiPreferencesDialog extends StageDialog { @FXML private JFXTextField iconPathTextField; @FXML private JFXColorPicker nodeLabelColorPicker; @FXML private JFXColorPicker nodeLabelBackgroundColorPicker; + @FXML private JFXTextField throughputLimitTextField; + @FXML private JFXTextField throughputWidthTextField; @FXML private JFXButton saveButton; public GuiPreferencesDialog(Controller controller) { @@ -42,6 +44,8 @@ public class GuiPreferencesDialog extends StageDialog { configuration.setIconPath(iconPathTextField.getText()); configuration.setNodeLabelColor(nodeLabelColorPicker.getValue().toString()); configuration.setNodeLabelBackgroundColor(nodeLabelBackgroundColorPicker.getValue().toString()); + configuration.setThroughputLimit(Double.parseDouble(throughputLimitTextField.getText())); + configuration.setThroughputWidth(Integer.parseInt(throughputWidthTextField.getText())); getController().getNetworkGraph().updatePreferences(configuration); try { ConfigUtils.save(configuration); @@ -60,6 +64,17 @@ public class GuiPreferencesDialog extends StageDialog { iconPathTextField.setText(configuration.getIconPath()); nodeLabelColorPicker.setValue(Color.web(configuration.getNodeLabelColor())); nodeLabelBackgroundColorPicker.setValue(Color.web(configuration.getNodeLabelBackgroundColor())); + String throughputLimit = null; + if (configuration.getThroughputLimit() != null) { + throughputLimit = configuration.getThroughputLimit().toString(); + } + throughputLimitTextField.setText(throughputLimit); + + String throughputWidth = null; + if (configuration.getThroughputWidth() != null) { + throughputWidth = configuration.getThroughputWidth().toString(); + } + throughputWidthTextField.setText(throughputWidth); show(); } } diff --git a/corefx/src/main/java/com/core/utils/Configuration.java b/corefx/src/main/java/com/core/utils/Configuration.java index 8cb58cb1..d8866462 100644 --- a/corefx/src/main/java/com/core/utils/Configuration.java +++ b/corefx/src/main/java/com/core/utils/Configuration.java @@ -18,4 +18,6 @@ public class Configuration { private List nodeTypeConfigs = new ArrayList<>(); private String nodeLabelColor; private String nodeLabelBackgroundColor; + private Double throughputLimit; + private Integer throughputWidth; } diff --git a/corefx/src/main/resources/fxml/gui_preferences.fxml b/corefx/src/main/resources/fxml/gui_preferences.fxml index 64057360..99972d24 100644 --- a/corefx/src/main/resources/fxml/gui_preferences.fxml +++ b/corefx/src/main/resources/fxml/gui_preferences.fxml @@ -2,13 +2,15 @@ + - - - + + + + @@ -22,7 +24,7 @@ - + @@ -30,11 +32,15 @@ - + @@ -44,5 +50,5 @@ - - + + diff --git a/corefx/src/main/resources/fxml/main.fxml b/corefx/src/main/resources/fxml/main.fxml index 5cc9f1b4..848b9c83 100644 --- a/corefx/src/main/resources/fxml/main.fxml +++ b/corefx/src/main/resources/fxml/main.fxml @@ -45,7 +45,6 @@ -