本文整理汇总了Java中java.awt.dnd.DropTargetDropEvent.getTransferable方法的典型用法代码示例。如果您正苦于以下问题:Java DropTargetDropEvent.getTransferable方法的具体用法?Java DropTargetDropEvent.getTransferable怎么用?Java DropTargetDropEvent.getTransferable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.dnd.DropTargetDropEvent
的用法示例。
在下文中一共展示了DropTargetDropEvent.getTransferable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
try {
Transferable t = dtde.getTransferable();
DataFlavor[] dataFlavors = t.getTransferDataFlavors();
for (DataFlavor df : dataFlavors) {
if (df.isFlavorJavaFileListType()) {
File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
pathNameTextField.setText(getFilesName(filesArray));
}
}
} catch (UnsupportedFlavorException e2) {
} catch (IOException ex) {
Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例2: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
} else {
dtde.rejectDrop();
return;
}
Transferable t = dtde.getTransferable();
List<Village> v;
MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor());
try {
v = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor);
fireVillagesDraggedEvent(v, dtde.getLocation());
} catch (Exception ignored) {
}
}
示例3: extractDropFile
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Nullable
private File extractDropFile(@Nonnull final DropTargetDropEvent dtde) throws Exception {
File result = null;
for (final DataFlavor df : dtde.getCurrentDataFlavors()) {
final Class<?> representation = df.getRepresentationClass();
if (FileTransferable.class.isAssignableFrom(representation)) {
final FileTransferable t = (FileTransferable) dtde.getTransferable();
final List<File> listOfFiles = t.getFiles();
result = listOfFiles.isEmpty() ? null : listOfFiles.get(0);
break;
} else if (df.isFlavorJavaFileListType()) {
try {
final List list = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
if (list != null && !list.isEmpty()) {
result = (File) list.get(0);
}
break;
}
catch (final Exception ex) {
LOGGER.error("Can't extract file from DnD", ex); //NOI18N
}
}
}
return result;
}
示例4: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Override
public void drop(DropTargetDropEvent arg0) {
Transferable tr = arg0.getTransferable();
arg0.acceptDrop(DnDConstants.ACTION_REFERENCE);
if(arg0.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
try {
@SuppressWarnings("unchecked")
List<File> fileList = (List<File>)tr.getTransferData(DataFlavor.javaFileListFlavor);
for(File file: fileList){
AttackResultFrame resultFrame = new AttackResultFrame();
if (resultFrame.loadResult(file) == true){
resultFrame.setVisible(true);
resultFrame.invalidate();
}else{
resultFrame = null;
}
}
} catch (UnsupportedFlavorException | IOException e) {
logger.debug(e);
}
}
}
示例5: extractTransferData
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
private void extractTransferData(DropTargetDropEvent dtde) {
if (dtde == null) {
System.out.println("ERROR> BDnDC::getTransferData(): dropEvent is null");
return;
}
Transferable tr = dtde.getTransferable();
try {
transferData = (Vector) tr.getTransferData(DefaultTransferableObject.OBJECT_FLAVOR);
// cache beanInfos
if (transferData.size() >= 2) {
Object bean = transferData.get(0);
BeanInfo beanInfo = (BeanInfo) transferData.get(1);
beanInfoMap.put(bean.getClass().getName(), beanInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: extractTransferData
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
/**
* Gets the object that is passed in transferable in DropTargetDropEvent.
*/
private Object extractTransferData(DropTargetDropEvent dtde) {
if (dtde == null) {
Debug.message("defaultdndcatcher",
"ERROR> DefaultDnDCatcher::getTransferData(): dropEvent is null");
return null;
}
Transferable tr = dtde.getTransferable();
try {
return tr.getTransferData(DefaultTransferableObject.OBJECT_FLAVOR);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例7: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
try {
final Transferable transferable = dtde.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
if (fileList.size() > 0) {
final OpenProductAction open = new OpenProductAction();
open.setFiles(fileList.toArray(new File[fileList.size()]));
dtde.dropComplete(Boolean.TRUE.equals(open.execute()));
}
} else {
dtde.rejectDrop();
}
} catch (UnsupportedFlavorException | IOException ignored) {
dtde.rejectDrop();
}
}
示例8: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public void drop(DropTargetDropEvent dtde) {
if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
// Accept the drop and get the transfer data
dtde.acceptDrop(dtde.getDropAction());
Transferable transferable = dtde.getTransferable();
boolean dropSucceeded = false;
try {
window
.setCursor(Cursor
.getPredefinedCursor(Cursor.WAIT_CURSOR));
dropSucceeded = dropFile(dtde.getDropAction(), transferable,
dtde.getLocation());
} catch (Exception e) {
e.printStackTrace();
} finally {
window.setCursor(Cursor.getDefaultCursor());
dtde.dropComplete(dropSucceeded);
}
} else {
dtde.dropComplete(false);
}
}
示例9: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public void drop(DropTargetDropEvent dtde) {
gestureStarted = false;
if ((dtde.getDropAction() & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
Transferable t = dtde.getTransferable();
try {
DBTableInternalFrame iFrame = (DBTableInternalFrame) t
.getTransferData(InternalFrameTransferable.DATA_FLAVOR);
if (iFrame != DBTableInternalFrame.this) {
JoinLine joinLine = new JoinLine(iFrame, iFrame
.getSelectedRow(), DBTableInternalFrame.this,
columnsListBox.getSelectedIndex());
desktop.addJoinLine(joinLine);
desktop.repaint();
}
} catch (Exception e) {
e.printStackTrace();
}
dtde.dropComplete(true);
}
}
示例10: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public void drop(DropTargetDropEvent event) {
int dropAction = event.getDropAction();
JComponent c = (JComponent) event.getDropTargetContext().getComponent();
DataObjectTransferHandler transferHandler = (DataObjectTransferHandler) c.getTransferHandler();
if (canImport && (transferHandler != null) && actionSupported(dropAction)) {
event.acceptDrop(dropAction);
try {
Transferable transferable = event.getTransferable();
transferHandler.setDropPoint(event.getLocation());
transferHandler.setDropComponent(c);
event.dropComplete(transferHandler.importData(c, transferable));
} catch (RuntimeException e) {
event.dropComplete(false);
}
} else {
event.rejectDrop();
}
}
示例11: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent dtde) {
if (!dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.rejectDrop();
return;
}
dtde.acceptDrop(dtde.getDropAction());
try {
Transferable transferable = dtde.getTransferable();
List<File> transferData = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
if (transferData != null && transferData.size() > 0) {
dtde.dropComplete(true);
// load first file
mainWindow.openFile(transferData.get(0));
}
} catch (Exception e) {
LOG.error("File drop operation failed", e);
}
}
示例12: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public void drop(DropTargetDropEvent dtde) {
try {
Transferable tr = dtde.getTransferable();
if (tr.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
String data = (String) tr.getTransferData(DataFlavor.stringFlavor);
// create the new TreeTable containing the selected dragged path
this.addSelectedTestdirectoryToMetaCampaign(data);
dtde.getDropTargetContext().dropComplete(true);
} else {
System.err.println("Rejected");
dtde.rejectDrop();
}
} catch (IOException | UnsupportedFlavorException io) {
logger.error(io);
dtde.rejectDrop();
}
}
示例13: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
final Transferable transferable = dropTargetDropEvent.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY);
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
}
else {
dropTargetDropEvent.rejectDrop();
}
}
catch (Exception ex) {
Log.error(ex);
dropTargetDropEvent.rejectDrop();
}
}
示例14: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
try {
Transferable t = dtde.getTransferable();
List<File> files = null;
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
files = (List<File>) t
.getTransferData(DataFlavor.javaFileListFlavor);
} else if (uriFlavor != null && t.isDataFlavorSupported(uriFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
files = textURIListToFileList((String) t
.getTransferData(uriFlavor));
} else
dtde.rejectDrop();
if (files != null && files.size() == 1) {
openFile(files.get(0));
dtde.dropComplete(true);
} else
dtde.dropComplete(false);
} catch (UnsupportedFlavorException ex) {
dtde.rejectDrop();
} catch (IOException e) {
dtde.rejectDrop();
}
}
示例15: isDropAcceptable
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
public boolean isDropAcceptable(DropTargetDropEvent event) {
Transferable transferable = event.getTransferable();
if (transferable != null) {
if (transferable.isDataFlavorSupported(FSTabbedPaneTransferable.FLAVOR)) {
FSTabbedPaneTransferable tabTransferable = getTabTransferable(event);
return tabTransferable.index >= 0;
}
}
return false;
}