From e73c48a82668f84d7e214f73056e4d9fd50f4522 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 26 Feb 2009 13:35:45 +0000 Subject: [PATCH] added mote relation support. used to show relations between simulated motes, typically for debugging and visualization purposes --- tools/cooja/java/se/sics/cooja/GUI.java | 94 +++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index 79713c06e..025dd9a5a 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: GUI.java,v 1.108 2009/02/25 16:11:59 fros4943 Exp $ + * $Id: GUI.java,v 1.109 2009/02/26 13:35:45 fros4943 Exp $ */ package se.sics.cooja; @@ -302,15 +302,35 @@ public class GUI extends Observable { private Vector> positionerClasses = new Vector>(); - // Mote highlight observable private class HighlightObservable extends Observable { - private void highlightMote(Mote mote) { + private void setChangedAndNotify(Mote mote) { setChanged(); notifyObservers(mote); } } private HighlightObservable moteHighlightObservable = new HighlightObservable(); + private class MoteRelationsObservable extends Observable { + private void setChangedAndNotify() { + setChanged(); + notifyObservers(); + } + } + private MoteRelationsObservable moteRelationObservable = new MoteRelationsObservable(); + + /** + * Mote relation (directed). + */ + public static class MoteRelation { + public Mote source; + public Mote dest; + public MoteRelation(Mote source, Mote dest) { + this.source = source; + this.dest = dest; + } + } + private ArrayList moteRelations = new ArrayList(); + /** * Creates a new COOJA Simulator GUI. * @@ -4088,7 +4108,72 @@ public class GUI extends Observable { * Mote to highlight */ public void signalMoteHighlight(Mote m) { - moteHighlightObservable.highlightMote(m); + moteHighlightObservable.setChangedAndNotify(m); + } + + /** + * Adds directed relation between given motes. + * + * @param source Source mote + * @param dest Destination mote + */ + public void addMoteRelation(Mote source, Mote dest) { + if (source == null || dest == null) { + return; + } + removeMoteRelation(source, dest); /* Unique relations */ + moteRelations.add(new MoteRelation(source, dest)); + moteRelationObservable.setChangedAndNotify(); + } + + /** + * Removes the relations between given motes. + * + * @param source Source mote + * @param dest Destination mote + */ + public void removeMoteRelation(Mote source, Mote dest) { + if (source == null || dest == null) { + return; + } + MoteRelation[] arr = getMoteRelations(); + for (MoteRelation r: arr) { + if (r.source == source && r.dest == dest) { + moteRelations.remove(r); + } + } + moteRelationObservable.setChangedAndNotify(); + } + + /** + * @return All current mote relations. + * + * @see #addMoteRelationsObserver(Observer) + */ + public MoteRelation[] getMoteRelations() { + MoteRelation[] arr = new MoteRelation[moteRelations.size()]; + moteRelations.toArray(arr); + return arr; + } + + /** + * Adds mote relation observer. + * Typically used by visualizer plugins. + * + * @param newObserver Observer + */ + public void addMoteRelationsObserver(Observer newObserver) { + moteRelationObservable.addObserver(newObserver); + } + + /** + * Removes mote relation observer. + * Typically used by visualizer plugins. + * + * @param observer Observer + */ + public void deleteMoteRelationsObserver(Observer observer) { + moteRelationObservable.deleteObserver(observer); } public static File stripTrailingUpDirs(File file) { @@ -4115,6 +4200,7 @@ public class GUI extends Observable { return file; } + public static File resolveShortAbsolutePath(File file) { file = file.getAbsoluteFile();