本文整理匯總了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) {
//
}
}
}
}