Serialization problem

Hi,
When I drag and drop an object from a palette to a view. This object is serialized so its layer is serialized too with all the objects in the layer.
Is it possible to prevent this behaviour and serialized only the dragged object ?
Alexandre Pique

Well, that’s an interesting revelation.
In a drag-and-drop, the view’s JGoSelection is the Transferable data that is transferred. That Transferable is serialized. (I have never understood why it is serialized even when both the source and the target are in the same Window.)
The selected objects have a reference to the JGoLayer that they are each in. So when a JGoObject is serialized, the (non-transient) reference to the JGoLayer causes the layer to be serialized too.
Unfortunately, it’s important to have the reference from the JGoObject to the JGoLayer, since if the source view has objects in different layers, you want to drop the copied objects into the corresponding layers in the destination view.
Copy and paste don’t have this problem, since JGoView.copyToClipboard makes a copy of the document and a copy of only the needed objects.
I guess a solution would be to change JGoView.dragGestureRecognized to do the same thing that copyToClipboard does. You can try modifying the definition in JGoView.java:
/** This implements the default drag gesture listener, starting a drag. */
public void dragGestureRecognized(DragGestureEvent e)
{
try {
Cursor cursor = DragSource.DefaultMoveDrop;
if (getState() == MouseStateResize ||
getState() == MouseStateCreateLink ||
getState() == MouseStateCreateLinkFrom) {
cursor = getCursor();
}
// Instead of passing a JGoSelection as the Transferable, pass a JGoDocument
JGoDocument thisdoc = getDocument();
Class docclass = thisdoc.getClass();
JGoDocument clipdoc = (JGoDocument)docclass.newInstance();
// make sure the clipdoc has the same layers as the view’s document,
// but not the same document objects in those layers
clipdoc.copyLayersFrom(thisdoc);
clipdoc.copyFromCollection(getSelection());
if (DragSource.isDragImageSupported()) {
if (myDragImage == null) {
myDragImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
}
e.startDrag(cursor, myDragImage, new Point(0, 0), clipdoc, getCanvas());
} else {
e.startDrag(cursor, clipdoc, getCanvas());
}
} catch (Exception x) {
x.printStackTrace();
}
}

Something similar would also need to be done for SWT.
Please tell me if this works for you.