Java Code Examples for java.awt.dnd.DropTargetDropEvent#getCurrentDataFlavors()

The following examples show how to use java.awt.dnd.DropTargetDropEvent#getCurrentDataFlavors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DnDUtils.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@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, Charset.defaultCharset());
        IOUtils.closeQuietly(in);
        foundMozLink = removeZeroChars(string.toString().split("\\n")[0]).trim();
      }
    }
  }
  return foundMozLink == null ? foundHtmlLink : foundMozLink;
}
 
Example 2
Source File: ExportPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@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 | IOException e) {
				//
			}
		}
	}
}
 
Example 3
Source File: XSLTransformationPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent dtde) {
    if (!stylesheet.isEnabled())
        return;

    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()) {
                        stylesheet.setText(file.getCanonicalPath());
                        lastPath = file.getParentFile();
                        break;
                    }
                }

                dtde.getDropTargetContext().dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                //
            }
        }
    }
}
 
Example 4
Source File: SrsPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@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 | IOException e) {
				//
			}
		}
	}
}
 
Example 5
Source File: ImportPanel.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
@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<File> files = new ArrayList<>();
				for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor))
					if (file.exists())
						files.add(file.getAbsoluteFile());
					else
						log.warn("Failed to drop from clipboard: '" + file.getAbsolutePath() + "' is not a file.");

				if (!files.isEmpty()) {
					if (dtde.getDropAction() != DnDConstants.ACTION_COPY)
						fileListModel.clear();

					addFiles(files);
				}

				dtde.getDropTargetContext().dropComplete(true);	
			} catch (UnsupportedFlavorException | IOException e) {
				//
			}
		}
	}
}