mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-22 11:55:15 -04:00
cleanup of insert wires modifiction
This commit is contained in:
parent
dfe8eca9ce
commit
0c19684d5e
@ -2530,7 +2530,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
||||
if (m instanceof VisualElement)
|
||||
builder.add(new ModifyInsertElement((VisualElement) m));
|
||||
}
|
||||
builder.add(new ModifyInsertWires(wires));
|
||||
builder.add(ModifyInsertWires.create(wires));
|
||||
modify(builder.build());
|
||||
}
|
||||
mouseNormal.activate();
|
||||
|
@ -7,34 +7,54 @@ package de.neemann.digital.gui.components.modification;
|
||||
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.Wire;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import de.neemann.digital.undo.Modification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Modifier to insert a list of wires.
|
||||
*/
|
||||
public class ModifyInsertWires implements Modification<Circuit> {
|
||||
private final ArrayList<Wire> wires;
|
||||
public final class ModifyInsertWires implements Modification<Circuit> {
|
||||
|
||||
/**
|
||||
* Creates a simplified modification.
|
||||
*
|
||||
* @param newWires the wires to insert
|
||||
* @return the modification
|
||||
*/
|
||||
public static Modification<Circuit> create(List<Wire> newWires) {
|
||||
switch (newWires.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return new ModifyInsertWire(newWires.get(0));
|
||||
default:
|
||||
return new ModifyInsertWires(newWires);
|
||||
}
|
||||
}
|
||||
|
||||
private final ArrayList<LocalWire> wires;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param newWires the wire to insert
|
||||
*/
|
||||
public ModifyInsertWires(Collection<Wire> newWires) {
|
||||
wires = new ArrayList<>();
|
||||
private ModifyInsertWires(Collection<Wire> newWires) {
|
||||
wires = new ArrayList<>(newWires.size());
|
||||
for (Wire w : newWires)
|
||||
wires.add(new Wire(w.p1, w.p2));
|
||||
wires.add(new LocalWire(w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(Circuit circuit) {
|
||||
ArrayList<Wire> wl = new ArrayList<>(wires.size());
|
||||
for (Wire w : wires)
|
||||
wl.add(new Wire(w));
|
||||
for (LocalWire w : wires)
|
||||
wl.add(new Wire(w.p1, w.p2));
|
||||
circuit.add(wl);
|
||||
}
|
||||
|
||||
@ -43,4 +63,13 @@ public class ModifyInsertWires implements Modification<Circuit> {
|
||||
return Lang.get("mod_insertedWire");
|
||||
}
|
||||
|
||||
private static final class LocalWire {
|
||||
private final Vector p1;
|
||||
private final Vector p2;
|
||||
|
||||
private LocalWire(Wire w) {
|
||||
this.p1 = w.p1;
|
||||
this.p2 = w.p2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user