Search in sources :

Example 1 with ModelAddAction

use of com.cburch.draw.actions.ModelAddAction in project logisim-evolution by reds-heig.

the class AppearanceCanvas method doAction.

@Override
public void doAction(Action canvasAction) {
    Circuit circuit = circuitState.getCircuit();
    if (!proj.getLogisimFile().contains(circuit)) {
        return;
    }
    if (canvasAction instanceof ModelReorderAction) {
        int max = getMaxIndex(getModel());
        ModelReorderAction reorder = (ModelReorderAction) canvasAction;
        List<ReorderRequest> rs = reorder.getReorderRequests();
        List<ReorderRequest> mod = new ArrayList<ReorderRequest>(rs.size());
        boolean changed = false;
        boolean movedToMax = false;
        for (ReorderRequest r : rs) {
            CanvasObject o = r.getObject();
            if (o instanceof AppearanceElement) {
                changed = true;
            } else {
                if (r.getToIndex() > max) {
                    int from = r.getFromIndex();
                    changed = true;
                    movedToMax = true;
                    if (from == max && !movedToMax) {
                        // this change is ineffective - don't add it
                        ;
                    } else {
                        mod.add(new ReorderRequest(o, from, max));
                    }
                } else {
                    if (r.getToIndex() == max)
                        movedToMax = true;
                    mod.add(r);
                }
            }
        }
        if (changed) {
            if (mod.isEmpty()) {
                return;
            }
            canvasAction = new ModelReorderAction(getModel(), mod);
        }
    }
    if (canvasAction instanceof ModelAddAction) {
        ModelAddAction addAction = (ModelAddAction) canvasAction;
        int cur = addAction.getDestinationIndex();
        int max = getMaxIndex(getModel());
        if (cur > max) {
            canvasAction = new ModelAddAction(getModel(), addAction.getObjects(), max + 1);
        }
    }
    proj.doAction(new CanvasActionAdapter(circuit, canvasAction));
}
Also used : ReorderRequest(com.cburch.draw.model.ReorderRequest) CanvasObject(com.cburch.draw.model.CanvasObject) ModelReorderAction(com.cburch.draw.actions.ModelReorderAction) ModelAddAction(com.cburch.draw.actions.ModelAddAction) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement)

Example 2 with ModelAddAction

use of com.cburch.draw.actions.ModelAddAction in project logisim-evolution by reds-heig.

the class CurveTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    Curve c = updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
    mouseDown = false;
    if (state == CONTROL_DRAG) {
        if (c != null) {
            attrs.applyTo(c);
            CanvasModel model = canvas.getModel();
            canvas.doAction(new ModelAddAction(model, c));
            canvas.toolGestureComplete(this, c);
        }
        state = BEFORE_CREATION;
    }
    repaintArea(canvas);
}
Also used : ModelAddAction(com.cburch.draw.actions.ModelAddAction) Curve(com.cburch.draw.shapes.Curve) CanvasModel(com.cburch.draw.model.CanvasModel)

Example 3 with ModelAddAction

use of com.cburch.draw.actions.ModelAddAction in project logisim-evolution by reds-heig.

the class PolyTool method commit.

private CanvasObject commit(Canvas canvas) {
    if (!active)
        return null;
    CanvasObject add = null;
    active = false;
    List<Location> locs = locations;
    for (int i = locs.size() - 2; i >= 0; i--) {
        if (locs.get(i).equals(locs.get(i + 1)))
            locs.remove(i);
    }
    if (locs.size() > 1) {
        CanvasModel model = canvas.getModel();
        add = new Poly(closed, locs);
        canvas.doAction(new ModelAddAction(model, add));
        repaintArea(canvas);
    }
    locs.clear();
    return 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 4 with ModelAddAction

use of com.cburch.draw.actions.ModelAddAction in project logisim-evolution by reds-heig.

the class RectangularTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        Bounds oldBounds = currentBounds;
        Bounds bds = computeBounds(canvas, e.getX(), e.getY(), e.getModifiersEx());
        currentBounds = Bounds.EMPTY_BOUNDS;
        active = false;
        CanvasObject add = null;
        if (bds.getWidth() != 0 && bds.getHeight() != 0) {
            CanvasModel model = canvas.getModel();
            add = createShape(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas, oldBounds.add(bds));
        }
        canvas.toolGestureComplete(this, add);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Bounds(com.cburch.logisim.data.Bounds) ModelAddAction(com.cburch.draw.actions.ModelAddAction) CanvasModel(com.cburch.draw.model.CanvasModel)

Example 5 with ModelAddAction

use of com.cburch.draw.actions.ModelAddAction in project logisim-evolution by reds-heig.

the class TextTool method commitText.

private void commitText(Canvas canvas) {
    Text cur = curText;
    boolean isNew = isTextNew;
    String newText = field.getText();
    if (cur == null) {
        return;
    }
    cancelText(canvas);
    if (isNew) {
        if (!newText.equals("")) {
            cur.setText(newText);
            canvas.doAction(new ModelAddAction(canvas.getModel(), cur));
        }
    } else {
        String oldText = cur.getText();
        if (newText.equals("")) {
            canvas.doAction(new ModelRemoveAction(canvas.getModel(), cur));
        } else if (!oldText.equals(newText)) {
            canvas.doAction(new ModelEditTextAction(canvas.getModel(), cur, newText));
        }
    }
}
Also used : ModelAddAction(com.cburch.draw.actions.ModelAddAction) ModelRemoveAction(com.cburch.draw.actions.ModelRemoveAction) Text(com.cburch.draw.shapes.Text) ModelEditTextAction(com.cburch.draw.actions.ModelEditTextAction)

Aggregations

ModelAddAction (com.cburch.draw.actions.ModelAddAction)6 CanvasModel (com.cburch.draw.model.CanvasModel)4 CanvasObject (com.cburch.draw.model.CanvasObject)4 Poly (com.cburch.draw.shapes.Poly)2 Location (com.cburch.logisim.data.Location)2 ModelEditTextAction (com.cburch.draw.actions.ModelEditTextAction)1 ModelRemoveAction (com.cburch.draw.actions.ModelRemoveAction)1 ModelReorderAction (com.cburch.draw.actions.ModelReorderAction)1 ReorderRequest (com.cburch.draw.model.ReorderRequest)1 Curve (com.cburch.draw.shapes.Curve)1 Text (com.cburch.draw.shapes.Text)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1 Bounds (com.cburch.logisim.data.Bounds)1 ArrayList (java.util.ArrayList)1