Added option to move motes in Visualizer without confirm dialog by dragging motes with ALT button pressed
This commit is contained in:
parent
78069e8853
commit
81dbcf1654
2 changed files with 42 additions and 36 deletions
|
@ -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. \
|
||||||
|
|
|
@ -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.
|
|
||||||
* Control or Shift pressed: We should either pan or zoom */
|
|
||||||
if (mouseEvent.isControlDown() || mouseEvent.isShiftDown()
|
|
||||||
|| motes == null || motes.length == 0) {
|
|
||||||
if (mouseEvent.isControlDown()) {
|
if (mouseEvent.isControlDown()) {
|
||||||
/* Zoom */
|
/* Zoom */
|
||||||
zooming = true;
|
zooming = true;
|
||||||
zoomingPixel = new Point(x, y);
|
zoomingPixel = new Point(x, y);
|
||||||
zoomingPosition = transformPixelToPosition(zoomingPixel);
|
zoomingPosition = transformPixelToPosition(zoomingPixel);
|
||||||
zoomStart = viewportTransform.getScaleX();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beginMoveRequest(Mote moteToMove, boolean withTiming) {
|
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, 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,8 +755,9 @@ 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) {
|
||||||
|
Position newPos = transformPixelToPosition(x, y);
|
||||||
|
if (moveConfirm) {
|
||||||
String options[] = {"Yes", "Cancel"};
|
String options[] = {"Yes", "Cancel"};
|
||||||
int returnValue = JOptionPane.showOptionDialog(Visualizer.this,
|
int returnValue = JOptionPane.showOptionDialog(Visualizer.this,
|
||||||
"Move mote to" +
|
"Move mote to" +
|
||||||
|
@ -763,18 +767,20 @@ public class Visualizer extends VisPlugin {
|
||||||
"Move mote?",
|
"Move mote?",
|
||||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
|
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
|
||||||
null, options, options[0]);
|
null, options, options[0]);
|
||||||
if (returnValue == JOptionPane.YES_OPTION) {
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue