當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。