X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2FModelComponent.java;h=9171ee839b7a82061619ae66e205b47045079231;hb=e5460cbb1f4ae06479a92d4ab483b08e8e01e4a6;hp=6853e382ccf44083ff906ae834d50e7be313c930;hpb=93b398d6271a538a2a4c9f4de07a3b4a8a2a7fd4;p=Mograsim.git
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java
index 6853e382..9171ee83 100644
--- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java
+++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java
@@ -9,7 +9,7 @@ import java.util.function.Consumer;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.wires.Pin;
import net.mograsim.logic.model.serializing.IdentifyParams;
import net.mograsim.logic.model.serializing.JSONSerializable;
@@ -17,7 +17,7 @@ import net.mograsim.logic.model.snippets.HighLevelStateHandler;
/**
* The base class for all model components.
- * A ModelComponent
has a reference to the ViewModel it belongs to.
+ * A ModelComponent
has a reference to the LogicModel it belongs to.
* A ModelComponent
has a name. This name is unique in the model the ModelComponent
belongs to.
* A ModelComponent
has a position and size. The size can only be modified by subclasses.
*
@@ -28,11 +28,12 @@ public abstract class ModelComponent implements JSONSerializable
/**
* The model this component is a part of.
*/
- protected final ViewModelModifiable model;
+ protected final LogicModelModifiable model;
/**
- * The name of this component. Is unique for all components in its model.
+ * The name of this component. Is unique for all components in its model.
+ * Does never change, but can't be final since it is set in {@link #init()}.
*/
- public final String name;
+ private String name;
private final Rectangle bounds;
/**
* The list of all pins of this component by name.
@@ -52,10 +53,21 @@ public abstract class ModelComponent implements JSONSerializable
// creation and destruction
- public ModelComponent(ViewModelModifiable model, String name)
+ public ModelComponent(LogicModelModifiable model, String name)
+ {
+ this(model, name, true);
+ }
+
+ /**
+ * Creates a new {@link ModelComponent} and, if callInit
, initializes the component (See {@link #init()}).
+ * If callInit==false
, make sure to call {@link #init()}!
+ *
+ * @author Daniel Kirschten
+ */
+ protected ModelComponent(LogicModelModifiable model, String name, boolean callInit)
{
this.model = model;
- this.name = name == null ? model.getDefaultComponentName(this) : name;
+ this.name = name;
this.bounds = new Rectangle(0, 0, 0, 0);
this.pinsByName = new HashMap<>();
this.pinsUnmodifiable = Collections.unmodifiableMap(pinsByName);
@@ -65,21 +77,41 @@ public abstract class ModelComponent implements JSONSerializable
this.pinAddedListeners = new ArrayList<>();
this.pinRemovedListeners = new ArrayList<>();
- // TODO this will crash the high level state debug shell because submodel is not yet set.
- // The same problem exists in ViewModelModifiable.getDefaultComponentName; see there
+ if (callInit)
+ init();
+ }
+
+ /**
+ * Initializes this component. This method should be called exactly once in this component's constructor.
+ *
{@link #name}==null
, sets {@link #name} to {@link LogicModelModifiable#getDefaultComponentName(ModelComponent)}.
+ *