Search in sources :

Example 6 with ReorderRequest

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

the class ModelReorderAction method createLowerBottom.

public static ModelReorderAction createLowerBottom(CanvasModel model, Collection<? extends CanvasObject> objects) {
    List<ReorderRequest> reqs = new ArrayList<ReorderRequest>();
    Map<CanvasObject, Integer> zmap = ZOrder.getZIndex(objects, model);
    int to = 0;
    for (Map.Entry<CanvasObject, Integer> entry : zmap.entrySet()) {
        CanvasObject obj = entry.getKey();
        int from = entry.getValue().intValue();
        reqs.add(new ReorderRequest(obj, from, to));
    }
    if (reqs.isEmpty()) {
        return null;
    } else {
        Collections.sort(reqs, ReorderRequest.ASCENDING_FROM);
        repairRequests(reqs);
        return new ModelReorderAction(model, reqs);
    }
}
Also used : ReorderRequest(com.cburch.draw.model.ReorderRequest) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 7 with ReorderRequest

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

the class ModelReorderAction method createLower.

public static ModelReorderAction createLower(CanvasModel model, Collection<? extends CanvasObject> objects) {
    List<ReorderRequest> reqs = new ArrayList<ReorderRequest>();
    Map<CanvasObject, Integer> zmap = ZOrder.getZIndex(objects, model);
    for (Map.Entry<CanvasObject, Integer> entry : zmap.entrySet()) {
        CanvasObject obj = entry.getKey();
        int from = entry.getValue().intValue();
        CanvasObject above = ZOrder.getObjectBelow(obj, model, objects);
        if (above != null) {
            int to = ZOrder.getZIndex(above, model);
            if (objects.contains(above)) {
                to++;
            }
            reqs.add(new ReorderRequest(obj, from, to));
        }
    }
    if (reqs.isEmpty()) {
        return null;
    } else {
        Collections.sort(reqs, ReorderRequest.ASCENDING_FROM);
        repairRequests(reqs);
        return new ModelReorderAction(model, reqs);
    }
}
Also used : ReorderRequest(com.cburch.draw.model.ReorderRequest) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

ReorderRequest (com.cburch.draw.model.ReorderRequest)7 ArrayList (java.util.ArrayList)6 CanvasObject (com.cburch.draw.model.CanvasObject)5 Map (java.util.Map)4 ModelAddAction (com.cburch.draw.actions.ModelAddAction)1 ModelReorderAction (com.cburch.draw.actions.ModelReorderAction)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1