basic visualizer with support for painting mote relations
This commit is contained in:
parent
a6fc125b64
commit
16bec06558
1 changed files with 38 additions and 3 deletions
|
@ -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: Visualizer2D.java,v 1.15 2009/02/17 14:09:51 fros4943 Exp $
|
* $Id: Visualizer2D.java,v 1.16 2009/02/26 13:29:30 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
|
@ -53,6 +53,7 @@ import javax.swing.Timer;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
|
import se.sics.cooja.GUI.MoteRelation;
|
||||||
import se.sics.cooja.interfaces.*;
|
import se.sics.cooja.interfaces.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +100,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
||||||
private Observer posObserver = null; // Watches position changes
|
private Observer posObserver = null; // Watches position changes
|
||||||
|
|
||||||
private Observer moteHighligtObserver = null;
|
private Observer moteHighligtObserver = null;
|
||||||
|
private Observer moteRelationsObserver = null;
|
||||||
private Mote highlightedMote = null;
|
private Mote highlightedMote = null;
|
||||||
private Color highlightColor = Color.GRAY;
|
private Color highlightColor = Color.GRAY;
|
||||||
private Timer highlightTimer = null;
|
private Timer highlightTimer = null;
|
||||||
|
@ -319,6 +321,13 @@ public abstract class Visualizer2D extends VisPlugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Paint mote relations */
|
||||||
|
myGUI.addMoteRelationsObserver(moteRelationsObserver = new Observer() {
|
||||||
|
public void update(Observable obs, Object obj) {
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
canvas.addMouseMotionListener(new MouseMotionListener() {
|
canvas.addMouseMotionListener(new MouseMotionListener() {
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, false);
|
myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, false);
|
||||||
|
@ -659,8 +668,8 @@ public abstract class Visualizer2D extends VisPlugin {
|
||||||
abstract public Color[] getColorOf(Mote mote);
|
abstract public Color[] getColorOf(Mote mote);
|
||||||
|
|
||||||
protected void visualizeSimulation(Graphics g) {
|
protected void visualizeSimulation(Graphics g) {
|
||||||
for (int i = 0; i < simulation.getMotesCount(); i++) {
|
Mote[] allMotes = simulation.getMotes();
|
||||||
Mote mote = simulation.getMote(i);
|
for (Mote mote: allMotes) {
|
||||||
Color moteColors[] = getColorOf(mote);
|
Color moteColors[] = getColorOf(mote);
|
||||||
Position motePos = mote.getInterfaces().getPosition();
|
Position motePos = mote.getInterfaces().getPosition();
|
||||||
|
|
||||||
|
@ -693,6 +702,29 @@ public abstract class Visualizer2D extends VisPlugin {
|
||||||
g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
|
g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
|
||||||
2 * MOTE_RADIUS);
|
2 * MOTE_RADIUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Paint mote relations */
|
||||||
|
MoteRelation[] relations = simulation.getGUI().getMoteRelations();
|
||||||
|
for (MoteRelation r: relations) {
|
||||||
|
Position sourcePos = r.source.getInterfaces().getPosition();
|
||||||
|
Position destPos = r.dest.getInterfaces().getPosition();
|
||||||
|
|
||||||
|
Point sourcePoint = transformPositionToPixel(sourcePos);
|
||||||
|
Point destPoint = transformPositionToPixel(destPos);
|
||||||
|
|
||||||
|
Point middlePoint = new Point(
|
||||||
|
(destPoint.x*9 + sourcePoint.x*1)/10,
|
||||||
|
(destPoint.y*9 + sourcePoint.y*1)/10
|
||||||
|
);
|
||||||
|
|
||||||
|
/* "Arrow body" is painted gray */
|
||||||
|
g.setColor(Color.LIGHT_GRAY);
|
||||||
|
g.drawLine(sourcePoint.x, sourcePoint.y, middlePoint.x, middlePoint.y);
|
||||||
|
|
||||||
|
/* "Arrow head" is painted black */
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawLine(middlePoint.x, middlePoint.y, destPoint.x, destPoint.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -819,6 +851,9 @@ public abstract class Visualizer2D extends VisPlugin {
|
||||||
if (moteHighligtObserver != null) {
|
if (moteHighligtObserver != null) {
|
||||||
myGUI.deleteMoteHighlightObserver(moteHighligtObserver);
|
myGUI.deleteMoteHighlightObserver(moteHighligtObserver);
|
||||||
}
|
}
|
||||||
|
if (moteRelationsObserver != null) {
|
||||||
|
myGUI.deleteMoteRelationsObserver(moteRelationsObserver);
|
||||||
|
}
|
||||||
|
|
||||||
if (simObserver != null) {
|
if (simObserver != null) {
|
||||||
simulation.deleteObserver(simObserver);
|
simulation.deleteObserver(simObserver);
|
||||||
|
|
Loading…
Reference in a new issue