use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class TextTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
if (!proj.getLogisimFile().contains(circ)) {
if (caret != null)
caret.cancelEditing();
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
return;
}
// Maybe user is clicking within the current caret.
if (caret != null) {
if (caret.getBounds(g).contains(e.getX(), e.getY())) {
// Yes
caret.mousePressed(e);
proj.repaintCanvas();
return;
} else {
// No. End the current caret.
caret.stopEditing();
}
}
// caret will be null at this point
// Otherwise search for a new caret.
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
// First search in selection.
for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
// Then search in circuit
if (caret == null) {
for (Component comp : circ.getAllContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
}
// if nothing found, create a new label
if (caret == null) {
if (loc.getX() < 0 || loc.getY() < 0)
return;
AttributeSet copy = (AttributeSet) attrs.clone();
caretComponent = Text.FACTORY.createComponent(loc, copy);
caretCreatingText = true;
TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
proj.getFrame().viewComponentAttributes(circ, caretComponent);
}
}
if (caret != null) {
caretCanvas = canvas;
caretCircuit = canvas.getCircuit();
caret.addCaretListener(listener);
caretCircuit.addCircuitListener(listener);
}
proj.repaintCanvas();
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class WiringTool method computeMove.
private boolean computeMove(int newX, int newY) {
if (cur.getX() == newX && cur.getY() == newY)
return false;
Location start = this.start;
if (direction == 0) {
if (newX != start.getX())
direction = HORIZONTAL;
else if (newY != start.getY())
direction = VERTICAL;
} else if (direction == HORIZONTAL && newX == start.getX()) {
if (newY == start.getY())
direction = 0;
else
direction = VERTICAL;
} else if (direction == VERTICAL && newY == start.getY()) {
if (newX == start.getX())
direction = 0;
else
direction = HORIZONTAL;
}
return true;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class AvoidanceMap method markWire.
public void markWire(Wire w, int dx, int dy) {
HashMap<Location, String> avoid = this.avoid;
boolean translated = dx != 0 || dy != 0;
Location loc0 = w.getEnd0();
Location loc1 = w.getEnd1();
if (translated) {
loc0 = loc0.translate(dx, dy);
loc1 = loc1.translate(dx, dy);
}
avoid.put(loc0, Connector.ALLOW_NEITHER);
avoid.put(loc1, Connector.ALLOW_NEITHER);
int x0 = loc0.getX();
int y0 = loc0.getY();
int x1 = loc1.getX();
int y1 = loc1.getY();
if (x0 == x1) {
// vertical wire
for (Location loc : Wire.create(loc0, loc1)) {
Object prev = avoid.put(loc, Connector.ALLOW_HORIZONTAL);
if (prev == Connector.ALLOW_NEITHER || prev == Connector.ALLOW_VERTICAL) {
avoid.put(loc, Connector.ALLOW_NEITHER);
}
}
} else if (y0 == y1) {
// horizontal wire
for (Location loc : Wire.create(loc0, loc1)) {
Object prev = avoid.put(loc, Connector.ALLOW_VERTICAL);
if (prev == Connector.ALLOW_NEITHER || prev == Connector.ALLOW_HORIZONTAL) {
avoid.put(loc, Connector.ALLOW_NEITHER);
}
}
} else {
// diagonal - shouldn't happen
throw new RuntimeException("diagonal wires not supported");
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class AvoidanceMap method unmarkWire.
public void unmarkWire(Wire w, Location deletedEnd, Set<Location> unmarkable) {
Location loc0 = w.getEnd0();
Location loc1 = w.getEnd1();
if (unmarkable == null || unmarkable.contains(deletedEnd)) {
avoid.remove(deletedEnd);
}
int x0 = loc0.getX();
int y0 = loc0.getY();
int x1 = loc1.getX();
int y1 = loc1.getY();
if (x0 == x1) {
// vertical wire
for (Location loc : w) {
if (unmarkable == null || unmarkable.contains(deletedEnd)) {
Object prev = avoid.remove(loc);
if (prev != Connector.ALLOW_HORIZONTAL && prev != null) {
avoid.put(loc, Connector.ALLOW_VERTICAL);
}
}
}
} else if (y0 == y1) {
// horizontal wire
for (Location loc : w) {
if (unmarkable == null || unmarkable.contains(deletedEnd)) {
Object prev = avoid.remove(loc);
if (prev != Connector.ALLOW_VERTICAL && prev != null) {
avoid.put(loc, Connector.ALLOW_HORIZONTAL);
}
}
}
} else {
// diagonal - shouldn't happen
throw new RuntimeException("diagonal wires not supported");
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CircuitState method copyFrom.
private void copyFrom(CircuitState src, Propagator base) {
this.base = base;
this.parentComp = src.parentComp;
this.parentState = src.parentState;
HashMap<CircuitState, CircuitState> substateData = new HashMap<CircuitState, CircuitState>();
this.substates = new HashSet<CircuitState>();
for (CircuitState oldSub : src.substates) {
CircuitState newSub = new CircuitState(src.proj, oldSub.circuit);
newSub.copyFrom(oldSub, base);
newSub.parentState = this;
this.substates.add(newSub);
substateData.put(oldSub, newSub);
}
for (Component key : src.componentData.keySet()) {
Object oldValue = src.componentData.get(key);
if (oldValue instanceof CircuitState) {
Object newValue = substateData.get(oldValue);
if (newValue != null)
this.componentData.put(key, newValue);
else
this.componentData.remove(key);
} else {
Object newValue;
if (oldValue instanceof ComponentState) {
newValue = ((ComponentState) oldValue).clone();
} else {
newValue = oldValue;
}
this.componentData.put(key, newValue);
}
}
for (Location key : src.causes.keySet()) {
Propagator.SetData oldValue = src.causes.get(key);
Propagator.SetData newValue = oldValue.cloneFor(this);
this.causes.put(key, newValue);
}
if (src.wireData != null) {
this.wireData = (CircuitWires.State) src.wireData.clone();
}
this.values.putAll(src.values);
this.dirtyComponents.addAll(src.dirtyComponents);
this.dirtyPoints.addAll(src.dirtyPoints);
}
Aggregations