Search in sources :

Example 16 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by logisim-evolution.

the class CanvasListener method handlePopupTrigger.

private void handlePopupTrigger(MouseEvent e) {
    final var loc = Location.create(e.getX(), e.getY());
    final var objects = canvas.getModel().getObjectsFromTop();
    CanvasObject clicked = null;
    for (final var o : objects) {
        if (o.contains(loc, false)) {
            clicked = o;
            break;
        }
    }
    if (clicked == null) {
        for (final var o : objects) {
            if (o.contains(loc, true)) {
                clicked = o;
                break;
            }
        }
    }
    canvas.showPopupMenu(e, clicked);
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject)

Example 17 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by logisim-evolution.

the class AttrTableSelectionModel method getTitle.

@Override
public String getTitle() {
    final var sel = canvas.getSelection();
    Class<? extends CanvasObject> commonClass = null;
    var commonCount = 0;
    CanvasObject firstObject = null;
    var totalCount = 0;
    for (final var obj : sel.getSelected()) {
        if (firstObject == null) {
            firstObject = obj;
            commonClass = obj.getClass();
            commonCount = 1;
        } else if (obj.getClass() == commonClass) {
            commonCount++;
        } else {
            commonClass = null;
        }
        totalCount++;
    }
    if (firstObject == null) {
        return null;
    } else if (commonClass == null) {
        return S.get("selectionVarious", "" + totalCount);
    } else if (commonCount == 1) {
        return firstObject.getDisplayNameAndLabel();
    } else {
        return S.get("selectionMultiple", firstObject.getDisplayName(), "" + commonCount);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject)

Example 18 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class AttrTableSelectionModel method getTitle.

@Override
public String getTitle() {
    final var sel = canvas.getSelection();
    Class<? extends CanvasObject> commonClass = null;
    var commonCount = 0;
    CanvasObject firstObject = null;
    var totalCount = 0;
    for (final var obj : sel.getSelected()) {
        if (firstObject == null) {
            firstObject = obj;
            commonClass = obj.getClass();
            commonCount = 1;
        } else if (obj.getClass() == commonClass) {
            commonCount++;
        } else {
            commonClass = null;
        }
        totalCount++;
    }
    if (firstObject == null) {
        return null;
    } else if (commonClass == null) {
        return S.get("selectionVarious", "" + totalCount);
    } else if (commonCount == 1) {
        return firstObject.getDisplayNameAndLabel();
    } else {
        return S.get("selectionMultiple", firstObject.getDisplayName(), "" + commonCount);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject)

Example 19 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class CanvasListener method handlePorts.

private void handlePorts(MouseEvent e) {
    final var loc = Location.create(e.getX(), e.getY());
    final var objects = canvas.getModel().getObjectsFromTop();
    final var ports = new ArrayList<CanvasObject>();
    CanvasObject newSelectedPort = null;
    for (final var object : objects) {
        if (object instanceof AppearancePort)
            ports.add(object);
    }
    for (final var port : ports) {
        if (port.contains(loc, false) || port.contains(loc, true)) {
            newSelectedPort = port;
        }
    }
    if (newSelectedPort != selectedPort) {
        if (newSelectedPort == null) {
            canvas.setTooltip(null, null);
            canvas.repaint(canvas.getVisibleRect());
        } else {
            canvas.setTooltip(loc, newSelectedPort.getDisplayNameAndLabel());
            canvas.repaint(canvas.getVisibleRect());
        }
        selectedPort = newSelectedPort;
    }
}
Also used : AppearancePort(com.cburch.logisim.circuit.appear.AppearancePort) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList)

Example 20 with CanvasObject

use of com.cburch.draw.model.CanvasObject 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;
    final var locs = locations;
    for (var i = locs.size() - 2; i >= 0; i--) {
        if (locs.get(i).equals(locs.get(i + 1)))
            locs.remove(i);
    }
    if (locs.size() > 1) {
        final var 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) Poly(com.cburch.draw.shapes.Poly)

Aggregations

CanvasObject (com.cburch.draw.model.CanvasObject)45 Location (com.cburch.logisim.data.Location)15 ArrayList (java.util.ArrayList)13 Handle (com.cburch.draw.model.Handle)9 Selection (com.cburch.draw.canvas.Selection)8 ModelAddAction (com.cburch.draw.actions.ModelAddAction)7 Direction (com.cburch.logisim.data.Direction)5 HandleGesture (com.cburch.draw.model.HandleGesture)4 Poly (com.cburch.draw.shapes.Poly)4 Instance (com.cburch.logisim.instance.Instance)4 Map (java.util.Map)4 Rectangle (com.cburch.draw.shapes.Rectangle)3 HashMap (java.util.HashMap)3 AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)2 CanvasModel (com.cburch.draw.model.CanvasModel)2 Circuit (com.cburch.logisim.circuit.Circuit)2 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)2 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)2 Attribute (com.cburch.logisim.data.Attribute)2 Bounds (com.cburch.logisim.data.Bounds)2