[cooja] plugins/Visualizer: Partly implement behavior of beginMoveRequest to fit new mote movement handling

This commit is contained in:
Enrico Joerns 2014-06-06 11:50:04 +02:00
parent 39f7ca586f
commit 73fbb69e39

View File

@ -437,6 +437,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
handleMouseDrag(e, false); handleMouseDrag(e, false);
} }
@Override
public void mouseMoved(MouseEvent e) {
handleMouseDrag(e, false);
}
}); });
canvas.addMouseListener(new MouseAdapter() { canvas.addMouseListener(new MouseAdapter() {
@Override @Override
@ -894,6 +899,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
pressedPos = transformPixelToPosition(mouseEvent.getPoint()); 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 // this is the state we have from pressing button
final Mote[] foundMotes = findMotesAtPosition(x, y); final Mote[] foundMotes = findMotesAtPosition(x, y);
if (foundMotes == null) { if (foundMotes == null) {
@ -942,6 +952,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
mouseActionState = MotesActionState.PANNING; mouseActionState = MotesActionState.PANNING;
} }
else { else {
/* If we start moving with on a cursor mote, switch to MOVING */
mouseActionState = MotesActionState.MOVING; mouseActionState = MotesActionState.MOVING;
// save start position // save start position
for (Mote m : selectedMotes) { for (Mote m : selectedMotes) {
@ -1048,17 +1059,27 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
repaint(); repaint();
} }
private void beginMoveRequest(Mote motesToMove, boolean withTiming, boolean confirm) { private void beginMoveRequest(Mote selectedMote, boolean withTiming, boolean confirm) {
if (withTiming) { if (withTiming) {
moveStartTime = System.currentTimeMillis(); moveStartTime = System.currentTimeMillis();
} }
else { else {
moveStartTime = -1; moveStartTime = -1;
} }
mouseActionState = MotesActionState.DEFAULT_PRESS; /* Save start positions and set move-start position to clicked mote */
selectedMotes.clear(); for (Mote m : selectedMotes) {
selectedMotes.add(motesToMove); Position pos = m.getInterfaces().getPosition();
repaint(); 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() { private double zoomFactor() {