use of com.cburch.draw.actions.ModelReorderAction 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));
}
Aggregations