Skip to content
Snippets Groups Projects
Commit 8853adf6 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Updated NodeInfo Visualization

parent 9fab7de8
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,8 @@
package de.tud.kom.p2psim.impl.topology.views.visualization.world;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
......@@ -165,15 +167,56 @@ public class NodeInfoComponentVis extends JComponent
private final Color activeGreen = new Color(0, 200, 0);
private final Color[] colors = { Color.ORANGE, Color.BLUE, Color.RED,
Color.MAGENTA, Color.GRAY, Color.GREEN, Color.CYAN,
Color.PINK };
private final Color[] baseColors = { Color.ORANGE, Color.BLUE, Color.RED,
Color.PINK, Color.GRAY, Color.GREEN, Color.CYAN,
Color.WHITE };
private final Color[] tuColors = {
new Color(93, 133, 195), // 1a
new Color(80, 182, 149), // 3a
// new Color(221,223,72), // 5a
new Color(248,186,60), // 7a
new Color(233,80,62), // 9a
new Color(128, 69, 151), // 11a
new Color(0, 78, 138), // 1c
new Color(0, 136, 119), // 3c
// new Color(177, 189, 0), // 5c
new Color(210, 135, 0), // 7c
new Color(185, 15, 34), // 9c
new Color(97, 28, 115), // 11c
};
private Color[][] colors = null;
public NodeVis(Host host, NodeInformation nodeInfo) {
this.nodeInfo = nodeInfo;
this.host = (SimHost) host;
this.loc = this.host.getTopologyComponent().getRealPosition();
this.visNodeInfo = VisualizationInjector.getNodeInformation(host.getId());
/*
* Create per-info-option colors by deriving the color from the base color
*/
colors = new Color[nodeInfo.getNodeColorDimensions()][];
for (int dim = 0; dim < colors.length; dim++) {
Color baseColor = baseColors[dim];
int dimensionSize = nodeInfo
.getNodeColorDescriptions(dim).length;
colors[dim] = new Color[dimensionSize];
/*
* http://stackoverflow.com/questions/2355157/dynamically-
* creating-colors-with-different-brightness
*/
// float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(),
// baseColor.getGreen(), baseColor.getBlue(), null);
for (int i = 0; i < dimensionSize; i++) {
float hue = i / (float) dimensionSize;
// colors[dim][i] = Color.getHSBColor(hue, hsbVals[1],
// hsbVals[2]);
colors[dim][i] = tuColors[i];
}
}
}
/**
......@@ -184,24 +227,28 @@ public class NodeInfoComponentVis extends JComponent
*/
public void drawLegend(Graphics2D g2) {
String[] dimensions = nodeInfo.getNodeColorDimensionDescriptions();
int radius = 4;
for (int dim = 0; dim < dimensions.length; dim++) {
radius += 2;
if (!activeLayers[dim]) {
int segments = dimensions.length;
int segmentDegrees = (int) (360 / (double) segments);
int arcSize = 8;
g2.setStroke(new BasicStroke(3));
for (int color = 0; color < segments; color++) {
if (!activeLayers[color]) {
continue;
}
g2.setColor(Color.DARK_GRAY);
g2.drawOval(10, 20 * (dim + 1) - 10, radius * 2, radius * 2);
g2.drawString(dimensions[dim], 30, 20 * (dim + 1));
String[] colorDescs = nodeInfo.getNodeColorDescriptions(dim);
g2.drawArc(10, 20 * (color + 1)+10, 2*arcSize, 2*arcSize, color*segmentDegrees, segmentDegrees);
String[] colorDescs = nodeInfo.getNodeColorDescriptions(color);
for (int i = 0; i < colorDescs.length; i++) {
g2.setColor(colors[i]);
g2.fillRect(30 + (i + 1) * 90, 20 * (dim + 1) - 10, 8, 8);
g2.setColor(colors[color][i]);
g2.fillRect(40 + i * 90, 20 * (color + 1)+10, 8, 8);
g2.setColor(Color.DARK_GRAY);
g2.drawString(colorDescs[i], 40 + (i + 1) * 90,
20 * (dim + 1));
g2.drawString(colorDescs[i], 50 + i * 90,
20 * (color + 2));
}
}
g2.setStroke(new BasicStroke(1));
}
public void draw(Graphics2D g2) {
......@@ -222,24 +269,26 @@ public class NodeInfoComponentVis extends JComponent
if (!nodeInfo.isActive()) {
return;
}
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1.0f));
/*
* TODO add offline/online info here as well (removes the need for a
* custom object that visualizes the underlay!)
*/
int numColors = nodeInfo.getNodeColorDimensions();
radius = 4;
for (int color = 0; color < numColors; color++) {
int value = nodeInfo.getNodeColor(color);
radius += 2;
if (value < 0 || !activeLayers[color]) {
int segments = nodeInfo.getNodeColorDimensions();
int segmentDegrees = (int) (360 / (double) segments);
int arcSize = 8;
g2.setStroke(new BasicStroke(8, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
for (int dim = 0; dim < segments; dim++) {
int value = nodeInfo.getNodeColor(dim);
if (value < 0 || !activeLayers[dim]) {
continue;
}
g2.setColor(colors[value]);
g2.drawOval(center.x - radius, center.y - radius, radius * 2,
radius * 2);
g2.setColor(colors[dim][value]);
g2.drawArc(center.x-arcSize, center.y-arcSize, 2*arcSize, 2*arcSize, dim*segmentDegrees, segmentDegrees);
}
g2.setStroke(new BasicStroke(1));
String nodeDesc = nodeInfo.getNodeDescription();
g2.drawString(nodeDesc, center.x + 4, center.y + 4);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment