Drag-n-drop - 1.4 stylee

This is a bit of a long-shot, but is anyone using 1.4 dnd? Having fought the evil monster that was pre-1.4 dnd on several occasions, and now with a semi-working 1.4 version I can attest that it’s much better (from a clarity-of-API-design viewpoint), but the tutorial is still rather poor.

It still suffers from the old dnd problem that some of the methods have almost no apparent purpose, and others you find yourself using but you’ve no idea why. Sooner or later, it kind of works, but you no longer know how :).

I’ve used it for dragging files from the OS to my app. That seemed simple enough.

I also used it in 1.3 for a small chess game. As you say it was a bit of a mystery in those days. I did get it to work, and it still works in 1.4… but I don’t think it’s ‘right’.

Well, a day of fiddling has shown that it is partially broken in linux at least. My earlier scouring of Sun’s forums showed plenty of Windows users who apparently had bad problems as well, and responses along the lines of “…and this bit won’t work at all if you’re using Windows…” etc.

It mostly works, but e.g.

[] you cannot DRAG from swing components, especially e.g. JTree, because Sun hasn’t fully rationalized the competing DragGesture and MouseMotionListener stuff (apparently). This manifest as “you MUST select the item you want to drag, then let go of the button, then drag it” (paraphrased from Sun’s tutorials…)
[] Approx 1 time in 4 nothing happens (no exceptions, no errors, nothing) when you drop inside a Jtree. Try again straight away and it Just Works (or you may have to try a few times if you’re really unlucky). This - unsurprisingly - made my initial dev bloody difficult :).
[
] Lots of “fun” trying to alter the cursors; allegedly on windows you still have to explicitly null the cursor before supplying a new one, and other shenanigans, although I haven’t confirmed this personally.

…but the “core” aspects seem to work fine. Presumably there’s a load of bugs extant on 1.4.x for dnd, so if they get (got) fixed for 1.5, all will be well. If not, it’s workable but looks darned shoddy :(.

Sigh. What with also trying to extract FileInputStream’s directly from a JAR it’s been a trying day (I tried to do it without using the URL stream classes because they irritate me; unfortunately URL is not compatible with URI in any way (the other way around, yes, although this is counter-intuitive), so you can’t send a resource URL to a File constructor.)

I’ve used DnD for two paint programs, never had problems with either of them, using Swing and 1.4.2. I thought the implementation was fairly straightforward. Although I’d have to refer to what I did as I don’t have this stuff memorized :slight_smile: Also my drag and drop needs were simple, pretty much just dragging one palette entry to another, or dragging around tiles.