当前位置: 首页>>代码示例>>Java>>正文


Java DropTargetDropEvent.getCurrentDataFlavors方法代码示例

本文整理汇总了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;
}
 
开发者ID:raydac,项目名称:netbeans-mmd-plugin,代码行数:25,代码来源:DnDUtils.java

示例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;
}
 
开发者ID:raydac,项目名称:netbeans-mmd-plugin,代码行数:26,代码来源:MMDEditor.java

示例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) {
				//
			}
		}
	}
}
 
开发者ID:3dcitydb,项目名称:importer-exporter,代码行数:25,代码来源:ExportPanel.java

示例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) {
				//
			}
		}
	}
}
 
开发者ID:3dcitydb,项目名称:importer-exporter,代码行数:25,代码来源:SrsPanel.java

示例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);
			}
		}
	}
}
 
开发者ID:bwollman,项目名称:41_follow,代码行数:45,代码来源:DndFileOpener.java

示例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;
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:11,代码来源:ControllerAdapter.java

示例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) {
				//
			}
		}
	}
}
 
开发者ID:3dcitydb,项目名称:importer-exporter,代码行数:32,代码来源:ImportPanel.java


注:本文中的java.awt.dnd.DropTargetDropEvent.getCurrentDataFlavors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。