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;
import com.core.graph.RadioIcon;
import com.core.utils.IconUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.uci.ics.jung.visualization.LayeredIcon;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@ -28,6 +31,10 @@ public class CoreNode {
private String icon;
@JsonIgnore
private boolean loaded = true;
@JsonIgnore
private LayeredIcon graphIcon;
@JsonIgnore
private RadioIcon radioIcon = new RadioIcon();
public CoreNode(Integer id) {
this.id = id;
@ -35,6 +42,15 @@ public class CoreNode {
this.loaded = false;
}
public LayeredIcon getGraphIcon() {
if (graphIcon == null) {
graphIcon = IconUtils.getIcon(icon);
graphIcon.add(radioIcon);
}
return graphIcon;
}
@JsonIgnore
public String getNodeTypeKey() {
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.GraphEventListener;
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.VisualizationViewer;
import edu.uci.ics.jung.visualization.annotations.AnnotationControls;
@ -57,7 +56,6 @@ public class NetworkGraph {
private Set<NodeType> nodeTypes = new HashSet<>();
private CorePopupGraphMousePlugin customPopupPlugin;
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
private RadioIcon radioIcon = new RadioIcon();
public NetworkGraph(Controller controller) {
this.controller = controller;
@ -77,13 +75,9 @@ public class NetworkGraph {
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
});
renderContext.setVertexIconTransformer(vertex -> {
LayeredIcon icon = IconUtils.getIcon(vertex.getIcon());
if (hasWirelessLink(vertex)) {
icon.add(radioIcon);
} else {
icon.remove(radioIcon);
}
return icon;
long wirelessLinks = wirelessLinkCount(vertex);
vertex.getRadioIcon().setWiressLinks(wirelessLinks);
return vertex.getGraphIcon();
});
// edge render properties
@ -312,8 +306,13 @@ public class NetworkGraph {
CoreNode node = vertexEvent.getVertex();
if (!node.isLoaded()) {
node.setType(nodeType.getValue());
node.setIcon(nodeType.getIcon());
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);
nodeMap.put(node.getId(), node);
}
@ -369,14 +368,10 @@ public class NetworkGraph {
return result || isWirelessNode(nodeTwo);
}
private boolean hasWirelessLink(CoreNode node) {
for (CoreNode neighbor : graph.getNeighbors(node)) {
if (isWirelessNode(neighbor)) {
return true;
}
}
return false;
private long wirelessLinkCount(CoreNode node) {
return graph.getNeighbors(node).stream()
.filter(this::isWirelessNode)
.count();
}
public void addLink(CoreLink link) {

View file

@ -1,11 +1,15 @@
package com.core.graph;
import com.core.utils.IconUtils;
import lombok.Data;
import javax.swing.*;
import java.awt.*;
@Data
public class RadioIcon implements Icon {
private long wiressLinks = 0;
@Override
public int getIconHeight() {
return IconUtils.ICON_SIZE;
@ -19,6 +23,9 @@ public class RadioIcon implements Icon {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
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;
import com.core.Controller;
import com.core.data.CoreNode;
import com.core.client.rest.ConfigOption;
import com.core.client.rest.GetConfig;
import com.core.data.CoreNode;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import javafx.event.ActionEvent;
@ -50,6 +50,10 @@ public class NodeEmaneDialog extends StageDialog {
modelCombo.getSelectionModel().selectFirst();
}
public List<String> getModels() {
return modelCombo.getItems();
}
private void emaneButtonHandler(ActionEvent event) {
try {
GetConfig getConfig = getCoreClient().getEmaneConfig(coreNode);