This question has an example of IExternalizable usage.
You have a number of UIComponents descendants, perhaps they even share a parent. So, you take each of the classes and write that they implements IExternalizable
, and write a coherent writeExternal
and readExternal
pair of methods, saving only the required properties (x, y, type, whatever else. Say a resistor, you save its x, y, type as enum or String, probably rotation, and that's all. When you do a readExternal
implementation, you read all the values in the same order you wrote them, and then reconstruct anything and everything within the object from the values you read. Anything external to the object should be restored by its parent, which will write a set of these objects (resistors, inductors, transistors etc) one by one, then will addChild()
them at reading. This is a complicated enough structure, but will work if done properly.
Yes, all this is able to be stored inside a SharedObject, with its natively available methods. Take care though, you will need to call a registerClassAlias
method for all classes involved in IExternalizable implementation.