Methods Summary |
---|
public void | dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
System.out.println ("dragEnter");
|
public void | dragExit(java.awt.dnd.DropTargetEvent dte)
System.out.println ("dragExit");
|
public void | dragOver(java.awt.dnd.DropTargetDragEvent dtde)
System.out.println ("dragOver");
|
public void | drop(java.awt.dnd.DropTargetDropEvent dtde)
System.out.println ("drop");
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
Transferable trans = dtde.getTransferable();
System.out.println ("Flavors:");
dumpDataFlavors (trans);
boolean gotData = false;
try {
// try to get an image
if (trans.isDataFlavorSupported (DataFlavor.imageFlavor)) {
System.out.println ("image flavor is supported");
Image img = (Image) trans.getTransferData (DataFlavor.imageFlavor);
showImageInNewFrame (img);
gotData = true;
} else if (trans.isDataFlavorSupported (
DataFlavor.javaFileListFlavor)) {
System.out.println ("javaFileList is supported");
java.util.List list = (java.util.List)
trans.getTransferData (DataFlavor.javaFileListFlavor);
ListIterator it = list.listIterator();
while (it.hasNext()) {
File f = (File) it.next();
ImageIcon icon = new ImageIcon (f.getAbsolutePath());
showImageInNewFrame (icon);
}
gotData = true;
} else if (trans.isDataFlavorSupported (uriListFlavor)) {
System.out.println ("uri-list flavor is supported");
String uris = (String)
trans.getTransferData (uriListFlavor);
// url-lists are defined by rfc 2483 as crlf-delimited
StringTokenizer izer = new StringTokenizer (uris, "\r\n");
while (izer.hasMoreTokens ()) {
String uri = izer.nextToken();
System.out.println (uri);
ImageIcon icon = new ImageIcon (uri);
showImageInNewFrame (icon);
}
gotData = true;
} else if (trans.isDataFlavorSupported (urlFlavor)) {
System.out.println ("url flavor is supported");
URL url = (URL) trans.getTransferData (urlFlavor);
System.out.println (url.toString());
ImageIcon icon = new ImageIcon (url);
showImageInNewFrame (icon);
gotData = true;
} else if (trans.isDataFlavorSupported (macPictStreamFlavor)) {
System.out.println ("mac pict stream flavor is supported");
InputStream in =
(InputStream) trans.getTransferData (macPictStreamFlavor);
// for the benefit of the non-mac crowd, this is
// done with reflection. directly, it would be:
// Image img = QTJPictHelper.pictStreamToJavaImage (in);
Class qtjphClass = Class.forName ("QTJPictHelper");
Class[] methodParamTypes = { java.io.InputStream.class };
Method method =
qtjphClass.getDeclaredMethod ("pictStreamToJavaImage",
methodParamTypes);
InputStream[] methodParams = { in };
Image img = (Image) method.invoke (null, methodParams);
showImageInNewFrame (img);
gotData = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println ("gotData is " + gotData);
dtde.dropComplete (gotData);
}
|
public void | dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
System.out.println ("dropActionChanged");
|
private void | dumpDataFlavors(java.awt.datatransfer.Transferable trans)
System.out.println ("Flavors:");
DataFlavor[] flavors = trans.getTransferDataFlavors();
for (int i=0; i<flavors.length; i++) {
System.out.println ("*** " + i + ": " + flavors[i]);
}
|
public static void | main(java.lang.String[] args)
JFrame frame = new JFrame ("Image DropTarget Demo");
ImageDropTargetDemo demoPanel = new ImageDropTargetDemo();
frame.getContentPane().add (demoPanel);
frame.pack();
frame.setVisible(true);
|
public void | showImageInNewFrame(javax.swing.ImageIcon icon)
JFrame frame = new JFrame();
frame.getContentPane().add (new JLabel (icon));
frame.pack();
frame.setVisible(true);
|
public void | showImageInNewFrame(java.awt.Image image)
showImageInNewFrame (new ImageIcon (image));
|