JGoObject.copyObject

Hi

Please, i need a detailed sample for copying an Object in JGo.
None of my solutions work.

Where do i get the JGoCopyEnvironment?

Hope for help.

Greetings
Loki2

JGoObject.copyObject isn’t what you are supposed to call in order to make a copy of a JGoObject. It is called during the copying process, and should be overridden by subclasses that have added fields in order to properly initialize a newly allocated object with the appropriate values from the object being copied.
If you want to copy one or more JGoObjects and add them to a JGoDocument, call JGoDocument.copyFromCollection. Even when just copying a single JGoObject, you’ll want to use this mechanism, since it acts in two passes in order to handle references between the objects being copied, and your “single” JGoObject might actually contain all kinds of other JGoObjects referring to each other, and have references to “data” that need to be managed.
I suppose we should have some additional methods that make this process easier, such as a JGoDocument.addCopy(JGoObject) method and a JGoObject.copy() method. But they would just end up calling JGoDocument.copyFromCollection, or something similar, anyway.

[QUOTE=walter]If you want to copy one or more JGoObjects and add
them to a JGoDocument, call JGoDocument.copyFromCollection. Even
when just copying a single JGoObject, you’ll want to use this
mechanism, since it acts in two passes in order to handle references
between the objects being copied, and your “single” JGoObject might
actually contain all kinds of other JGoObjects referring to
each other, and have references to “data” that need to be
managed.[/quote]

Thanks for reply.
Do you have an example for JGoDocument.copyFromCollection? I’m sorry but i don’t understand how to copy a single JgoObject.

Thanks a lot.

Ah, yes, JGo doesn’t have a JGoCollection class that implements JGoObject[Simple]Collection without the overhead of JGoSelection or JGoDocument. Still, using a JGoDocument as the collection is easy and doesn’t waste much memory:
// the JGoObject to be copied, here an initialized JGoIconicNode
JGoIconicNode proto = new JGoIconicNode(“test”);
proto.getImage().loadImage(Demo1.class.getResource("star.gif "), false);
// allocate a collection and add the prototype
JGoDocument coll = new JGoDocument();
coll.addObjectAtTail(proto);
// copy the prototype into the view’s document
myView.getDocument().copyFromCollection(coll);