Completely changed the structure and switched to Eclipse Plugin.
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / ViewModel.java
index 7f9b113..445810a 100644 (file)
@@ -8,7 +8,7 @@ import java.util.function.Consumer;
 import net.mograsim.logic.ui.model.components.GUIComponent;
 import net.mograsim.logic.ui.model.wires.GUIWire;
 
-public class ViewModel
+public class ViewModel implements Visitable
 {
        private final List<GUIComponent> components;
        private final List<GUIComponent> componentsUnmodifiable;
@@ -23,7 +23,7 @@ public class ViewModel
 
        private final Runnable redrawListenerForSubcomponents;
 
-       public ViewModel()
+       protected ViewModel()
        {
                components = new ArrayList<>();
                componentsUnmodifiable = Collections.unmodifiableList(components);
@@ -43,7 +43,7 @@ public class ViewModel
         * Adds the given component to the list of components and calls all componentAddedListeners. Don't call this method from application
         * code as it is automatically called in GUIComponent::new.
         */
-       public void componentCreated(GUIComponent component)
+       protected void componentCreated(GUIComponent component)
        {
                if (components.contains(component))
                        throw new IllegalStateException("Don't add the same component twice!");
@@ -57,7 +57,7 @@ public class ViewModel
         * Removes the given component from the list of components and calls all componentRemovedListeners. Don't call this method from
         * application code as it is automatically called in GUIComponent::destroy.
         */
-       public void componentDestroyed(GUIComponent component)
+       protected void componentDestroyed(GUIComponent component)
        {
                if (!components.contains(component))
                        throw new IllegalStateException("Don't remove the same component twice!");
@@ -68,10 +68,10 @@ public class ViewModel
        }
 
        /**
-        * Adds the given component to the list of components and calls all componentAddedListeners. Don't call this method from application
-        * code as it is automatically called in GUIComponent::new.
+        * Adds the given wire to the list of wires and calls all wireAddedListeners. Don't call this method from application code as it is
+        * automatically called in GUIWire::new.
         */
-       public void wireCreated(GUIWire wire)
+       protected void wireCreated(GUIWire wire)
        {
                if (wires.contains(wire))
                        throw new IllegalStateException("Don't add the same wire twice!");
@@ -82,10 +82,10 @@ public class ViewModel
        }
 
        /**
-        * Removes the given component from the list of components and calls all componentRemovedListeners. Don't call this method from
-        * application code as it is automatically called in GUIComponent::destroy.
+        * Removes the given wire from the list of wires and calls all wireRemovedListeners. Don't call this method from application code as it
+        * is automatically called in GUIWire::destroy.
         */
-       public void wireDestroyed(GUIWire wire)
+       protected void wireDestroyed(GUIWire wire)
        {
                if (!wires.contains(wire))
                        throw new IllegalStateException("Don't remove the same wire twice!");
@@ -105,10 +105,11 @@ public class ViewModel
                return wiresUnmodifiable;
        }
 
-//     public void requestRedraw()
-//     {
-//             callRedrawListeners();
-//     }
+       @Override
+       public void accept(ModelVisitor mv)
+       {
+               mv.visit(this);
+       }
 
        // @formatter:off
        public void addComponentAddedListener     (Consumer<? super GUIComponent> listener) {componentAddedListeners  .add   (listener);}