@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;
}