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=1ce42890e85c1a114bf647002d1aa2743ff9871a;hp=6fcfa9a1d3413e91ab85720f959ce447b1ddedde;hpb=618175d733f76185710e5072b916455f251436de;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 6fcfa9a1..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 @@ -30,9 +30,10 @@ public abstract class ModelComponent implements JSONSerializable */ 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. @@ -66,7 +67,7 @@ public abstract class ModelComponent implements JSONSerializable 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); @@ -82,13 +83,25 @@ public abstract class ModelComponent implements JSONSerializable /** * Initializes this component. This method should be called exactly once in this component's constructor.
- * Currently, this method only registers this component in the model. + * */ protected void init() { + if (name == null) + name = model.getDefaultComponentName(this); model.componentCreated(this, this::destroyed); } + // basic getters + + public String getName() + { + return name; + } + /** * Destroys this component. This method is called from {@link LogicModelModifiable#componentDestroyed(ModelComponent) * destroyComponent()} of the model this component is a part of.