use of com.cburch.draw.actions.ModelMoveHandleAction in project logisim-evolution by reds-heig.
the class SelectTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
beforePressSelection = null;
beforePressHandle = null;
setMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
CanvasModel model = canvas.getModel();
Selection selection = canvas.getSelection();
Set<CanvasObject> selected = selection.getSelected();
int action = curAction;
curAction = IDLE;
if (!dragEffective) {
Location loc = dragEnd;
CanvasObject o = getObjectAt(model, loc.getX(), loc.getY(), false);
if (o != null) {
Handle han = o.canDeleteHandle(loc);
if (han != null) {
selection.setHandleSelected(han);
} else {
han = o.canInsertHandle(loc);
if (han != null) {
selection.setHandleSelected(han);
}
}
}
}
Location start = dragStart;
int x1 = e.getX();
int y1 = e.getY();
switch(action) {
case MOVE_ALL:
Location moveDelta = selection.getMovingDelta();
if (dragEffective && !moveDelta.equals(Location.create(0, 0))) {
canvas.doAction(new ModelTranslateAction(model, selected, moveDelta.getX(), moveDelta.getY()));
}
break;
case MOVE_HANDLE:
HandleGesture gesture = curGesture;
curGesture = null;
if (dragEffective && gesture != null) {
ModelMoveHandleAction act;
act = new ModelMoveHandleAction(model, gesture);
canvas.doAction(act);
Handle result = act.getNewHandle();
if (result != null) {
Handle h = result.getObject().canDeleteHandle(result.getLocation());
selection.setHandleSelected(h);
}
}
break;
case RECT_SELECT:
if (dragEffective) {
Bounds bds = Bounds.create(start).add(x1, y1);
selection.setSelected(canvas.getModel().getObjectsIn(bds), true);
} else {
CanvasObject clicked;
clicked = getObjectAt(model, start.getX(), start.getY(), true);
if (clicked != null) {
selection.clearSelected();
selection.setSelected(clicked, true);
}
}
break;
case RECT_TOGGLE:
if (dragEffective) {
Bounds bds = Bounds.create(start).add(x1, y1);
selection.toggleSelected(canvas.getModel().getObjectsIn(bds));
} else {
CanvasObject clicked;
clicked = getObjectAt(model, start.getX(), start.getY(), true);
selection.setSelected(clicked, !selected.contains(clicked));
}
break;
default:
break;
}
selection.clearDrawsSuppressed();
repaintArea(canvas);
}
Aggregations