I've got a Swing application which makes a lot of use of cut & paste operations. I use the standard Toolkit, Clipboard, DataFlavor, etc classes. Throughtout various parts of the application, users might be cutting & pasting text and images, as well visual layout widget that are of a custom type that I created (the application is sort of a design/layout application). Obviously, I want to user's experience to be seamless; e.g. if the user copies text and then pastes into the app, text is pasted; if they copy an image from somewhere and then paste into the app, and image is pasted; and if they copy a layout widget from the app and then paste, a duplicate layout widget is pasted. Whatever's on the clipboard gets pasted.
So my problem is that I think I'm handling the latter case, the custom layout widget, incorrectly. I've created a custom Transferable, WidgetListSelection, whose sole supported DataFlavor is DataFlavor.javaFileListFlavor. When the user selects one or more widgets and then copies them, a WidgetListSelection containing a List of the selected Widgets is placed on the clipboard.
This actually worked, until OX 10.5, Leopard, came out for the Mac; now it doesn't. I haven't found any bug reports related to cut/paste on Leopard, and I guess I'm at the very least misusing DataFlavor.javaFileListFlavor. So I figure it's my bad, not Leopard's.
My thought for a solution was just to place the copied widgets into a List somewhere (not on the Clipboard), and then place something like a unique
String on the Clipboard itself. Then when the user pastes, I check the Clipboard contents for that unique String. If I find it, then I grab the Widgets from that List and paste them.
Obviously, there are a few things that smell wrong about that approach. But, what would be the right approach? Anyone have any experience in copying/pasting custom object types that aren't text or images using the Clipboard? I should clarify that these objects have no relevance outside of my application, but I want to use the Clipboard mechanism to keep things seamless for the user.