Changed to draw the mote relations under the motes

This commit is contained in:
nifi 2010-02-26 07:38:08 +00:00
parent 74df2dbf43
commit 512da4195c

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: Visualizer.java,v 1.13 2010/02/03 15:49:24 fros4943 Exp $ * $Id: Visualizer.java,v 1.14 2010/02/26 07:38:08 nifi Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -65,7 +65,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Vector;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
@ -168,8 +167,9 @@ public class Visualizer extends VisPlugin {
private MoteCountListener newMotesListener; private MoteCountListener newMotesListener;
private Observer posObserver = null; private Observer posObserver = null;
private Observer moteHighligtObserver = null; private Observer moteHighligtObserver = null;
private Vector<Mote> highlightedMotes = new Vector<Mote>(); private ArrayList<Mote> highlightedMotes = new ArrayList<Mote>();
private final static Color HIGHLIGHT_COLOR = Color.CYAN; private final static Color HIGHLIGHT_COLOR = Color.CYAN;
private final static Color MOVE_COLOR = Color.WHITE;
private Observer moteRelationsObserver = null; private Observer moteRelationsObserver = null;
/* Popup menu */ /* Popup menu */
@ -773,6 +773,7 @@ public class Visualizer extends VisPlugin {
} }
moving = false; moving = false;
movedMote = null;
repaint(); repaint();
} }
} }
@ -822,52 +823,6 @@ public class Visualizer extends VisPlugin {
public void paintMotes(Graphics g) { public void paintMotes(Graphics g) {
Mote[] allMotes = simulation.getMotes(); Mote[] allMotes = simulation.getMotes();
for (Mote mote: allMotes) {
/* Use the first skin's non-null mote colors */
Color moteColors[] = null;
for (VisualizerSkin skin: currentSkins) {
moteColors = skin.getColorOf(mote);
if (moteColors != null) {
break;
}
}
if (moteColors == null) {
moteColors = DEFAULT_MOTE_COLORS;
}
Position motePos = mote.getInterfaces().getPosition();
Point pixelCoord = transformPositionToPixel(motePos);
int x = pixelCoord.x;
int y = pixelCoord.y;
if (!highlightedMotes.isEmpty() && highlightedMotes.contains(mote)) {
g.setColor(HIGHLIGHT_COLOR);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
} else if (mote == movedMote) {
/* No fill */
} else if (moteColors.length >= 2) {
g.setColor(moteColors[0]);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
g.setColor(moteColors[1]);
g.fillOval(x - MOTE_RADIUS / 2, y - MOTE_RADIUS / 2, MOTE_RADIUS,
MOTE_RADIUS);
} else if (moteColors.length >= 1) {
g.setColor(moteColors[0]);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
}
g.setColor(Color.BLACK);
g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
}
/* Paint mote relations */ /* Paint mote relations */
MoteRelation[] relations = simulation.getGUI().getMoteRelations(); MoteRelation[] relations = simulation.getGUI().getMoteRelations();
for (MoteRelation r: relations) { for (MoteRelation r: relations) {
@ -890,6 +845,54 @@ public class Visualizer extends VisPlugin {
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.drawLine(middlePoint.x, middlePoint.y, destPoint.x, destPoint.y); g.drawLine(middlePoint.x, middlePoint.y, destPoint.x, destPoint.y);
} }
for (Mote mote: allMotes) {
/* Use the first skin's non-null mote colors */
Color moteColors[] = null;
for (VisualizerSkin skin: currentSkins) {
moteColors = skin.getColorOf(mote);
if (moteColors != null) {
break;
}
}
if (moteColors == null) {
moteColors = DEFAULT_MOTE_COLORS;
}
Position motePos = mote.getInterfaces().getPosition();
Point pixelCoord = transformPositionToPixel(motePos);
int x = pixelCoord.x;
int y = pixelCoord.y;
if (mote == movedMote) {
g.setColor(MOVE_COLOR);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
} else if (!highlightedMotes.isEmpty() && highlightedMotes.contains(mote)) {
g.setColor(HIGHLIGHT_COLOR);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
} else if (moteColors.length >= 2) {
g.setColor(moteColors[0]);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
g.setColor(moteColors[1]);
g.fillOval(x - MOTE_RADIUS / 2, y - MOTE_RADIUS / 2, MOTE_RADIUS,
MOTE_RADIUS);
} else if (moteColors.length >= 1) {
g.setColor(moteColors[0]);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
}
g.setColor(Color.BLACK);
g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS);
}
} }
/** /**
@ -1057,7 +1060,7 @@ public class Visualizer extends VisPlugin {
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>(); ArrayList<Element> config = new ArrayList<Element>();
Element element; Element element;
/* Skins */ /* Skins */