use of com.cburch.logisim.circuit.appear.AppearanceElement 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.logisim.circuit.appear.AppearanceElement in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method computeEnabled.
@Override
public void computeEnabled() {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
Selection sel = canvas.getSelection();
boolean selEmpty = sel.isEmpty();
boolean canChange = proj.getLogisimFile().contains(circ);
boolean clipExists = !Clipboard.isEmpty();
boolean selHasRemovable = false;
for (CanvasObject o : sel.getSelected()) {
if (!(o instanceof AppearanceElement)) {
selHasRemovable = true;
}
}
boolean canRaise;
boolean canLower;
if (!selEmpty && canChange) {
Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
int zmin = Integer.MAX_VALUE;
int zmax = Integer.MIN_VALUE;
int count = 0;
for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
if (!(entry.getKey() instanceof AppearanceElement)) {
count++;
int z = entry.getValue().intValue();
if (z < zmin)
zmin = z;
if (z > zmax)
zmax = z;
}
}
int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
if (count > 0 && count <= maxPoss) {
canRaise = zmin <= maxPoss - count;
canLower = zmax >= count;
} else {
canRaise = false;
canLower = false;
}
} else {
canRaise = false;
canLower = false;
}
boolean canAddCtrl = false;
boolean canRemCtrl = false;
Handle handle = sel.getSelectedHandle();
if (handle != null && canChange) {
CanvasObject o = handle.getObject();
canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
}
setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
setEnabled(LogisimMenuBar.COPY, !selEmpty);
setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
setEnabled(LogisimMenuBar.SELECT_ALL, true);
setEnabled(LogisimMenuBar.RAISE, canRaise);
setEnabled(LogisimMenuBar.LOWER, canLower);
setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
Aggregations