gui - set default emane model for emane nodes, slight update to radio icon to draw a circle for each linked wireless network

This commit is contained in:
Blake J. Harnden 2018-09-17 14:37:20 -07:00
parent f062e2868d
commit 106d993b9d
4 changed files with 42 additions and 20 deletions

View file

@ -1,6 +1,9 @@
package com.core.data; package com.core.data;
import com.core.graph.RadioIcon;
import com.core.utils.IconUtils;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.uci.ics.jung.visualization.LayeredIcon;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -28,6 +31,10 @@ public class CoreNode {
private String icon; private String icon;
@JsonIgnore @JsonIgnore
private boolean loaded = true; private boolean loaded = true;
@JsonIgnore
private LayeredIcon graphIcon;
@JsonIgnore
private RadioIcon radioIcon = new RadioIcon();
public CoreNode(Integer id) { public CoreNode(Integer id) {
this.id = id; this.id = id;
@ -35,6 +42,15 @@ public class CoreNode {
this.loaded = false; this.loaded = false;
} }
public LayeredIcon getGraphIcon() {
if (graphIcon == null) {
graphIcon = IconUtils.getIcon(icon);
graphIcon.add(radioIcon);
}
return graphIcon;
}
@JsonIgnore @JsonIgnore
public String getNodeTypeKey() { public String getNodeTypeKey() {
if (model == null) { if (model == null) {

View file

@ -10,7 +10,6 @@ import edu.uci.ics.jung.graph.ObservableGraph;
import edu.uci.ics.jung.graph.event.GraphEvent; import edu.uci.ics.jung.graph.event.GraphEvent;
import edu.uci.ics.jung.graph.event.GraphEventListener; import edu.uci.ics.jung.graph.event.GraphEventListener;
import edu.uci.ics.jung.graph.util.Pair; import edu.uci.ics.jung.graph.util.Pair;
import edu.uci.ics.jung.visualization.LayeredIcon;
import edu.uci.ics.jung.visualization.RenderContext; import edu.uci.ics.jung.visualization.RenderContext;
import edu.uci.ics.jung.visualization.VisualizationViewer; import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.annotations.AnnotationControls; import edu.uci.ics.jung.visualization.annotations.AnnotationControls;
@ -57,7 +56,6 @@ public class NetworkGraph {
private Set<NodeType> nodeTypes = new HashSet<>(); private Set<NodeType> nodeTypes = new HashSet<>();
private CorePopupGraphMousePlugin customPopupPlugin; private CorePopupGraphMousePlugin customPopupPlugin;
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin; private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
private RadioIcon radioIcon = new RadioIcon();
public NetworkGraph(Controller controller) { public NetworkGraph(Controller controller) {
this.controller = controller; this.controller = controller;
@ -77,13 +75,9 @@ public class NetworkGraph {
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE); return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
}); });
renderContext.setVertexIconTransformer(vertex -> { renderContext.setVertexIconTransformer(vertex -> {
LayeredIcon icon = IconUtils.getIcon(vertex.getIcon()); long wirelessLinks = wirelessLinkCount(vertex);
if (hasWirelessLink(vertex)) { vertex.getRadioIcon().setWiressLinks(wirelessLinks);
icon.add(radioIcon); return vertex.getGraphIcon();
} else {
icon.remove(radioIcon);
}
return icon;
}); });
// edge render properties // edge render properties
@ -312,8 +306,13 @@ public class NetworkGraph {
CoreNode node = vertexEvent.getVertex(); CoreNode node = vertexEvent.getVertex();
if (!node.isLoaded()) { if (!node.isLoaded()) {
node.setType(nodeType.getValue()); node.setType(nodeType.getValue());
node.setIcon(nodeType.getIcon());
node.setModel(nodeType.getModel()); node.setModel(nodeType.getModel());
node.setIcon(nodeType.getIcon());
if (node.getType() == NodeType.EMANE) {
String emaneModel = controller.getNodeEmaneDialog().getModels().get(0);
node.setEmane(emaneModel);
}
logger.info("adding user created node: {}", node); logger.info("adding user created node: {}", node);
nodeMap.put(node.getId(), node); nodeMap.put(node.getId(), node);
} }
@ -369,14 +368,10 @@ public class NetworkGraph {
return result || isWirelessNode(nodeTwo); return result || isWirelessNode(nodeTwo);
} }
private boolean hasWirelessLink(CoreNode node) { private long wirelessLinkCount(CoreNode node) {
for (CoreNode neighbor : graph.getNeighbors(node)) { return graph.getNeighbors(node).stream()
if (isWirelessNode(neighbor)) { .filter(this::isWirelessNode)
return true; .count();
}
}
return false;
} }
public void addLink(CoreLink link) { public void addLink(CoreLink link) {

View file

@ -1,11 +1,15 @@
package com.core.graph; package com.core.graph;
import com.core.utils.IconUtils; import com.core.utils.IconUtils;
import lombok.Data;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@Data
public class RadioIcon implements Icon { public class RadioIcon implements Icon {
private long wiressLinks = 0;
@Override @Override
public int getIconHeight() { public int getIconHeight() {
return IconUtils.ICON_SIZE; return IconUtils.ICON_SIZE;
@ -19,6 +23,9 @@ public class RadioIcon implements Icon {
@Override @Override
public void paintIcon(Component c, Graphics g, int x, int y) { public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(Color.black); g.setColor(Color.black);
g.fillOval(x, y, 10, 10); for (int i = 0; i < wiressLinks; i++) {
g.fillOval(x, y, 10, 10);
x += 15;
}
} }
} }

View file

@ -1,9 +1,9 @@
package com.core.ui; package com.core.ui;
import com.core.Controller; import com.core.Controller;
import com.core.data.CoreNode;
import com.core.client.rest.ConfigOption; import com.core.client.rest.ConfigOption;
import com.core.client.rest.GetConfig; import com.core.client.rest.GetConfig;
import com.core.data.CoreNode;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox; import com.jfoenix.controls.JFXComboBox;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@ -50,6 +50,10 @@ public class NodeEmaneDialog extends StageDialog {
modelCombo.getSelectionModel().selectFirst(); modelCombo.getSelectionModel().selectFirst();
} }
public List<String> getModels() {
return modelCombo.getItems();
}
private void emaneButtonHandler(ActionEvent event) { private void emaneButtonHandler(ActionEvent event) {
try { try {
GetConfig getConfig = getCoreClient().getEmaneConfig(coreNode); GetConfig getConfig = getCoreClient().getEmaneConfig(coreNode);