if (!(obj instanceof Mote)) {
return;
}
final Timer timer = new Timer(100, null);
final Mote mote = (Mote) obj;
timer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
/* Count down */
if (timer.getDelay() < 90) {
timer.stop();
highlightedMotes.remove(mote);
repaint();
return;
}
/* Toggle highlight state */
if (highlightedMotes.contains(mote)) {
highlightedMotes.remove(mote);
}
else {
highlightedMotes.add(mote);
}
timer.setDelay(timer.getDelay() - 1);
repaint();
}
});
timer.start();
}
});
/* Observe mote relations */
gui.addMoteRelationsObserver(moteRelationsObserver = new Observer() {
@Override
public void update(Observable obs, Object obj) {
repaint();
}
});
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) {
Iterator<Mote> iter = Visualizer.this.getSelectedMotes().iterator();
while (iter.hasNext()) {
Mote m = iter.next();
m.getSimulation().removeMote(m);
iter.remove();
}
}
});