X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2Fhandles%2FHandleManager.java;h=ee755f92b935aca80f9fdb3576d5375e4b2d0bb1;hb=d43a60248809b835d63a7f8cc50a3346902e790e;hp=c5e06a54cc7bb2d634903a9a647fafcb02b140dc;hpb=cc6e329dc014542eb743833ef865b9d59047abbb;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java index c5e06a54..ee755f92 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java @@ -90,8 +90,8 @@ public class HandleManager comps.remove(interfaceComp); registerInterfaceComponent(interfaceComp); comps.forEach(c -> registerComponent(c)); - - model.getWires().forEach(w -> registerWire(w)); + + model.getWiresByName().values().forEach(w -> registerWire(w)); addHandle(cornerHandle = new CornerHandle(editor.toBeEdited)); } } @@ -121,18 +121,18 @@ public class HandleManager { Point[] newPath = w.getPath(); int newLength = newPath == null ? 0 : newPath.length; - int diff = oldLength.getAndSet(newLength) - newLength; - if(diff != 0) + int diff = newLength - oldLength.getAndSet(newLength); + if (diff != 0) { - if(diff > 0) + if (diff > 0) { - for(int i = 0; i < diff; i++) + for (int i = 0; i < diff; i++) addWirePointHandle(w); } - + List wpHandles = pointHandlesPerWire.get(w); int size = wpHandles.size(); - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) { wpHandles.get(i).setIndex(i); } @@ -182,8 +182,8 @@ public class HandleManager private void addInterfacePinHandle(Pin p) { - //The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called - //editor.toBeEdited.getSubmodelMovablePins().get(p.name); + // The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called + // editor.toBeEdited.getSubmodelMovablePins().get(p.name); MovablePin pM = (MovablePin) p; InterfacePinHandle h = new InterfacePinHandle(pM, editor.toBeEdited); handlePerInterfacePin.put(pM, h); @@ -213,19 +213,22 @@ public class HandleManager this.wirePointHandles.add(h); addHandle(h); } - + void destroyWirePointHandle(GUIWire owner, WirePointHandle h) { - List handles = pointHandlesPerWire.get(owner); - int pointIndex = handles.indexOf(h); - handles.remove(pointIndex); - removeHandle(h); - owner.removePathPoint(pointIndex); + if (pointHandlesPerWire.containsKey(owner)) + { + List handles = pointHandlesPerWire.get(owner); + int pointIndex = handles.indexOf(h); + handles.remove(pointIndex); + removeHandle(h); + owner.removePathPoint(pointIndex); + } } private void removeWirePointHandles(GUIWire owner) { - if(!pointHandlesPerWire.containsKey(owner)) + if (!pointHandlesPerWire.containsKey(owner)) return; pointHandlesPerWire.get(owner).forEach(h -> { @@ -276,7 +279,7 @@ public class HandleManager { return handlePerWire.get(parent); } - + public Handle getInterfacePinHandle(Pin p) { return handlePerInterfacePin.get(p); @@ -305,7 +308,7 @@ public class HandleManager { return Collections.unmodifiableCollection(handlePerPin.values()); } - + /** * @return An unmodifiable view of all registered {@link InterfacePinHandle}s */ @@ -348,11 +351,11 @@ public class HandleManager if (!click(getWirePointHandles(), clicked, entryState, stateMask)) if (!click(getWireHandles(), clicked, entryState, stateMask)) if (!click(handlePerComp.values(), clicked, entryState, stateMask)) - entryState.clickedEmpty(clicked, stateMask); + entryState.clickedEmpty(clicked, stateMask); entryState.clicked(clicked, stateMask); } - private boolean click(Collection handles, Point clicked, EditorState state, int stateMask) + private static boolean click(Collection handles, Point clicked, EditorState state, int stateMask) { for (Handle h : handles) if (h.click(clicked.x, clicked.y, stateMask, state))