better wiring mouse listener, wire ends if connected to a pin

This commit is contained in:
hneemann 2016-03-31 13:00:17 +02:00
parent 5b11532520
commit 2a2f037421
2 changed files with 20 additions and 3 deletions

View File

@ -212,6 +212,18 @@ public class Circuit implements Drawable {
return null;
}
public boolean isPinPos(Vector pos) {
VisualElement el = getElementAt(pos);
if (el == null) return false;
for (Pin p : el.getPins())
if (p.getPos().equals(pos))
return true;
return false;
}
public void modified() {
modified = true;
}

View File

@ -216,10 +216,15 @@ public class CircuitComponent extends JComponent {
if (e.getButton() == MouseEvent.BUTTON1) {
if (wire != null) {
circuit.add(wire);
repaint();
}
Vector startPos = raster(getPosVector(e));
if (circuit.isPinPos(startPos))
wire = null;
else
wire = new Wire(startPos, startPos);
} else {
Vector startPos = raster(getPosVector(e));
wire = new Wire(startPos, startPos);
}
repaint();
} else {
if (wire != null) {