本文整理汇总了Java中java.awt.datatransfer.DataFlavor.isMimeTypeEqual方法的典型用法代码示例。如果您正苦于以下问题:Java DataFlavor.isMimeTypeEqual方法的具体用法?Java DataFlavor.isMimeTypeEqual怎么用?Java DataFlavor.isMimeTypeEqual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.datatransfer.DataFlavor
的用法示例。
在下文中一共展示了DataFlavor.isMimeTypeEqual方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setContentsNative
import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
@Override
protected void setContentsNative(Transferable contents) {
// Don't use delayed Clipboard rendering for the Transferable's data.
// If we did that, we would call Transferable.getTransferData on
// the Toolkit thread, which is a security hole.
//
// Get all of the target formats into which the Transferable can be
// translated. Then, for each format, translate the data and post
// it to the Clipboard.
Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
getFormatsForTransferable(contents, getDefaultFlavorTable());
openClipboard(this);
try {
for (Long format : formatMap.keySet()) {
DataFlavor flavor = formatMap.get(format);
try {
byte[] bytes = WDataTransferer.getInstance().
translateTransferable(contents, flavor, format);
publishClipboardData(format, bytes);
} catch (IOException e) {
// Fix 4696186: don't print exception if data with
// javaJVMLocalObjectMimeType failed to serialize.
// May remove this if-check when 5078787 is fixed.
if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
e instanceof java.io.NotSerializableException)) {
e.printStackTrace();
}
}
}
} finally {
closeClipboard();
}
}
示例2: removeSuspectedData
import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
throws IOException
{
if (null == System.getSecurityManager()
|| !flavor.isMimeTypeEqual("text/uri-list"))
{
return str;
}
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {
StringBuilder allowedFiles = new StringBuilder(str.length());
String [] uriArray = str.split("(\\s)+");
for (String fileName : uriArray)
{
File file = new File(fileName);
if (file.exists() &&
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
if (0 != allowedFiles.length())
{
allowedFiles.append("\\r\\n");
}
allowedFiles.append(fileName);
}
}
return allowedFiles.toString();
});
} catch (PrivilegedActionException pae) {
throw new IOException(pae.getMessage(), pae);
}
}
示例3: drop
import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavours = tr.getTransferDataFlavors();
// Iterate the flavours we have for this event
for (DataFlavor flavour : flavours) {
List<File> files = new ArrayList<>(0);
// Is the OS playing nicely? This is the correct data flavour
// for what we want
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
if (flavour.isFlavorJavaFileListType()) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
files = (List<File>) tr.getTransferData(flavour);
}
}
// Check if this is the URI way of providing the dnd data
else if (uriListFlavor != null && dtde.isDataFlavorSupported(uriListFlavor)) {
if (flavour.isMimeTypeEqual(uriListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
String data = (String) tr.getTransferData(uriListFlavor);
files = textURIListToFileList(data);
}
} else {
log.error("No supported data flavors!");
}
// We didn't get the desired flavour, keep trying until we do
// (or run out).
if (files.size() == 0) {
continue;
}
// Filter unsupported files from our list of files.
for (File f : files) {
if (!ImageToZxSpec.isSupported(f)) {
files.remove(f);
}
}
// Only convert the first file.
File[] inFiles = files.toArray(new File[0]);
ImageToZxSpec.setInFiles(inFiles);
if (inFiles[0].isDirectory()) {
ImageToZxSpec.setOutFolder(inFiles[0]);
} else {
ImageToZxSpec.setOutFolder(inFiles[0].getParentFile());
}
// For drag and drop we want feedback so we're showing the
// preview dialog which will show the first file.
uiCallback.processPopupPreview();
// We got what we came for - don't bother to keep checking
break;
}
} catch (Exception io) {
log.error("Drag and drop error {}", io);
} finally {
dtde.dropComplete(true);
}
}
示例4: removeSuspectedData
import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
throws IOException
{
if (null == System.getSecurityManager()
|| !flavor.isMimeTypeEqual("text/uri-list"))
{
return str;
}
String ret_val = "";
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
try {
ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() {
StringBuffer allowedFiles = new StringBuffer(str.length());
String [] uriArray = str.split("(\\s)+");
for (String fileName : uriArray)
{
File file = new File(fileName);
if (file.exists() &&
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
if (0 != allowedFiles.length())
{
allowedFiles.append("\\r\\n");
}
allowedFiles.append(fileName);
}
}
return allowedFiles.toString();
}
});
} catch (PrivilegedActionException pae) {
throw new IOException(pae.getMessage(), pae);
}
return ret_val;
}