use of com.cburch.draw.model.ReorderRequest 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));
}
use of com.cburch.draw.model.ReorderRequest in project logisim-evolution by reds-heig.
the class ModelReorderAction method createRaiseTop.
public static ModelReorderAction createRaiseTop(CanvasModel model, Collection<? extends CanvasObject> objects) {
List<ReorderRequest> reqs = new ArrayList<ReorderRequest>();
Map<CanvasObject, Integer> zmap = ZOrder.getZIndex(objects, model);
int to = model.getObjectsFromBottom().size() - 1;
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);
}
}
use of com.cburch.draw.model.ReorderRequest in project logisim-evolution by reds-heig.
the class ModelReorderAction method createRaise.
public static ModelReorderAction createRaise(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.getObjectAbove(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.DESCENDING_FROM);
repairRequests(reqs);
return new ModelReorderAction(model, reqs);
}
}
use of com.cburch.draw.model.ReorderRequest in project logisim-evolution by reds-heig.
the class ModelReorderAction method repairRequests.
private static void repairRequests(List<ReorderRequest> reqs) {
for (int i = 0, n = reqs.size(); i < n; i++) {
ReorderRequest req = reqs.get(i);
int from = req.getFromIndex();
int to = req.getToIndex();
for (int j = 0; j < i; j++) {
ReorderRequest prev = reqs.get(j);
int prevFrom = prev.getFromIndex();
int prevTo = prev.getToIndex();
if (prevFrom <= from && from < prevTo) {
from--;
} else if (prevTo <= from && from < prevFrom) {
from++;
}
if (prevFrom <= to && to < prevTo) {
to--;
} else if (prevTo <= to && to < prevFrom) {
to++;
}
}
if (from != req.getFromIndex() || to != req.getToIndex()) {
reqs.set(i, new ReorderRequest(req.getObject(), from, to));
}
}
for (int i = reqs.size() - 1; i >= 0; i--) {
ReorderRequest req = reqs.get(i);
if (req.getFromIndex() == req.getToIndex()) {
reqs.remove(i);
}
}
}
use of com.cburch.draw.model.ReorderRequest in project logisim-evolution by reds-heig.
the class ModelReorderAction method undoSub.
@Override
void undoSub(CanvasModel model) {
List<ReorderRequest> inv = new ArrayList<ReorderRequest>(requests.size());
for (int i = requests.size() - 1; i >= 0; i--) {
ReorderRequest r = requests.get(i);
inv.add(new ReorderRequest(r.getObject(), r.getToIndex(), r.getFromIndex()));
}
model.reorderObjects(inv);
}
Aggregations