}
}
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
if (state == MOVING) {
setState(proj, IDLE);
computeDxDy(proj, e, g);
int dx = curDx;
int dy = curDy;
if (dx != 0 || dy != 0) {
if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
} else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
} else {
boolean connect = shouldConnect(canvas, e.getModifiersEx());
drawConnections = false;
ReplacementMap repl;
if (connect) {
MoveGesture gesture = moveGesture;
if (gesture == null) {
gesture = new MoveGesture(new MoveRequestHandler(canvas),
canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
}
canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
MoveResult result = gesture.forceRequest(dx, dy);
clearCanvasMessage(canvas, dx, dy);
repl = result.getReplacementMap();
} else {
repl = null;
}
Selection sel = proj.getSelection();
proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
}
}
moveGesture = null;
proj.repaintCanvas();
} else if (state == RECT_SELECT) {
Bounds bds = Bounds.create(start).add(start.getX() + curDx,
start.getY() + curDy);
Circuit circuit = canvas.getCircuit();
Selection sel = proj.getSelection();
Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
for (Component comp : circuit.getAllWithin(bds, g)) {
if (!in_sel.contains(comp)) sel.add(comp);
}
Action act = SelectionActions.drop(sel, in_sel);
if (act != null) {
proj.doAction(act);
}
setState(proj, IDLE);
proj.repaintCanvas();
}
}