Search in sources :

Example 6 with CanvasModel

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);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ModelAddAction(com.cburch.draw.actions.ModelAddAction) CanvasModel(com.cburch.draw.model.CanvasModel) Poly(com.cburch.draw.shapes.Poly) Location(com.cburch.logisim.data.Location)

Example 7 with CanvasModel

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);
}
Also used : HandleGesture(com.cburch.draw.model.HandleGesture) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ModelTranslateAction(com.cburch.draw.actions.ModelTranslateAction) Bounds(com.cburch.logisim.data.Bounds) CanvasModel(com.cburch.draw.model.CanvasModel) ModelMoveHandleAction(com.cburch.draw.actions.ModelMoveHandleAction) Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 8 with CanvasModel

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);
        }
    }
}
Also used : CanvasModel(com.cburch.draw.model.CanvasModel)

Example 9 with CanvasModel

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();
    }
}
Also used : Graphics(java.awt.Graphics) CanvasModel(com.cburch.draw.model.CanvasModel)

Example 10 with CanvasModel

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);
}
Also used : CanvasModel(com.cburch.draw.model.CanvasModel)

Aggregations

CanvasModel (com.cburch.draw.model.CanvasModel)11 CanvasObject (com.cburch.draw.model.CanvasObject)6 ModelAddAction (com.cburch.draw.actions.ModelAddAction)4 Location (com.cburch.logisim.data.Location)3 Selection (com.cburch.draw.canvas.Selection)2 Poly (com.cburch.draw.shapes.Poly)2 Bounds (com.cburch.logisim.data.Bounds)2 ModelChangeAttributeAction (com.cburch.draw.actions.ModelChangeAttributeAction)1 ModelMoveHandleAction (com.cburch.draw.actions.ModelMoveHandleAction)1 ModelRemoveAction (com.cburch.draw.actions.ModelRemoveAction)1 ModelTranslateAction (com.cburch.draw.actions.ModelTranslateAction)1 AttributeMapKey (com.cburch.draw.model.AttributeMapKey)1 Handle (com.cburch.draw.model.Handle)1 HandleGesture (com.cburch.draw.model.HandleGesture)1 Curve (com.cburch.draw.shapes.Curve)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Graphics (java.awt.Graphics)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1