use of java.awt.datatransfer.DataFlavor in project vcell by virtualcell.
the class VirtualFrapBatchRunFrame method drop.
public void drop(DropTargetDropEvent dtde) {
try {
// get the dropped object and try to figure out what it is
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
boolean bFileSelected = false;
if (flavors.length > 0) {
for (DataFlavor flavor : flavors) {
// Check for file lists specifically
if (flavor.isFlavorJavaFileListType()) {
// Accept copy and move drops...
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
@SuppressWarnings("unchecked") List<File> tData = (List<File>) tr.getTransferData(flavor);
for (Object dataElement : tData) {
if (dataElement instanceof File) {
File inputFile = (File) dataElement;
// check file extension, we'll open only .vfrap
if (VirtualFrapLoader.filter_vfbatch.accept(inputFile)) {
bFileSelected = true;
AsynchClientTask[] openTasks = open(inputFile);
ClientTaskDispatcher.dispatch(VirtualFrapBatchRunFrame.this, new Hashtable<String, Object>(), openTasks, true);
} else {
String msg = "Unkown file type of " + inputFile.getName() + ". Virtual FRAP Batchrun document names must have an extension of \'." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION + "\'.";
DialogUtils.showErrorDialog(this, msg);
return;
}
}
if (bFileSelected) {
break;
}
}
}
// If we made it this far, everything worked.
dtde.dropComplete(true);
return;
// other cases can be....
// else if (flavor.isFlavorSerializedObjectType()) {
// java object
// }
// else if (flavor.isRepresentationClassInputStream()) {
// input stream
// }
}
}
// the user must not have dropped a file list
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace(System.out);
dtde.rejectDrop();
}
}
use of java.awt.datatransfer.DataFlavor in project vcell by virtualcell.
the class DropTest2 method drop.
public void drop(DropTargetDropEvent dtde) {
try {
// Ok, get the dropped object and try to figure out what it is
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println("Possible flavor: " + flavors[i].getMimeType());
// Check for file lists specifically
if (flavors[i].isFlavorJavaFileListType()) {
// Great! Accept copy drops...
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
ta.setText("Successful file list drop.\n\n");
// And add the list of file names to our text area
@SuppressWarnings("unchecked") List<File> list = (List<File>) tr.getTransferData(flavors[i]);
for (int j = 0; j < list.size(); j++) {
ta.append(list.get(j) + "\n");
}
// If we made it this far, everything worked.
dtde.dropComplete(true);
return;
} else // Ok, is it another Java object?
if (flavors[i].isFlavorSerializedObjectType()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
ta.setText("Successful text drop.\n\n");
Object o = tr.getTransferData(flavors[i]);
ta.append("Object: " + o);
dtde.dropComplete(true);
return;
} else // How about an input stream?
if (flavors[i].isRepresentationClassInputStream()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
ta.setText("Successful text drop.\n\n");
ta.read(new InputStreamReader((InputStream) tr.getTransferData(flavors[i])), "from system clipboard");
dtde.dropComplete(true);
return;
}
}
// Hmm, the user must not have dropped a file list
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
dtde.rejectDrop();
}
}
use of java.awt.datatransfer.DataFlavor in project vcell by virtualcell.
the class VirtualFrapMainFrame method drop.
public void drop(DropTargetDropEvent dtde) {
try {
// get the dropped object and try to figure out what it is
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
boolean bFileSelected = false;
if (flavors.length > 0) {
for (DataFlavor flavor : flavors) {
// Check for file lists specifically
if (flavor.isFlavorJavaFileListType()) {
// Accept copy and move drops...
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
@SuppressWarnings("unchecked") List<File> tData = (List<File>) tr.getTransferData(flavor);
for (Object dataElement : tData) {
if (dataElement instanceof File) {
File inputFile = (File) dataElement;
// check file extension, we'll open only .vfrap
if (VirtualFrapLoader.filter_vfrap.accept(inputFile)) {
bFileSelected = true;
AsynchClientTask[] openTasks = frapStudyPanel.open(inputFile);
ClientTaskDispatcher.dispatch(VirtualFrapMainFrame.this, new Hashtable<String, Object>(), openTasks, true);
} else {
String msg = "Unkown file type of " + inputFile.getName() + ". Virtual FRAP document names must have an extension of \'." + VirtualFrapLoader.VFRAP_EXTENSION + "\'.";
DialogUtils.showErrorDialog(this, msg);
return;
}
}
if (bFileSelected) {
break;
}
}
}
// If we made it this far, everything worked.
dtde.dropComplete(true);
return;
// other cases can be....
// else if (flavor.isFlavorSerializedObjectType()) {
// java object
// }
// else if (flavor.isRepresentationClassInputStream()) {
// input stream
// }
}
}
// the user must not have dropped a file list
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace(System.out);
dtde.rejectDrop();
}
}
Aggregations