added way to not display links for wlan/emane, added very basic way to denote a wireless connection for nodes with no visible links
This commit is contained in:
parent
895c3bd5cd
commit
dd9ad5644d
5 changed files with 70 additions and 8 deletions
|
@ -17,6 +17,9 @@ public class CoreLink {
|
|||
@JsonIgnore
|
||||
private boolean loaded = true;
|
||||
|
||||
@JsonIgnore
|
||||
private boolean visible = true;
|
||||
|
||||
private Integer type = 1;
|
||||
|
||||
@JsonProperty("node_one")
|
||||
|
|
|
@ -8,13 +8,13 @@ import java.util.Map;
|
|||
|
||||
@Data
|
||||
public class NodeType {
|
||||
private static final Map<String, NodeType> LOOKUP = new HashMap<>();
|
||||
private static final Map<Integer, String> DISPLAY_MAP = new HashMap<>();
|
||||
public static final int DEFAULT = 0;
|
||||
public static final int SWITCH = 4;
|
||||
public static final int HUB = 5;
|
||||
public static final int WLAN = 6;
|
||||
public static final int EMANE = 10;
|
||||
private static final Map<String, NodeType> LOOKUP = new HashMap<>();
|
||||
private static final Map<Integer, String> DISPLAY_MAP = new HashMap<>();
|
||||
private final int value;
|
||||
private final String display;
|
||||
private final String model;
|
||||
|
|
|
@ -13,6 +13,7 @@ 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;
|
||||
|
@ -67,25 +68,34 @@ public class NetworkGraph {
|
|||
graphViewer.setBackground(Color.WHITE);
|
||||
graphViewer.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S);
|
||||
|
||||
// establish render properties for vertexes/edges
|
||||
RenderContext<CoreNode, CoreLink> renderContext = graphViewer.getRenderContext();
|
||||
|
||||
// vertext render properties
|
||||
renderContext.setVertexLabelTransformer(CoreNode::getName);
|
||||
renderContext.setVertexShapeTransformer(node -> {
|
||||
double offset = -(IconUtils.ICON_SIZE / 2);
|
||||
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
||||
});
|
||||
renderContext.setVertexIconTransformer(vertex -> {
|
||||
LayeredIcon layeredIcon = IconUtils.getIcon(vertex.getIcon());
|
||||
if (hasWirelessLink(vertex)) {
|
||||
RadioIcon radioIcon = new RadioIcon();
|
||||
layeredIcon.add(radioIcon);
|
||||
}
|
||||
return layeredIcon;
|
||||
});
|
||||
|
||||
// edge render properties
|
||||
renderContext.setEdgeStrokeTransformer(edge -> new BasicStroke(1));
|
||||
renderContext.setEdgeShapeTransformer(edge -> new Rectangle2D.Float(0, 0, 1, 10));
|
||||
renderContext.setEdgeFillPaintTransformer(edge -> Color.BLACK);
|
||||
renderContext.setEdgeIncludePredicate(predicate -> predicate.element.isVisible());
|
||||
|
||||
graphViewer.setVertexToolTipTransformer(renderContext.getVertexLabelTransformer());
|
||||
graphMouse = new CoreEditingModalGraphMouse<>(controller, this, renderContext,
|
||||
vertexFactory, linkFactory);
|
||||
graphViewer.setGraphMouse(graphMouse);
|
||||
|
||||
// icons
|
||||
renderContext.setVertexIconTransformer(vertex -> IconUtils.getIcon(vertex.getIcon()));
|
||||
|
||||
// mouse events
|
||||
graphViewer.addGraphMouseListener(new GraphMouseListener<CoreNode>() {
|
||||
@Override
|
||||
|
@ -207,6 +217,9 @@ public class NetworkGraph {
|
|||
link.setInterfaceTwo(interfaceTwo);
|
||||
}
|
||||
|
||||
boolean isVisible = !isWirelessLink(nodeOne, nodeTwo);
|
||||
link.setVisible(isVisible);
|
||||
|
||||
logger.info("adding user created edge: {}", link);
|
||||
}
|
||||
}
|
||||
|
@ -270,6 +283,25 @@ public class NetworkGraph {
|
|||
graphViewer.repaint();
|
||||
}
|
||||
|
||||
private boolean isWirelessNode(CoreNode node) {
|
||||
return node.getType() == NodeType.EMANE || node.getType() == NodeType.WLAN;
|
||||
}
|
||||
|
||||
private boolean isWirelessLink(CoreNode nodeOne, CoreNode nodeTwo) {
|
||||
boolean result = isWirelessNode(nodeOne);
|
||||
return result || isWirelessNode(nodeTwo);
|
||||
}
|
||||
|
||||
private boolean hasWirelessLink(CoreNode node) {
|
||||
for (CoreNode neighbor : graph.getNeighbors(node)) {
|
||||
if (isWirelessNode(neighbor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addLink(CoreLink link) {
|
||||
link.setId(linkId++);
|
||||
|
||||
|
@ -285,6 +317,9 @@ public class NetworkGraph {
|
|||
nodeTwo.addInterface(interfaceTwo);
|
||||
}
|
||||
|
||||
boolean isVisible = !isWirelessLink(nodeOne, nodeTwo);
|
||||
link.setVisible(isVisible);
|
||||
|
||||
graph.addEdge(link, nodeOne, nodeTwo);
|
||||
}
|
||||
|
||||
|
|
24
corefx/src/main/java/com/core/graph/RadioIcon.java
Normal file
24
corefx/src/main/java/com/core/graph/RadioIcon.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.utils.IconUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class RadioIcon implements Icon {
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return IconUtils.ICON_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return IconUtils.ICON_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
g.setColor(Color.black);
|
||||
g.fillOval(x, y, 10, 10);
|
||||
}
|
||||
}
|
|
@ -14,13 +14,13 @@ import java.util.Map;
|
|||
public final class IconUtils {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
public static final int ICON_SIZE = 75;
|
||||
private static final Map<String, Icon> ICON_MAP = new HashMap<>();
|
||||
private static final Map<String, LayeredIcon> ICON_MAP = new HashMap<>();
|
||||
|
||||
private IconUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static Icon getIcon(String iconPath) {
|
||||
public static LayeredIcon getIcon(String iconPath) {
|
||||
return ICON_MAP.computeIfAbsent(iconPath, key -> {
|
||||
ImageIcon imageIcon = new ImageIcon(IconUtils.class.getResource(iconPath));
|
||||
Image image = imageIcon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT);
|
||||
|
|
Loading…
Add table
Reference in a new issue