Optional<ModelComponent> o;
while ((o = submodelModifiable.getComponentsByName().values().stream()
- .filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
+ .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
submodelModifiable.destroyComponent(o.get());
- tempModel.getComponentsByName().values().stream().filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+ tempModel.getComponentsByName().values().stream().filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
.forEach(c -> IndirectModelComponentCreator
- .createComponent(submodelModifiable, c.getIDForSerializing(iP), c.getParamsForSerializingJSON(iP), c.name)
+ .createComponent(submodelModifiable, c.getIDForSerializing(iP), c.getParamsForSerializingJSON(iP), c.getName())
.moveTo(c.getPosX(), c.getPosY()));
for (ModelWire w : tempModel.getWiresByName().values())
createWire(Function.identity(), submodelModifiable, w);
private static Pin getRemappedPin(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
Pin pin)
{
- return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.name)).getPin(pin.name);
+ return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.getName())).getPin(pin.name);
}
private static int compareStringsWithIntegers(String a, String b)
private void addComponentSelectorItems(List<ModelComponent> componentsByItemIndex, String base, Combo componentSelector,
LogicModel model)
{
- model.getComponentsByName().values().stream().sorted((c1, c2) -> c1.name.compareTo(c2.name)).forEach(c ->
+ model.getComponentsByName().values().stream().sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(c ->
{
if (!(c instanceof ModelWireCrossPoint || c instanceof SubmodelInterface))
{
- String item = base + c.name;
+ String item = base + c.getName();
componentsByItemIndex.add(c);
componentSelector.add(item);
if (c instanceof SubmodelComponent)
*/
protected void componentCreated(ModelComponent component, Runnable destroyed)
{
- if (components.containsKey(component.name))
+ if (components.containsKey(component.getName()))
throw new IllegalStateException("Don't add the same component twice!");
- components.put(component.name, component);
- componentDestroyFunctions.put(component.name, destroyed);
+ components.put(component.getName(), component);
+ componentDestroyFunctions.put(component.getName(), destroyed);
callComponentAddedListeners(component);
requestRedraw();
}
*/
protected void destroyComponent(ModelComponent component)
{
- componentDestroyFunctions.get(component.name).run();
- if (!components.containsKey(component.name))
+ componentDestroyFunctions.get(component.getName()).run();
+ if (!components.containsKey(component.getName()))
throw new IllegalStateException("Don't remove the same component twice!");
- components.remove(component.name);
+ components.remove(component.getName());
callComponentRemovedListeners(component);
requestRedraw();
}
*/
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.<br>
+ * 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.
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);
/**
* Initializes this component. This method should be called exactly once in this component's constructor.<br>
- * Currently, this method only registers this component in the model.
+ * <ul>
+ * <li>If <code>{@link #name}==null</code>, sets {@link #name} to {@link LogicModelModifiable#getDefaultComponentName(ModelComponent)}.
+ * <li>Registers this component in the model.
+ * </ul>
*/
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.<br>
innerComponentParams.pos = new Point(innerComponent.getPosX(), innerComponent.getPosY());
innerComponentParams.id = innerComponent.getIDForSerializing(idParams);
innerComponentParams.params = innerComponent.getParamsForSerializingJSON(idParams);
- innerComponentParams.name = innerComponent.name;
+ innerComponentParams.name = innerComponent.getName();
i1++;
}
submodelParams.subComps = componentParams;
LegacyInnerPinParams pin1Params = new LegacyInnerPinParams(), pin2Params = new LegacyInnerPinParams();
pin1Params.pinName = innerWire.getPin1().name;
- pin1Params.compName = innerWire.getPin1().component.name;
+ pin1Params.compName = innerWire.getPin1().component.getName();
pin2Params.pinName = innerWire.getPin2().name;
- pin2Params.compName = innerWire.getPin2().component.name;
+ pin2Params.compName = innerWire.getPin2().component.getName();
innerWireParams.name = innerWire.name;
innerWireParams.pin1 = pin1Params;
innerWireParams.pin2 = pin2Params;
compParams.pos = new Point(component.getPosX(), component.getPosY());
compParams.id = component.getIDForSerializing(idParams);
compParams.params = component.getParamsForSerializingJSON(idParams);
- compParams.name = component.name;
+ compParams.name = component.getName();
}
modelParams.components = componentsParams.toArray(ComponentParams[]::new);
Arrays.sort(modelParams.components, Comparator.comparing(c -> c.name));
PinParams pin1Params = new PinParams(), pin2Params = new PinParams();
pin1Params.pinName = innerWire.getPin1().name;
- pin1Params.compName = innerWire.getPin1().component.name;
+ pin1Params.compName = innerWire.getPin1().component.getName();
pin2Params.pinName = innerWire.getPin2().name;
- pin2Params.compName = innerWire.getPin2().component.name;
+ pin2Params.compName = innerWire.getPin2().component.getName();
innerWireParams.name = innerWire.name;
innerWireParams.pin1 = pin1Params;
innerWireParams.pin2 = pin2Params;
{
if (delegateTarget == null)
this.delegateTarget = parentComponent;
- else if (parentComponent.submodel.getComponentsByName().get(delegateTarget.name) != delegateTarget)
+ else if (parentComponent.submodel.getComponentsByName().get(delegateTarget.getName()) != delegateTarget)
throw new IllegalArgumentException(
"Can only set components belonging to the submodel of the parent component of this handler as the delegate target");
this.delegateTarget = delegateTarget;
public DelegatingAtomicHighLevelStateHandlerParams getParamsForSerializing(IdentifyParams idParams)
{
DelegatingAtomicHighLevelStateHandlerParams params = new DelegatingAtomicHighLevelStateHandlerParams();
- params.delegateTarget = delegateTarget.name;
+ params.delegateTarget = delegateTarget.getName();
params.subStateID = subStateID;
return params;
}
{
if (delegateTarget == null)
this.delegateTarget = parentComponent;
- else if (parentComponent.submodel.getComponentsByName().get(delegateTarget.name) != delegateTarget)
+ else if (parentComponent.submodel.getComponentsByName().get(delegateTarget.getName()) != delegateTarget)
throw new IllegalArgumentException(
"Can only set components belonging to the submodel of the parent component of this handler as the delegate target");
this.delegateTarget = delegateTarget;
public DelegatingSubcomponentHighLevelStateHandlerParams getParamsForSerializing(IdentifyParams idParams)
{
DelegatingSubcomponentHighLevelStateHandlerParams params = new DelegatingSubcomponentHighLevelStateHandlerParams();
- params.delegateTarget = delegateTarget.name;
+ params.delegateTarget = delegateTarget.getName();
params.prefix = prefix;
return params;
}