[cooja] skins/TrafficVisualizerSkin: Use alpha value to fade out arrow color an potentially allow to configure colors

This commit is contained in:
Enrico Joerns 2014-06-11 11:21:39 +02:00
parent 449046669f
commit cd9164d5e2

View file

@ -65,6 +65,8 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
private static final Logger logger = Logger.getLogger(TrafficVisualizerSkin.class); private static final Logger logger = Logger.getLogger(TrafficVisualizerSkin.class);
private final int MAX_HISTORY_SIZE = 200; private final int MAX_HISTORY_SIZE = 200;
private final float TRANSMITTED_COLOR_RGB[] = Color.BLUE.getRGBColorComponents(null);
private final float UNTRANSMITTED_COLOR_RGB[] = Color.RED.getRGBColorComponents(null);
private boolean active = false; private boolean active = false;
private Simulation simulation = null; private Simulation simulation = null;
@ -181,17 +183,17 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
@Override @Override
public void paintBeforeMotes(Graphics g) { public void paintBeforeMotes(Graphics g) {
for (RadioConnectionArrow connArrow : historyList) { for (RadioConnectionArrow connArrow : historyList) {
float colorHistoryIndex = connArrow.getAge(); float colorHistoryIndex = 1.0f - connArrow.getAge();
g.setColor(new Color(colorHistoryIndex, colorHistoryIndex, 1.0f));
Radio source = connArrow.getConnection().getSource(); Radio source = connArrow.getConnection().getSource();
Point sourcePoint = visualizer.transformPositionToPixel(source.getPosition()); Point sourcePoint = visualizer.transformPositionToPixel(source.getPosition());
/* If there is no destination, paint red circles to indicate untransmitted message */ /* If there is no destination, paint red circles to indicate untransmitted message */
if (connArrow.getConnection().getDestinations().length == 0) { if (connArrow.getConnection().getDestinations().length == 0) {
g.setColor(new Color(1.0f, colorHistoryIndex, colorHistoryIndex)); g.setColor(new Color(UNTRANSMITTED_COLOR_RGB[0], UNTRANSMITTED_COLOR_RGB[1], UNTRANSMITTED_COLOR_RGB[2], colorHistoryIndex));
g.drawOval(sourcePoint.x - 20, sourcePoint.y - 20, 40, 40); g.drawOval(sourcePoint.x - 20, sourcePoint.y - 20, 40, 40);
g.drawOval(sourcePoint.x - 30, sourcePoint.y - 30, 60, 60); g.drawOval(sourcePoint.x - 30, sourcePoint.y - 30, 60, 60);
continue; continue;
} }
g.setColor(new Color(TRANSMITTED_COLOR_RGB[0], TRANSMITTED_COLOR_RGB[1], TRANSMITTED_COLOR_RGB[2], colorHistoryIndex));
for (Radio destRadio : connArrow.getConnection().getDestinations()) { for (Radio destRadio : connArrow.getConnection().getDestinations()) {
Position destPos = destRadio.getPosition(); Position destPos = destRadio.getPosition();
Point destPoint = visualizer.transformPositionToPixel(destPos); Point destPoint = visualizer.transformPositionToPixel(destPos);