corefx - added throughput display toggle

This commit is contained in:
Blake J. Harnden 2018-12-20 09:22:40 -08:00
parent c45a0af088
commit 2a879ce0ba
5 changed files with 48 additions and 13 deletions

View file

@ -42,6 +42,7 @@ import java.util.stream.Collectors;
public class NetworkGraph { public class NetworkGraph {
private static final Logger logger = LogManager.getLogger(); private static final Logger logger = LogManager.getLogger();
private static final int EDGE_LABEL_OFFSET = -5; private static final int EDGE_LABEL_OFFSET = -5;
private static final int EDGE_WIDTH = 5;
private Controller controller; private Controller controller;
private ObservableGraph<CoreNode, CoreLink> graph; private ObservableGraph<CoreNode, CoreLink> graph;
private StaticLayout<CoreNode, CoreLink> graphLayout; private StaticLayout<CoreNode, CoreLink> graphLayout;
@ -64,6 +65,8 @@ public class NetworkGraph {
// display options // display options
private boolean showThroughput = false; private boolean showThroughput = false;
private Double throughputLimit = null;
private int throughputWidth = 10;
public NetworkGraph(Controller controller) { public NetworkGraph(Controller controller) {
this.controller = controller; this.controller = controller;
@ -90,22 +93,28 @@ public class NetworkGraph {
}); });
// link render properties // link render properties
renderContext.setEdgeLabelTransformer(link -> { renderContext.setEdgeLabelTransformer(edge -> {
if (!showThroughput || link == null) { if (!showThroughput || edge == null) {
return null; return null;
} }
double kbps = link.getThroughput() / 1000.0; double kbps = edge.getThroughput() / 1000.0;
return String.format("%.2f kbps", kbps); return String.format("%.2f kbps", kbps);
}); });
renderContext.setLabelOffset(EDGE_LABEL_OFFSET); renderContext.setLabelOffset(EDGE_LABEL_OFFSET);
renderContext.setEdgeStrokeTransformer(edge -> { renderContext.setEdgeStrokeTransformer(edge -> {
// determine edge width
int width = EDGE_WIDTH;
if (throughputLimit != null && edge.getThroughput() > throughputLimit) {
width = throughputWidth;
}
LinkTypes linkType = LinkTypes.get(edge.getType()); LinkTypes linkType = LinkTypes.get(edge.getType());
if (LinkTypes.WIRELESS == linkType) { if (LinkTypes.WIRELESS == linkType) {
float[] dash = {15.0f}; 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); 0, dash, 0);
} else { } else {
return new BasicStroke(5); return new BasicStroke(width);
} }
}); });
renderContext.setEdgeShapeTransformer(EdgeShape.line(graph)); renderContext.setEdgeShapeTransformer(EdgeShape.line(graph));
@ -204,6 +213,10 @@ public class NetworkGraph {
Color nodeLabelColor = convertJfxColor(configuration.getNodeLabelColor()); Color nodeLabelColor = convertJfxColor(configuration.getNodeLabelColor());
Color nodeLabelBackgroundColor = convertJfxColor(configuration.getNodeLabelBackgroundColor()); Color nodeLabelBackgroundColor = convertJfxColor(configuration.getNodeLabelBackgroundColor());
nodeLabelRenderer.setColors(nodeLabelColor, nodeLabelBackgroundColor); nodeLabelRenderer.setColors(nodeLabelColor, nodeLabelBackgroundColor);
throughputLimit = configuration.getThroughputLimit();
if (configuration.getThroughputWidth() != null) {
throughputWidth = configuration.getThroughputWidth();
}
graphViewer.repaint(); graphViewer.repaint();
} }

View file

@ -24,6 +24,8 @@ public class GuiPreferencesDialog extends StageDialog {
@FXML private JFXTextField iconPathTextField; @FXML private JFXTextField iconPathTextField;
@FXML private JFXColorPicker nodeLabelColorPicker; @FXML private JFXColorPicker nodeLabelColorPicker;
@FXML private JFXColorPicker nodeLabelBackgroundColorPicker; @FXML private JFXColorPicker nodeLabelBackgroundColorPicker;
@FXML private JFXTextField throughputLimitTextField;
@FXML private JFXTextField throughputWidthTextField;
@FXML private JFXButton saveButton; @FXML private JFXButton saveButton;
public GuiPreferencesDialog(Controller controller) { public GuiPreferencesDialog(Controller controller) {
@ -42,6 +44,8 @@ public class GuiPreferencesDialog extends StageDialog {
configuration.setIconPath(iconPathTextField.getText()); configuration.setIconPath(iconPathTextField.getText());
configuration.setNodeLabelColor(nodeLabelColorPicker.getValue().toString()); configuration.setNodeLabelColor(nodeLabelColorPicker.getValue().toString());
configuration.setNodeLabelBackgroundColor(nodeLabelBackgroundColorPicker.getValue().toString()); configuration.setNodeLabelBackgroundColor(nodeLabelBackgroundColorPicker.getValue().toString());
configuration.setThroughputLimit(Double.parseDouble(throughputLimitTextField.getText()));
configuration.setThroughputWidth(Integer.parseInt(throughputWidthTextField.getText()));
getController().getNetworkGraph().updatePreferences(configuration); getController().getNetworkGraph().updatePreferences(configuration);
try { try {
ConfigUtils.save(configuration); ConfigUtils.save(configuration);
@ -60,6 +64,17 @@ public class GuiPreferencesDialog extends StageDialog {
iconPathTextField.setText(configuration.getIconPath()); iconPathTextField.setText(configuration.getIconPath());
nodeLabelColorPicker.setValue(Color.web(configuration.getNodeLabelColor())); nodeLabelColorPicker.setValue(Color.web(configuration.getNodeLabelColor()));
nodeLabelBackgroundColorPicker.setValue(Color.web(configuration.getNodeLabelBackgroundColor())); 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(); show();
} }
} }

View file

@ -18,4 +18,6 @@ public class Configuration {
private List<NodeTypeConfig> nodeTypeConfigs = new ArrayList<>(); private List<NodeTypeConfig> nodeTypeConfigs = new ArrayList<>();
private String nodeLabelColor; private String nodeLabelColor;
private String nodeLabelBackgroundColor; private String nodeLabelBackgroundColor;
private Double throughputLimit;
private Integer throughputWidth;
} }

View file

@ -2,13 +2,15 @@
<?import com.jfoenix.controls.JFXColorPicker?> <?import com.jfoenix.controls.JFXColorPicker?>
<?import com.jfoenix.controls.JFXTextField?> <?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.TitledPane?> <?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children> <Accordion xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<TitledPane animated="false" collapsible="false" text="File Paths"> <panes>
<TitledPane text="File Paths">
<content> <content>
<VBox spacing="10.0"> <VBox spacing="10.0">
<children> <children>
@ -22,7 +24,7 @@
</VBox> </VBox>
</content> </content>
</TitledPane> </TitledPane>
<TitledPane animated="false" collapsible="false" text="Graph"> <TitledPane text="Graph">
<content> <content>
<VBox spacing="10.0"> <VBox spacing="10.0">
<children> <children>
@ -30,11 +32,15 @@
<JFXColorPicker fx:id="nodeLabelColorPicker" maxWidth="1.7976931348623157E308" /> <JFXColorPicker fx:id="nodeLabelColorPicker" maxWidth="1.7976931348623157E308" />
<Label text="Node Label Background" /> <Label text="Node Label Background" />
<JFXColorPicker fx:id="nodeLabelBackgroundColorPicker" maxWidth="1.7976931348623157E308" /> <JFXColorPicker fx:id="nodeLabelBackgroundColorPicker" maxWidth="1.7976931348623157E308" />
<Label text="Throughput Limit" />
<JFXTextField fx:id="throughputLimitTextField" />
<Label text="Throughput Width" />
<JFXTextField fx:id="throughputWidthTextField" />
</children> </children>
</VBox> </VBox>
</content> </content>
</TitledPane> </TitledPane>
<TitledPane animated="false" collapsible="false" text="Programs"> <TitledPane text="Programs">
<content> <content>
<VBox spacing="10.0"> <VBox spacing="10.0">
<children> <children>
@ -44,5 +50,5 @@
</VBox> </VBox>
</content> </content>
</TitledPane> </TitledPane>
</children> </panes>
</VBox> </Accordion>

View file

@ -45,7 +45,6 @@
<Menu mnemonicParsing="false" text="Widgets"> <Menu mnemonicParsing="false" text="Widgets">
<items> <items>
<CheckMenuItem fx:id="throughputMenuItem" mnemonicParsing="false" text="Throughput" /> <CheckMenuItem fx:id="throughputMenuItem" mnemonicParsing="false" text="Throughput" />
<MenuItem mnemonicParsing="false" text="Throughput Config" />
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Help"> <Menu mnemonicParsing="false" text="Help">