From af1932de613ae24b88731c1944b4309d949d13e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dawans?= Date: Mon, 29 Oct 2012 13:26:44 +0100 Subject: [PATCH] Fixes COOJA Network Visualiser glitch when clicking on a mote --- .../se/sics/cooja/plugins/Visualizer.java | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java index fa6d272ac..410b6e66c 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java @@ -155,6 +155,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { private Position zoomingPosition = null; /* Zooming center position */ private Point zoomingPixel = null; /* Zooming center pixel */ private boolean moving = false; + private Point mouseDownPixel = null; /* Records position of mouse down to differentiate a click from a move */ private Mote movedMote = null; public Mote clickedMote = null; private long moveStartTime = -1; @@ -813,6 +814,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { if (motes != null && motes.length > 0) { /* One of the clicked motes should be moved */ + mouseDownPixel = new Point(x, y); clickedMote = motes[0]; beginMoveRequest(motes[0], false, false); } @@ -902,43 +904,45 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { /* Moving */ if (moving) { - Position newPos = transformPixelToPosition(x, y); + if(x != mouseDownPixel.x || y != mouseDownPixel.y) { + Position newPos = transformPixelToPosition(x, y); - if (!stop) { - canvas.setCursor(moveCursor); - movedMote.getInterfaces().getPosition().setCoordinates( - newPos.getXCoordinate(), - newPos.getYCoordinate(), - movedMote.getInterfaces().getPosition().getZCoordinate() - ); - repaint(); - return; - } - /* Restore cursor */ - canvas.setCursor(Cursor.getDefaultCursor()); - - - /* Move mote */ - if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) { - if (moveConfirm) { - String options[] = {"Yes", "Cancel"}; - int returnValue = JOptionPane.showOptionDialog(Visualizer.this, - "Move mote to" + - "\nX=" + newPos.getXCoordinate() + - "\nY=" + newPos.getYCoordinate() + - "\nZ=" + movedMote.getInterfaces().getPosition().getZCoordinate(), - "Move mote?", - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, - null, options, options[0]); - moving = returnValue == JOptionPane.YES_OPTION; - } - if (moving) { + if (!stop) { + canvas.setCursor(moveCursor); movedMote.getInterfaces().getPosition().setCoordinates( newPos.getXCoordinate(), newPos.getYCoordinate(), movedMote.getInterfaces().getPosition().getZCoordinate() ); repaint(); + return; + } + /* Restore cursor */ + canvas.setCursor(Cursor.getDefaultCursor()); + + + /* Move mote */ + if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) { + if (moveConfirm) { + String options[] = {"Yes", "Cancel"}; + int returnValue = JOptionPane.showOptionDialog(Visualizer.this, + "Move mote to" + + "\nX=" + newPos.getXCoordinate() + + "\nY=" + newPos.getYCoordinate() + + "\nZ=" + movedMote.getInterfaces().getPosition().getZCoordinate(), + "Move mote?", + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, + null, options, options[0]); + moving = returnValue == JOptionPane.YES_OPTION; + } + if (moving) { + movedMote.getInterfaces().getPosition().setCoordinates( + newPos.getXCoordinate(), + newPos.getYCoordinate(), + movedMote.getInterfaces().getPosition().getZCoordinate() + ); + repaint(); + } } }