From 963d2686f30e8ae9b48ae7a58667b1d5002aa990 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 11 Jul 2014 00:26:00 +0200 Subject: [PATCH 1/9] [cooja] plugins/Visualizer: Fix: Always highlight selected motes. Motes were highlighted only by the UDGMVisualizerSkin before. Now highlighting moved from individual VisualizerSkin to Visualizer. A selected mote is highlighted with a blue circle and a semi-transparent gray overlay. --- .../contikios/cooja/plugins/Visualizer.java | 19 ++++++++++++++++--- .../plugins/skins/UDGMVisualizerSkin.java | 3 --- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 733bafa6f..5d139eb7e 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -1209,9 +1209,22 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { 2 * MOTE_RADIUS); } - g.setColor(Color.BLACK); - g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, - 2 * MOTE_RADIUS); + if (getSelectedMotes().contains(mote)) { + /* If mote is selected, highlight with red circle + and semitransparent gray overlay */ + g.setColor(new Color(51, 102, 255)); + g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, + 2 * MOTE_RADIUS); + g.drawOval(x - MOTE_RADIUS - 1, y - MOTE_RADIUS - 1, 2 * MOTE_RADIUS + 2, + 2 * MOTE_RADIUS + 2); + g.setColor(new Color(128, 128, 128, 128)); + g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, + 2 * MOTE_RADIUS); + } else { + g.setColor(Color.BLACK); + g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, + 2 * MOTE_RADIUS); + } } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/skins/UDGMVisualizerSkin.java b/tools/cooja/java/org/contikios/cooja/plugins/skins/UDGMVisualizerSkin.java index 45f7a826a..144760405 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/skins/UDGMVisualizerSkin.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/skins/UDGMVisualizerSkin.java @@ -263,9 +263,6 @@ public class UDGMVisualizerSkin implements VisualizerSkin { @Override public Color[] getColorOf(Mote mote) { - if (visualizer.getSelectedMotes().contains(mote)) { - return new Color[]{Color.CYAN}; - } return null; } From 65946843420a11c531820863c4f3383476e4f0f5 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 5 Jun 2014 22:33:45 +0200 Subject: [PATCH 2/9] [cooja] plugins/Visualizer: Enable multi-mote deletion in mote menu --- .../org/contikios/cooja/plugins/Visualizer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 5d139eb7e..903183203 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -1584,12 +1584,22 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { @Override public String getDescription(Visualizer visualizer, Mote mote) { - return "Delete " + mote; + if (visualizer.getSelectedMotes().size() == 1) { + return "Delete " + mote; + } else { + return "Delete selected Motes"; + } } @Override public void doAction(Visualizer visualizer, Mote mote) { - mote.getSimulation().removeMote(mote); + if (visualizer.getSelectedMotes().size() == 1) { + mote.getSimulation().removeMote(mote); + } else { + for (Mote m: visualizer.getSelectedMotes()) { + mote.getSimulation().removeMote(m); + } + } } }; From 3ada5671ef60bdda540a7f3febe2b176247752e1 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 6 Jun 2014 11:31:36 +0200 Subject: [PATCH 3/9] [cooja] plugins/Visualizer: Fixed node selection in Delete menu handling Previously if multiple motes were selected and the context menu of a non-selected mote was used to delete, not the clicked mote but the other selected ones were removed. This behavior is fixed so that if another mote is clicked only this is deleted. --- .../contikios/cooja/plugins/Visualizer.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 903183203..1fc0ab410 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -1584,21 +1584,25 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { @Override public String getDescription(Visualizer visualizer, Mote mote) { - if (visualizer.getSelectedMotes().size() == 1) { - return "Delete " + mote; - } else { + if (visualizer.getSelectedMotes().contains(mote) && visualizer.getSelectedMotes().size() > 1) { return "Delete selected Motes"; + } else { + return "Delete " + mote; } } @Override public void doAction(Visualizer visualizer, Mote mote) { - if (visualizer.getSelectedMotes().size() == 1) { - mote.getSimulation().removeMote(mote); - } else { - for (Mote m: visualizer.getSelectedMotes()) { - mote.getSimulation().removeMote(m); - } + + /* If the currently clicked mote is note in the current mote selection, + * select it exclusively */ + if (!visualizer.getSelectedMotes().contains(mote)) { + visualizer.getSelectedMotes().clear(); + visualizer.getSelectedMotes().add(mote); + } + + for (Mote m : visualizer.getSelectedMotes()) { + mote.getSimulation().removeMote(m); } } }; From 99e74e83486165dea1075ef13b6c61c2623640f3 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 6 Jun 2014 11:35:17 +0200 Subject: [PATCH 4/9] [cooja] plugins/Visualizer: Implemented multi-mode behavior of delete mote menu for move, too Note that this does not yet implement the correct behavior of beginMoveReques() --- .../java/org/contikios/cooja/plugins/Visualizer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 1fc0ab410..4b9073117 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -1702,11 +1702,21 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { @Override public String getDescription(Visualizer visualizer, Mote mote) { - return "Move " + mote; + if (visualizer.getSelectedMotes().contains(mote) && visualizer.getSelectedMotes().size() > 1) { + return "Move selected Motes"; + } else { + return "Move " + mote; + } } @Override public void doAction(Visualizer visualizer, Mote mote) { + /* If the currently clicked mote is note in the current mote selection, + * select it exclusively */ + if (!visualizer.getSelectedMotes().contains(mote)) { + visualizer.getSelectedMotes().clear(); + visualizer.getSelectedMotes().add(mote); + } visualizer.beginMoveRequest(mote, false, false); } }; From 2465a361e37faf27243cfb2d2bb49b1bdd7b6981 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 6 Jun 2014 11:41:44 +0200 Subject: [PATCH 5/9] [cooja] plugins/Visualizer: Group mote placement modifications together (move, delete) --- tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 4b9073117..1418b5b6f 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -477,10 +477,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { }); /* Register mote menu actions */ - registerMoteMenuAction(MoveMoteMenuAction.class); registerMoteMenuAction(ButtonClickMoteMenuAction.class); registerMoteMenuAction(ShowLEDMoteMenuAction.class); registerMoteMenuAction(ShowSerialMoteMenuAction.class); + + registerMoteMenuAction(MoveMoteMenuAction.class); registerMoteMenuAction(DeleteMoteMenuAction.class); /* Register simulation menu actions */ From 39f7ca586f5d2b936df403ce26a4260e12af947b Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 6 Jun 2014 11:46:50 +0200 Subject: [PATCH 6/9] [cooja] plugins/Visualizer: Mouse release always terminates previous action and reses actions state and cursor appearance Also renamed UNKNOWN state to NONE as it is a more adequate name for the new behavior --- .../org/contikios/cooja/plugins/Visualizer.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 1418b5b6f..bb9df74db 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -160,12 +160,16 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { private static final int MOVE_MASK = Event.SHIFT_MASK; enum MotesActionState { - - UNKNWON, + NONE, + // press to select mote SELECT_PRESS, + // press DEFAULT_PRESS, + // press to start panning PAN_PRESS, + // panning the viewport PANNING, + // moving a mote MOVING, // rectangular select SELECTING @@ -176,7 +180,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { /* Mote that was under curser while mouse press */ Mote cursorMote; - MotesActionState mouseActionState = MotesActionState.UNKNWON; + MotesActionState mouseActionState = MotesActionState.NONE; /* Position where mouse button was pressed */ Position pressedPos; @@ -1038,6 +1042,9 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { repaint(); break; } + /* Release always stops previous actions */ + mouseActionState = MotesActionState.NONE; + canvas.setCursor(Cursor.getDefaultCursor()); repaint(); } From 73fbb69e398121132c2b43ada2d33f4aaa0f6d84 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 6 Jun 2014 11:50:04 +0200 Subject: [PATCH 7/9] [cooja] plugins/Visualizer: Partly implement behavior of beginMoveRequest to fit new mote movement handling --- .../contikios/cooja/plugins/Visualizer.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index bb9df74db..950885bc6 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -437,6 +437,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { public void mouseDragged(MouseEvent e) { handleMouseDrag(e, false); } + + @Override + public void mouseMoved(MouseEvent e) { + handleMouseDrag(e, false); + } }); canvas.addMouseListener(new MouseAdapter() { @Override @@ -894,6 +899,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { pressedPos = transformPixelToPosition(mouseEvent.getPoint()); + // if we are in moving, we ignore the press (rest is handled by release) + if (mouseActionState == MotesActionState.MOVING) { + return; + } + // this is the state we have from pressing button final Mote[] foundMotes = findMotesAtPosition(x, y); if (foundMotes == null) { @@ -942,6 +952,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { mouseActionState = MotesActionState.PANNING; } else { + /* If we start moving with on a cursor mote, switch to MOVING */ mouseActionState = MotesActionState.MOVING; // save start position for (Mote m : selectedMotes) { @@ -1048,17 +1059,27 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { repaint(); } - private void beginMoveRequest(Mote motesToMove, boolean withTiming, boolean confirm) { + private void beginMoveRequest(Mote selectedMote, boolean withTiming, boolean confirm) { if (withTiming) { moveStartTime = System.currentTimeMillis(); } else { moveStartTime = -1; } - mouseActionState = MotesActionState.DEFAULT_PRESS; - selectedMotes.clear(); - selectedMotes.add(motesToMove); - repaint(); + /* Save start positions and set move-start position to clicked mote */ + for (Mote m : selectedMotes) { + Position pos = m.getInterfaces().getPosition(); + moveStartPositions.put(m, new double[]{ + pos.getXCoordinate(), + pos.getYCoordinate(), + pos.getZCoordinate()}); + } + pressedPos.setCoordinates( + selectedMote.getInterfaces().getPosition().getXCoordinate(), + selectedMote.getInterfaces().getPosition().getYCoordinate(), + selectedMote.getInterfaces().getPosition().getZCoordinate()); + + mouseActionState = MotesActionState.MOVING; } private double zoomFactor() { From 8b1bf449ee320724a87442a6049491f68f7ed9cc Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Tue, 10 Jun 2014 08:04:18 +0200 Subject: [PATCH 8/9] [cooja] plugins/Visualizer: Key control: Allow to abort actions with ESCAPE key and delete motes using DELETE key --- .../contikios/cooja/plugins/Visualizer.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 950885bc6..885668526 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -431,6 +431,37 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { } }); + canvas.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "abort_action"); + canvas.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "delete_motes"); + + canvas.getActionMap().put("abort_action", new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + if (mouseActionState == MotesActionState.MOVING) { + /* Reset positions to those of move start */ + for (Mote m : Visualizer.this.getSelectedMotes()) { + double rstPos[] = Visualizer.this.moveStartPositions.get(m); + m.getInterfaces().getPosition().setCoordinates(rstPos[0], rstPos[1], rstPos[2]); + } + mouseActionState = MotesActionState.NONE; + } + /* Always deselect all */ + Visualizer.this.getSelectedMotes().clear(); + repaint(); + } + }); + + canvas.getActionMap().put("delete_motes", new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + for (Mote m : Visualizer.this.getSelectedMotes()) { + m.getSimulation().removeMote(m); + } + } + }); + /* Popup menu */ canvas.addMouseMotionListener(new MouseMotionAdapter() { @Override From d8cf0d1349d2c253dc44df5e0f444280a7ff856c Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Tue, 10 Jun 2014 15:59:33 +0200 Subject: [PATCH 9/9] [cooja] plugins/Visualizer: Deselect motes when removing This also fixes visualization issues such as remaining transmission range underlays for removed motes --- .../org/contikios/cooja/plugins/Visualizer.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 885668526..5b6c513ba 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -67,6 +67,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -456,8 +457,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { @Override public void actionPerformed(ActionEvent e) { - for (Mote m : Visualizer.this.getSelectedMotes()) { + Iterator iter = Visualizer.this.getSelectedMotes().iterator(); + while (iter.hasNext()) { + Mote m = iter.next(); m.getSimulation().removeMote(m); + iter.remove(); } } }); @@ -1654,16 +1658,15 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { @Override public void doAction(Visualizer visualizer, Mote mote) { - /* If the currently clicked mote is note in the current mote selection, + /* If the currently clicked mote is not in the current mote selection, * select it exclusively */ if (!visualizer.getSelectedMotes().contains(mote)) { visualizer.getSelectedMotes().clear(); visualizer.getSelectedMotes().add(mote); } - for (Mote m : visualizer.getSelectedMotes()) { - mote.getSimulation().removeMote(m); - } + /* Invoke 'delete_motes' action */ + visualizer.canvas.getActionMap().get("delete_motes").actionPerformed(null); } };