本文整理汇总了Java中java.awt.dnd.DropTargetDropEvent.getCurrentDataFlavors方法的典型用法代码示例。如果您正苦于以下问题:Java DropTargetDropEvent.getCurrentDataFlavors方法的具体用法?Java DropTargetDropEvent.getCurrentDataFlavors怎么用?Java DropTargetDropEvent.getCurrentDataFlavors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.dnd.DropTargetDropEvent
的用法示例。
在下文中一共展示了DropTargetDropEvent.getCurrentDataFlavors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractDropLink
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@Nullable
public static String extractDropLink(@Nonnull final DropTargetDropEvent dtde) throws Exception {
String foundHtmlLink = null;
String foundMozLink = null;
for (final DataFlavor df : dtde.getCurrentDataFlavors()) {
if (df.getRepresentationClass() == String.class) {
if (foundHtmlLink == null && df.isMimeTypeEqual(MIME_TEXT_HTML)) {
final String link = extractHtmlLink(true, (String) dtde.getTransferable().getTransferData(df));
if (link != null) {
foundHtmlLink = link;
}
}
} else if (df.getRepresentationClass() == InputStream.class && df.isMimeTypeEqual(MIME_MOZ_URL)) {
if (foundMozLink == null) {
final InputStream in = ((InputStream) dtde.getTransferable().getTransferData(df));
final StringWriter string = new StringWriter();
IOUtils.copy(in, string);
IOUtils.closeQuietly(in);
foundMozLink = removeZeroChars(string.toString().split("\\n")[0]).trim();
}
}
}
return foundMozLink == null ? foundHtmlLink : foundMozLink;
}
示例2: 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;
}
示例3: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
if (dataFlover.isFlavorJavaFileListType()) {
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)) {
if (file.isFile() && file.canRead()) {
browseText.setText(file.getCanonicalPath());
break;
}
}
dtde.getDropTargetContext().dropComplete(true);
} catch (UnsupportedFlavorException e1) {
//
} catch (IOException e2) {
//
}
}
}
}
示例4: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
if (dataFlover.isFlavorJavaFileListType()) {
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)) {
if (file.isFile() && file.canRead()) {
fileText.setText(file.getCanonicalPath());
break;
}
}
dtde.getDropTargetContext().dropComplete(true);
} catch (UnsupportedFlavorException e1) {
//
} catch (IOException e2) {
//
}
}
}
}
示例5: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
/**
* If the DropTargetDropEvent's DataFlavor is javaFileListFlavor, it opens the List of dropped
* files in the Follow application. No other DataFlavors are supported.
*
* @param e
* "drop" event
* @see java.awt.dnd.DropTargetListener#drop(DropTargetDropEvent)
*/
public void drop(DropTargetDropEvent e)
{
DataFlavor[] flavors = e.getCurrentDataFlavors();
int numFlavors = (flavors != null) ? flavors.length : 0;
for (int i = 0; i < numFlavors; i++)
{
// Ignore all flavors except javaFileListType
if (flavors[i].isFlavorJavaFileListType())
{
e.acceptDrop(DnDConstants.ACTION_COPY);
boolean dropCompleted = false;
Transferable transferable = e.getTransferable();
try
{
List<File> fileList = (List<File>) transferable.getTransferData(flavors[i]);
for (File file : fileList)
{
app.openFile(file);
}
dropCompleted = true;
}
catch (UnsupportedFlavorException ufException)
{
// do nothing
}
catch (IOException ioException)
{
// do nothing
}
finally
{
e.dropComplete(dropCompleted);
}
}
}
}
示例6: isDropAcceptable
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
private boolean isDropAcceptable(DropTargetDropEvent event) {
// check if there is at least one File Type in the list
DataFlavor[] flavors = event.getCurrentDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].isFlavorJavaFileListType()) {
return true;
}
}
return false;
}
示例7: drop
import java.awt.dnd.DropTargetDropEvent; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
if (dataFlover.isFlavorJavaFileListType()) {
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List<String> fileNames = new ArrayList<String>();
for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor))
if (file.exists())
fileNames.add(file.getCanonicalPath());
else
LOG.warn("Failed to drop from clipboard: '" + file.getAbsolutePath() + "' is not a file.");
if (!fileNames.isEmpty()) {
if (dtde.getDropAction() != DnDConstants.ACTION_COPY)
fileListModel.clear();
addFileNames(fileNames);
}
dtde.getDropTargetContext().dropComplete(true);
} catch (UnsupportedFlavorException e1) {
//
} catch (IOException e2) {
//
}
}
}
}