Use javaJVMLocalObjectMimeType for local DnD and serialization for external drop

I am working on a component in which smaller components are stacked. The user should be able to reorder these components using drag and drop. I did this job by executing TransferHandler, which accepts the local reference DataFlavor( javaJVMLocalObjectMimeType) of the underlying data models. It works great.

Now I would also like to launch my application a second time and be able to drag and drop my components from one application to another. In this case, I want to associate the necessary data of the drag source with the serializable object to restore the object in the drop application and use the serializable DataFlavor for this. I do not want to use object serialization in both situations.

How can I decide if my drag and drop operation was initiated in the same JVM so that I can decide to use an object reference or a serialized version of the data. The official Swing DnD documentation mentions that you can mix local and serialized flavors, but it does not talk about how to best use this.

Edit

This is how I create a fragrance in my DataModelTransferable

public static DataFlavor localFlavor;

static {
    try {
        localFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=\"" +  ArrayList.class.getName() + "\"");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
...
@Override
public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] { localFlavor };
}

And in mine TransferHandlerI do it

@Override
public boolean canImport(TransferSupport support) {
    return support.isDataFlavorSupported(DataModelTransferable.localFlavor);
}

, , , , java.io.IOException: Owner failed to convert data drop a java.io.NotSerializableException: alignment.model.DataModel . , .

ArrayList, , fyi.

+3
2

, . DataModelList ArrayList DataModels, Serializable :

localFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=\"" +  DataModelList.class.getName() + "\"");

, JVM.

, , Serializable. - , , .

+1

JVM. , Transferable " ", " Dataflavor".

0

All Articles