Editor settings updated
[Mograsim.git] / net.mograsim.logic.model.editor / src / net / mograsim / logic / model / editor / handles / HandleManager.java
index f999c96..e4fb314 100644 (file)
@@ -89,7 +89,7 @@ public class HandleManager
                        comps.remove(interfaceComp);
                        registerInterfaceComponent(interfaceComp);
                        comps.forEach(c -> registerComponent(c));
-                       
+
                        model.getWires().forEach(w -> registerWire(w));
                        addHandle(cornerHandle = new CornerHandle(editor.toBeEdited));
                }
@@ -116,24 +116,17 @@ public class HandleManager
        {
                wire.addPathChangedListener((w, diff) ->
                {
-                       if(diff != 0)
+                       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);
                                }
-                               else
-                               {
-                                       for(int i = 0; i > diff; i--)
-                                       {
-                                               removeLastWirePointHandle(wire);
-                                       }
-                               }
-                               
+
                                List<WirePointHandle> 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);
                                }
@@ -183,8 +176,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);
@@ -203,11 +196,11 @@ public class HandleManager
                List<WirePointHandle> wireHandles = pointHandlesPerWire.get(w);
                WirePointHandle h;
                if (wireHandles != null)
-                       wireHandles.add(h = new WirePointHandle(w, wireHandles.size()));
+                       wireHandles.add(h = new WirePointHandle(this, w, wireHandles.size()));
                else
                {
                        wireHandles = new ArrayList<>();
-                       h = new WirePointHandle(w, 0);
+                       h = new WirePointHandle(this, w, 0);
                        wireHandles.add(h);
                        pointHandlesPerWire.put(h.parent, wireHandles);
                }
@@ -215,16 +208,18 @@ public class HandleManager
                addHandle(h);
        }
 
-       private void removeLastWirePointHandle(GUIWire owner)
+       void destroyWirePointHandle(GUIWire owner, WirePointHandle h)
        {
-               Handle h = pointHandlesPerWire.get(owner).remove(0);
-               wirePointHandles.remove(h);
+               List<WirePointHandle> 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 ->
                {
@@ -275,7 +270,7 @@ public class HandleManager
        {
                return handlePerWire.get(parent);
        }
-       
+
        public Handle getInterfacePinHandle(Pin p)
        {
                return handlePerInterfacePin.get(p);
@@ -304,7 +299,7 @@ public class HandleManager
        {
                return Collections.unmodifiableCollection(handlePerPin.values());
        }
-       
+
        /**
         * @return An unmodifiable view of all registered {@link InterfacePinHandle}s
         */
@@ -345,8 +340,8 @@ public class HandleManager
                        if (!click(handlePerPin.values(), clicked, entryState, stateMask))
                                if (!click(handlePerInterfacePin.values(), clicked, entryState, stateMask))
                                        if (!click(getWirePointHandles(), clicked, entryState, stateMask))
-                                               if (!click(handlePerComp.values(), clicked, entryState, stateMask))
-                                                       if (!click(getWireHandles(), clicked, entryState, stateMask))
+                                               if (!click(getWireHandles(), clicked, entryState, stateMask))
+                                                       if (!click(handlePerComp.values(), clicked, entryState, stateMask))
                                                                entryState.clickedEmpty(clicked, stateMask);
                entryState.clicked(clicked, stateMask);
        }