X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2FViewModel.java;h=68cc489f06accd934d3f8883be94f3fde4f46d21;hb=6f717d2b76148b0d49c342f9ab937ba87d81dddb;hp=193813297d3584912290051a5875652a0a7a1647;hpb=b5d8c2d71e27350ea7c9314e40df5bb0584271cd;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModel.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModel.java index 19381329..68cc489f 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModel.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModel.java @@ -14,8 +14,8 @@ public class ViewModel { private final Map components; private final Map componentsUnmodifiable; - private final List wires; - private final List wiresUnmodifiable; + private final Map wires; + private final Map wiresUnmodifiable; private final List> componentAddedListeners; private final List> componentRemovedListeners; @@ -29,8 +29,8 @@ public class ViewModel { components = new HashMap<>(); componentsUnmodifiable = Collections.unmodifiableMap(components); - wires = new ArrayList<>(); - wiresUnmodifiable = Collections.unmodifiableList(wires); + wires = new HashMap<>(); + wiresUnmodifiable = Collections.unmodifiableMap(wires); componentAddedListeners = new ArrayList<>(); componentRemovedListeners = new ArrayList<>(); @@ -75,9 +75,9 @@ public class ViewModel */ protected void wireCreated(GUIWire wire) { - if (wires.contains(wire)) + if (wires.containsKey(wire.name)) throw new IllegalStateException("Don't add the same wire twice!"); - wires.add(wire); + wires.put(wire.name, wire); callWireAddedListeners(wire); wire.addRedrawListener(redrawListenerForSubcomponents); callRedrawListeners(); @@ -89,9 +89,9 @@ public class ViewModel */ protected void wireDestroyed(GUIWire wire) { - if (!wires.contains(wire)) + if (!wires.containsKey(wire.name)) throw new IllegalStateException("Don't remove the same wire twice!"); - wires.remove(wire); + wires.remove(wire.name); callWireRemovedListeners(wire); wire.removeRedrawListener(redrawListenerForSubcomponents); callRedrawListeners(); @@ -102,7 +102,7 @@ public class ViewModel return componentsUnmodifiable; } - public List getWires() + public Map getWiresByName() { return wiresUnmodifiable; }