use of com.cburch.draw.model.CanvasModel in project logisim-evolution by reds-heig.
the class LineTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
if (active) {
updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
Location start = mouseStart;
Location end = mouseEnd;
CanvasObject add = null;
if (!start.equals(end)) {
active = false;
CanvasModel model = canvas.getModel();
Location[] ends = { start, end };
List<Location> locs = UnmodifiableList.create(ends);
add = attrs.applyTo(new Poly(false, locs));
add.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
canvas.doAction(new ModelAddAction(model, add));
repaintArea(canvas);
}
canvas.toolGestureComplete(this, add);
}
}
use of com.cburch.draw.model.CanvasModel 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);
}
use of com.cburch.draw.model.CanvasModel in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method propertyChange.
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (prop.equals(Canvas.MODEL_PROPERTY)) {
CanvasModel oldModel = (CanvasModel) e.getOldValue();
if (oldModel != null) {
oldModel.removeCanvasModelListener(this);
}
CanvasModel newModel = (CanvasModel) e.getNewValue();
if (newModel != null) {
newModel.addCanvasModelListener(this);
}
}
}
use of com.cburch.draw.model.CanvasModel in project logisim-evolution by reds-heig.
the class Canvas method paintForeground.
protected void paintForeground(Graphics g) {
CanvasModel cModel = this.model;
CanvasTool tool = listener.getTool();
if (cModel != null) {
Graphics dup = g.create();
cModel.paint(g, selection);
dup.dispose();
}
if (tool != null) {
Graphics dup = g.create();
tool.draw(this, dup);
dup.dispose();
}
}
use of com.cburch.draw.model.CanvasModel in project logisim-evolution by reds-heig.
the class Canvas method setModel.
public void setModel(CanvasModel value, ActionDispatcher dispatcher) {
CanvasModel oldValue = model;
if (oldValue != null) {
if (!oldValue.equals(value)) {
oldValue.removeCanvasModelListener(listener);
}
}
model = value;
this.dispatcher = dispatcher;
if (value != null) {
value.addCanvasModelListener(listener);
}
selection.clearSelected();
repaint();
firePropertyChange(MODEL_PROPERTY, oldValue, value);
}
Aggregations