Added option to move motes in Visualizer without confirm dialog by dragging motes with ALT button pressed

This commit is contained in:
nifi 2010-03-24 14:22:56 +00:00
parent 78069e8853
commit 81dbcf1654
2 changed files with 42 additions and 36 deletions

View file

@ -1,7 +1,7 @@
se.sics.cooja.plugins.Visualizer = \ se.sics.cooja.plugins.Visualizer = \
<b>Visualizer</b> \ <b>Visualizer</b> \
<p>The visualizer shows the positions of simulated motes as viewed from above (XY-plane). \ <p>The visualizer shows the positions of simulated motes as viewed from above (XY-plane). \
It is possible to zoom (CRTL+Mouse drag) and pan (Shift+Mouse drag) the current view. \ It is possible to zoom (CRTL+Mouse drag) and pan (Shift+Mouse drag) the current view. Motes can be moved by dragging them (ALT+Mouse drag). \
Mouse right-click a mote or unoccupied space for a popup menu with more options. \ Mouse right-click a mote or unoccupied space for a popup menu with more options. \
<p>The visualizer supports "visualizer skins". \ <p>The visualizer supports "visualizer skins". \
Each skin provides some specific information, such as ongoing simulated radio traffic, or the IP addresses of motes. \ Each skin provides some specific information, such as ongoing simulated radio traffic, or the IP addresses of motes. \

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.14 2010/02/26 07:38:08 nifi Exp $ * $Id: Visualizer.java,v 1.15 2010/03/24 14:22:56 nifi Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -144,6 +144,7 @@ public class Visualizer extends VisPlugin {
private boolean moving = false; private boolean moving = false;
private Mote movedMote = null; private Mote movedMote = null;
private long moveStartTime = -1; private long moveStartTime = -1;
private boolean moveConfirm;
private Cursor moveCursor = new Cursor(Cursor.MOVE_CURSOR); private Cursor moveCursor = new Cursor(Cursor.MOVE_CURSOR);
/* Visualizer skins */ /* Visualizer skins */
@ -656,39 +657,41 @@ public class Visualizer extends VisPlugin {
} }
private void handleMousePress(MouseEvent mouseEvent) { private void handleMousePress(MouseEvent mouseEvent) {
int x = mouseEvent.getPoint().x; int x = mouseEvent.getX();
int y = mouseEvent.getPoint().y; int y = mouseEvent.getY();
final Mote[] motes = findMotesAtPosition(x, y);
/* No motes clicked: We should either pan or zoom. if (mouseEvent.isControlDown()) {
* Control or Shift pressed: We should either pan or zoom */ /* Zoom */
if (mouseEvent.isControlDown() || mouseEvent.isShiftDown() zooming = true;
|| motes == null || motes.length == 0) { zoomingPixel = new Point(x, y);
if (mouseEvent.isControlDown()) { zoomingPosition = transformPixelToPosition(zoomingPixel);
/* Zoom */ zoomStart = viewportTransform.getScaleX();
zooming = true;
zoomingPixel = new Point(x, y);
zoomingPosition = transformPixelToPosition(zoomingPixel);
zoomStart = viewportTransform.getScaleX();
} else {
/* Pan */
panning = true;
panningPosition = transformPixelToPosition(x, y);
}
return; return;
} }
/* One of the clicked motes should be moved */ final Mote[] motes = findMotesAtPosition(x, y);
beginMoveRequest(motes[0], true); if (mouseEvent.isShiftDown() ||
(!mouseEvent.isAltDown() && (motes == null || motes.length == 0))) {
/* No motes clicked or shift pressed: We should pan */
panning = true;
panningPosition = transformPixelToPosition(x, y);
return;
}
if (motes != null && motes.length > 0) {
/* One of the clicked motes should be moved */
beginMoveRequest(motes[0], !mouseEvent.isAltDown(), !mouseEvent.isAltDown());
}
} }
private void beginMoveRequest(Mote moteToMove, boolean withTiming) { private void beginMoveRequest(Mote moteToMove, boolean withTiming, boolean confirm) {
if (withTiming) { if (withTiming) {
moveStartTime = System.currentTimeMillis(); moveStartTime = System.currentTimeMillis();
} else { } else {
moveStartTime = -1; moveStartTime = -1;
} }
moving = true; moving = true;
moveConfirm = confirm;
movedMote = moteToMove; movedMote = moteToMove;
repaint(); repaint();
} }
@ -752,29 +755,32 @@ public class Visualizer extends VisPlugin {
canvas.setCursor(Cursor.getDefaultCursor()); canvas.setCursor(Cursor.getDefaultCursor());
/* Move mote */ /* Move mote */
Position newPos = transformPixelToPosition(x, y);
if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) { if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) {
String options[] = {"Yes", "Cancel"}; Position newPos = transformPixelToPosition(x, y);
int returnValue = JOptionPane.showOptionDialog(Visualizer.this, if (moveConfirm) {
"Move mote to" + String options[] = {"Yes", "Cancel"};
"\nX=" + newPos.getXCoordinate() + int returnValue = JOptionPane.showOptionDialog(Visualizer.this,
"\nY=" + newPos.getYCoordinate() + "Move mote to" +
"\nZ=" + movedMote.getInterfaces().getPosition().getZCoordinate(), "\nX=" + newPos.getXCoordinate() +
"Move mote?", "\nY=" + newPos.getYCoordinate() +
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, "\nZ=" + movedMote.getInterfaces().getPosition().getZCoordinate(),
null, options, options[0]); "Move mote?",
if (returnValue == JOptionPane.YES_OPTION) { JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
moving = returnValue == JOptionPane.YES_OPTION;
}
if (moving) {
movedMote.getInterfaces().getPosition().setCoordinates( movedMote.getInterfaces().getPosition().setCoordinates(
newPos.getXCoordinate(), newPos.getXCoordinate(),
newPos.getYCoordinate(), newPos.getYCoordinate(),
movedMote.getInterfaces().getPosition().getZCoordinate() movedMote.getInterfaces().getPosition().getZCoordinate()
); );
repaint();
} }
} }
moving = false; moving = false;
movedMote = null; movedMote = null;
repaint();
} }
} }
@ -1248,7 +1254,7 @@ public class Visualizer extends VisPlugin {
return "Move " + mote; return "Move " + mote;
} }
public void doAction(Visualizer visualizer, Mote mote) { public void doAction(Visualizer visualizer, Mote mote) {
visualizer.beginMoveRequest(mote, false); visualizer.beginMoveRequest(mote, false, true);
} }
}; };