lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
on:
2003-04-10 13:20:02 » |
|
Ok, so I have this program ( http://sourceforge.net/projects/javapsionlink/) that for the purposes of this query can be considered equivalent to an FTP program. So far I have managed to get it so you can drag files into the window and get them uploaded. Easy as the files already exist (in java.io.File terms). My question is how to go about the drag from the window? In this case the files (in the java.io.File sense) don't exist. Has anyone worked out how to do this kind of thing? The best lead I found was about "deferred" drag'n'drop, but that reckoned it wasn't possible in java. cheers, John
|
|
|
|
leknor
Full Member   Posts: 218
ROCK!!!
|
 |
«
Reply #1 on:
2003-04-10 17:12:55 » |
|
I'm pulling this outta my butt and I may be way off base but it's an idea.
What if you used a URL or URI to represent files, I'm not gonna claim to understand the difference. They should be abstract enough to handle both locations and I think you can add new protocol handlers at runtime somehow.
|
|
|
|
|
jbanes
JGO Neuromancer     Posts: 1178
"Java Games? Incredible! Mr. Incredible, that is!"
|
 |
«
Reply #2 on:
2003-04-11 09:31:10 » |
|
If I understand correctly, a URL is global (find it anywhere, anytime) while a URI is contextual (i.e. /usr/local/myfile).
|
|
|
|
Games published by our own members! Go get 'em!
|
|
lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
Reply #3 on:
2003-04-11 12:07:31 » |
|
In principal I see what you mean. However how would the OS know how to get at the files? The url/uri would hve to be something like:
psion://c/documents/myfile.txt
But seeing as the only program running that undersood that would be mine, how can it then get called back?
I know on the mac you have to have a "promised hfs" ostype, which basically says I promise to put a file where you ask me to, but there doesn't seem to be anything like that in teh dnd api.
Is this another missing feature, such as irregular windows, or has anyone got this to work?
|
|
|
|
javatypo
Full Member   Posts: 143
|
 |
«
Reply #4 on:
2003-04-11 15:14:43 » |
|
interesting question.
but i dont think that many applications do that.
i know u can drag and drop files into photoshop.. but i dont think it goes the other way.
of course your using a list right? do u know if its possible in c++? or c?
|
|
|
|
|
leknor
Full Member   Posts: 218
ROCK!!!
|
 |
«
Reply #5 on:
2003-04-11 15:26:54 » |
|
However how would the OS know how to get at the files? I missunderstood what you were trying to do. I thought all drag-n-dropping was happening within the application.
|
|
|
|
|
javatypo
Full Member   Posts: 143
|
 |
«
Reply #6 on:
2003-04-12 10:13:09 » |
|
if u can find out if its doable in C++, then it is probably dobale in java.. just not in the current api
|
|
|
|
|
lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
Reply #7 on:
2003-04-14 11:47:08 » |
|
I know it is possible in C++, as I have dragged files out of ftp programs before. I also know that you can use the file list flavor when dragging out, as long as the files already exist. With that in mind it _might_ be possible to fake it: somehow work out when the user has dragged and dropped the files, and download them to a temporary directory, _before_ the OS tries to move them. I guess some experimentation may be needed. But I was just wondering if anyone had had any success before I attempted to re-invent he wheel.
cheers, John
|
|
|
|
lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
Reply #8 on:
2003-05-23 14:07:49 » |
|
Ooh ooh. Whilst googling for the elusive drag'n'drop of files that don't yet exist answer, I have thought up a possible (slightly hacked) solution. As said earlier we effectively need to provide a URL to the file to download and let the OS decide how/when to grab the file pointed to by the URL. So if the app runs a webserver and the urls are specified for that webserver (e.g. http://127.0.0.1/c/documents/myfile.txt ) then it might actually work. I think I shall have to see if that can/will work and if there is another way that does not involve networking, as it's really just a hack to make a call-back from the OS. I guess under linux/unix there would be named pipes and/or domain sockets. Anyway, just wanted to get this written down, it might be another clue for someone else to figure out the right way (tm) of doing it.
|
|
|
|
lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
Reply #9 on:
2003-05-25 09:23:31 » |
|
Ok, the URL thing looks like it might have been a red herring. It seems to only allow you to place a shortcut/link/alias to that URL. Instead I went down the platform specific route. With the help of Appl technote TN1085 (Using the Drag Manager to Interact With and Manipulate File System Entities): http://developer.apple.com/technotes/tn/tn1085.htmlWith that and that fact the java<->native code interaction on the mac is dead easy (no C glue code is needed) I was eventually able to figure out how to the get directory that a drop occurs in, therefore allowing me to copy the dragged files to the correct location. I had to use a couple of un-documented apple classes tho. Mainly to allow me to turn an FSSpec to a java.io.File. This code is for MacOS classic, but it may be possible to convert it to MacOS X easily - I can't say for definate as I don't have MacOS X yet. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
| import com.apple.mrj.datatransfer.*; import com.apple.mrj.dnd.*; import com.apple.mrj.*; import com.apple.mrj.jdirect.*; import com.apple.mrj.macos.toolbox.AEDesc; import com.apple.mrj.macos.toolbox.FSSpec; import com.apple.mrj.macos.libraries.*; import java.awt.*; import java.net.*; import java.io.*;
public class DragTest extends Frame implements DragLib, InterfaceLib { private final OSTypeFlavor kDragPromisedFlavor = new OSTypeFlavor( new MRJOSType( "fssP" ) ); private final OSTypeFlavor flavorTypePromisedHFS = new OSTypeFlavor( new MRJOSType( "phfs" ) ); private final MRJOSType typeAlias = new MRJOSType( "alis" ); private final MRJOSType typeFSS = new MRJOSType( "fss " ); public DragTest() { addMouseListener( new DragInit() ); } public native static short GetDropLocation( int theDrag, byte[] dropLocation ); public native static short AECoerceDesc( byte[] theAEDesc, int toType, byte[] result ); class PromiseHFSFlavor extends ByteArrayStruct { public PromiseHFSFlavor() { super( 14 ); } public void setFileType( MRJOSType type ) { setIntAt( 0, type.toInt() ); } public void setFileCreator( MRJOSType type ) { setIntAt( 4, type.toInt() ); } public void setFlags( int flags ) { setShortAt( 8, (short)flags ); } public void setPromisedFlavor( OSTypeFlavor flavor ) { setIntAt( 0, flavor.getOSType().toInt() ); } } class FSSpecHandle extends HandleStruct { public FSSpecHandle( int handle ) { super( handle ); } public short getVolumeRef() { return getShortAt( 0 ); } public int getParentID() { return getIntAt( 2 ); } public String getName() { byte[] bytes = getBytesAt( 6, 64 ); int len = 0xFF & bytes[ 0 ]; if ( len >= 64 ) throw new RuntimeException( "error in FSSpec name length" ); return new String( bytes, 1, len ); } public int getSize() { return 70; } } class DragInit extends DragInitiatorAdapter { public void dragGesture( DragInitiatorEvent e ) { System.out.println( e ); OutgoingDrag drag = e.getDrag(); try { Transfer trans = new Transfer(); PromiseHFSFlavor phfs = new PromiseHFSFlavor(); phfs.setFlags( 0 ); phfs.setPromisedFlavor( kDragPromisedFlavor ); trans.addFlavor( flavorTypePromisedHFS, phfs.getBytes() ); trans.addFlavor( kDragPromisedFlavor, new byte[ 0 ] ); drag.addItem( trans ); } catch( Exception ex ) { ex.printStackTrace(); } }
public void dragCompleted( DragInitiatorEvent e ) { OutgoingDrag drag = e.getDrag(); if ( !drag.isDropAccepted() ) return; int dragRef = drag.getRef(); AEDesc dropLocAlias = new AEDesc(); if ( GetDropLocation( dragRef, dropLocAlias.getByteArray() ) != 0 ) { return; } if ( dropLocAlias.getDescriptorType() != typeAlias.toInt() ) { System.err.println( "error descriptor not alis: " + new MRJOSType( dropLocAlias.getDescriptorType() ) ); return; } AEDesc dropLocFSS = new AEDesc(); if ( AECoerceDesc( dropLocAlias.getByteArray(), typeFSS.toInt(), dropLocFSS.getByteArray() ) != 0 ) { System.err.println( "error coercing to typeFSS" ); return; } int dataHandle = dropLocFSS.getDataHandle(); FSSpecHandle fss = new FSSpecHandle( dataHandle ); FSSpec fsspec = new FSSpec( fss ); File file = fsspec.toFile(); System.out.println( file ); dropLocAlias.dispose(); dropLocFSS.dispose(); if ( file.isDirectory() ) { File index = new File( file, "index.html" ); if ( !index.exists() ) { try { Writer writer = new OutputStreamWriter( new BufferedOutputStream( new FileOutputStream( index ) ) ); writer.write( "<html>\n<head><title>Test Drag</title></head>\n<body>Testing MRJ drag</body>\n</html>" ); writer.flush(); writer.close(); } catch( Exception ex ) { ex.printStackTrace(); } } } }
public void dragFailed( DragInitiatorEvent e ) { System.out.println( e ); } } public Dimension getPreferredSize() { return new Dimension( 320, 240 ); }
public static void main( String[] args ) { DragTest dt = new DragTest(); dt.pack(); dt.show(); } } |
|
|
|
|
Games published by our own members! Go get 'em!
|
|
swpalmer
JGO Kernel      Posts: 3438 Medals: 4
Where's the Kaboom?
|
 |
«
Reply #10 on:
2003-05-25 11:46:19 » |
|
Are you aware that JDirect does not work with Apple's 1.4.1 JRE? You will have to go with JNI like everyone else, or you could grab JNIDirect which some dude wrote to do some JDirect-like things via JNI.
|
|
|
|
lilspikey
JGO n00b  Posts: 27
Computers Stole My Social Skills
|
 |
«
Reply #11 on:
2003-05-25 12:07:36 » |
|
No didn't know that. I guess in MacOS X I'd have to do another version using the cocoa classes. The app I am doing this for tries to dynamically load stuff, so if it doesn't work under MacOS X, you just won't be able to drag files.
I though Apple had continued on with JDirect? I know that JDirect 3 was out, and that's based on JNI anyway. I guess you don't pay close enough attention untill you actually use an OS, and I can't afford to upgrade at the moment.
Anyway, I wish that sun would add this kind of functionality to "normal" java. It can't be that hard really, or are Windows, Linux, Unix etc a bit more ackward for that kind of thing?
|
|
|
|
CornedBee
JGO n00b  Posts: 4
Eat me!
|
 |
«
Reply #12 on:
2003-06-02 06:41:10 » |
|
I know of an FTP app where you can drag remote files to explorer. I guess it works using OLE DnD. This mechanism says that when initiating the drop the source app only says what type of thing gets dragged, so that another app can decide whether it wants the object. Only when the object is really dropped the source application must provide data, which gives it a chance to download the file and save it to a temporary location, where the target app then reads it from.
|
All the buzzt CornedBee :rolleyes:
|
|
|
|