use of com.cburch.draw.model.Handle 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);
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class AppearanceAnchor method getHandles.
@Override
public List<Handle> getHandles(HandleGesture gesture) {
Location c = getLocation();
Location end = c.translate(facing, RADIUS + INDICATOR_LENGTH);
return UnmodifiableList.create(new Handle[] { new Handle(this, c), new Handle(this, end) });
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class AppearancePort method getHandles.
@Override
public List<Handle> getHandles(HandleGesture gesture) {
Location loc = getLocation();
int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
return UnmodifiableList.create(new Handle[] { new Handle(this, loc.translate(-r, -r)), new Handle(this, loc.translate(r, -r)), new Handle(this, loc.translate(r, r)), new Handle(this, loc.translate(-r, r)) });
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class SelectTool method setMouse.
private void setMouse(Canvas canvas, int mx, int my, int mods) {
lastMouseX = mx;
lastMouseY = my;
boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
boolean ctrl = (mods & InputEvent.CTRL_DOWN_MASK) != 0;
Location newEnd = Location.create(mx, my);
dragEnd = newEnd;
Location start = dragStart;
int dx = newEnd.getX() - start.getX();
int dy = newEnd.getY() - start.getY();
if (!dragEffective) {
if (Math.abs(dx) + Math.abs(dy) > DRAG_TOLERANCE) {
dragEffective = true;
} else {
return;
}
}
switch(curAction) {
case MOVE_HANDLE:
HandleGesture gesture = curGesture;
if (ctrl) {
Handle h = gesture.getHandle();
dx = canvas.snapX(h.getX() + dx) - h.getX();
dy = canvas.snapY(h.getY() + dy) - h.getY();
}
curGesture = new HandleGesture(gesture.getHandle(), dx, dy, mods);
canvas.getSelection().setHandleGesture(curGesture);
break;
case MOVE_ALL:
if (ctrl) {
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
for (CanvasObject o : canvas.getSelection().getSelected()) {
for (Handle handle : o.getHandles(null)) {
int x = handle.getX();
int y = handle.getY();
if (x < minX)
minX = x;
if (y < minY)
minY = y;
}
}
dx = canvas.snapX(minX + dx) - minX;
dy = canvas.snapY(minY + dy) - minY;
}
if (shift) {
if (Math.abs(dx) > Math.abs(dy)) {
dy = 0;
} else {
dx = 0;
}
}
canvas.getSelection().setMovingDelta(dx, dy);
break;
default:
break;
}
repaintArea(canvas);
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Line method getHandles.
@Override
public List<Handle> getHandles(HandleGesture gesture) {
if (gesture == null) {
return UnmodifiableList.create(new Handle[] { new Handle(this, x0, y0), new Handle(this, x1, y1) });
} else {
Handle h = gesture.getHandle();
int dx = gesture.getDeltaX();
int dy = gesture.getDeltaY();
Handle[] ret = new Handle[2];
ret[0] = new Handle(this, h.isAt(x0, y0) ? Location.create(x0 + dx, y0 + dy) : Location.create(x0, y0));
ret[1] = new Handle(this, h.isAt(x1, y1) ? Location.create(x1 + dx, y1 + dy) : Location.create(x1, y1));
return UnmodifiableList.create(ret);
}
}
Aggregations