Search in sources :

Example 11 with CanvasObject

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

the class ZOrder method sortXFirst.

private static <E extends CanvasObject> List<E> sortXFirst(Collection<E> objects, CanvasModel model, Collection<CanvasObject> objs) {
    Set<E> set = toSet(objects);
    List<E> ret = new ArrayList<E>(objects.size());
    for (CanvasObject o : objs) {
        if (set.contains(o)) {
            @SuppressWarnings("unchecked") E toAdd = (E) o;
            ret.add(toAdd);
        }
    }
    return ret;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList)

Example 12 with CanvasObject

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

the class ZOrder method getZIndex.

public static Map<CanvasObject, Integer> getZIndex(Collection<? extends CanvasObject> query, CanvasModel model) {
    // from the bottom up.
    if (query == null)
        return Collections.emptyMap();
    Set<? extends CanvasObject> querySet = toSet(query);
    Map<CanvasObject, Integer> ret;
    ret = new LinkedHashMap<CanvasObject, Integer>(query.size());
    int z = -1;
    for (CanvasObject o : model.getObjectsFromBottom()) {
        z++;
        if (querySet.contains(o)) {
            ret.put(o, Integer.valueOf(z));
        }
    }
    return ret;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject)

Example 13 with CanvasObject

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

the class Main method main.

public static void main(String[] args) {
    DrawingAttributeSet attrs = new DrawingAttributeSet();
    Drawing model = new Drawing();
    CanvasObject rect = attrs.applyTo(new Rectangle(25, 25, 50, 50));
    model.addObjects(0, Collections.singleton(rect));
    showFrame(model, "Drawing 1");
    showFrame(model, "Drawing 2");
}
Also used : Drawing(com.cburch.draw.model.Drawing) CanvasObject(com.cburch.draw.model.CanvasObject) Rectangle(com.cburch.draw.shapes.Rectangle) DrawingAttributeSet(com.cburch.draw.tools.DrawingAttributeSet)

Example 14 with CanvasObject

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

the class Selection method setHandleSelected.

public void setHandleSelected(Handle handle) {
    Handle cur = selectedHandle;
    boolean same = cur == null ? handle == null : cur.equals(handle);
    if (!same) {
        selectedHandle = handle;
        curHandleGesture = null;
        Collection<CanvasObject> objs;
        if (handle == null) {
            objs = Collections.emptySet();
        } else {
            objs = Collections.singleton(handle.getObject());
        }
        fireChanged(SelectionEvent.ACTION_HANDLE, objs);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Handle(com.cburch.draw.model.Handle)

Example 15 with CanvasObject

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

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)

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