本文整理汇总了Java中java.awt.datatransfer.DataFlavor类的典型用法代码示例。如果您正苦于以下问题:Java DataFlavor类的具体用法?Java DataFlavor怎么用?Java DataFlavor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataFlavor类属于java.awt.datatransfer包,在下文中一共展示了DataFlavor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MissedHtmlAndRtfBug
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df)
throws InterruptedException {
final Frame targetFrame = new Frame("Target frame");
final TargetPanel targetPanel = new TargetPanel(targetFrame, df);
targetFrame.add(targetPanel);
targetFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
targetFrame.dispose();
}
});
targetFrame.setLocation(targetFrameLocation);
targetFrame.pack();
targetFrame.setVisible(true);
doTest(dragSourcePoint, targetPanel);
}
示例2: getClipboardString
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
/**
* Returns a string stored in the system clipboard.
*/
public static String getClipboardString()
{
try
{
Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);
if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
{
return (String)transferable.getTransferData(DataFlavor.stringFlavor);
}
}
catch (Exception var1)
{
;
}
return "";
}
示例3: testClipboardCopy
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public void testClipboardCopy() throws Exception {
String tablename = "testtable";
String pkName = "id";
createBasicTable(tablename, pkName);
String viewname = "testview";
createView(viewname, "select id from testtable");
ViewNode viewNode = getViewNode(viewname);
assertNotNull(viewNode);
assertTrue(viewNode.canCopy());
Transferable transferable = (Transferable)viewNode.clipboardCopy();
Set mimeTypes = new HashSet();
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
mimeTypes.add(flavors[i].getMimeType());
}
assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-view; class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$View"));
assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node"));
dropView(viewname);
dropTable(tablename);
}
示例4: runTest
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
private static void runTest() throws Exception {
String testString = "my string";
JTextField tf = new JTextField(testString);
tf.selectAll();
Clipboard clipboard = new Clipboard("clip");
tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);
DataFlavor[] dfs = clipboard.getAvailableDataFlavors();
for (DataFlavor df: dfs) {
String charset = df.getParameter("charset");
if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) &&
charset != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(
(InputStream) clipboard.getData(df), charset));
String s = br.readLine();
System.out.println("Content: '" + s + "'");
passed &= s.contains(testString);
}
}
}
示例5: importData
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean importData(JComponent comp, Transferable t) {
if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return false;
}
try {
@SuppressWarnings("unchecked")
final List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
// importation
fileTableModel.addFiles(files);
return true;
} catch (final Exception e) {
DcdUiHelper.printStackTrace(e);
}
return false;
}
示例6: testClipboardCopy
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public void testClipboardCopy() throws Exception {
JDBCDriver driver = JDBCDriver.create("foo", "Foo", "org.example.Foo", new URL[0]);
JDBCDriverManager.getDefault().addDriver(driver);
DatabaseConnection dbconn = DatabaseConnection.create(driver, "url", "user", "schema", "pwd", false);
ConnectionManager.getDefault().addConnection(dbconn);
ConnectionNode connectionNode = getConnectionNode();
assertTrue(connectionNode != null);
assertTrue(connectionNode.canCopy());
Transferable transferable = (Transferable)connectionNode.clipboardCopy();
Set mimeTypes = new HashSet();
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
mimeTypes.add(flavors[i].getMimeType());
}
assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-connection; class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$Connection"));
assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node"));
}
示例7: clipboardChanged
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
@Override
public void clipboardChanged(ClipboardEvent ev) {
ExClipboard clipboard = ev.getClipboard();
Transferable transferable = null;
String clipboardContent = null;
try {
transferable = clipboard.getContents(null);
if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
clipboardContent = (String) transferable.getTransferData(DataFlavor.stringFlavor);
}
} catch (OutOfMemoryError oom) {
NotificationDisplayer.getDefault().notify( NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom"),NotificationDisplayer.Priority.NORMAL.getIcon(), NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom-details"), null);
return;
} catch (IOException ioe) {
//ignored for bug #218255
} catch (UnsupportedFlavorException ufe) {
}
if (clipboardContent != null) {
addHistory(transferable, clipboardContent);
}
}
示例8: drop
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
try {
Transferable t = dtde.getTransferable();
DataFlavor[] dataFlavors = t.getTransferDataFlavors();
for (DataFlavor df : dataFlavors) {
if (df.isFlavorJavaFileListType()) {
File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
pathNameTextField.setText(getFilesName(filesArray));
}
}
} catch (UnsupportedFlavorException e2) {
} catch (IOException ex) {
Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例9: dragEnter
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
@Override
public void dragEnter(DropTargetDragEvent dtde) {
accept = null;
value = null;
for (DataFlavor dataFlavor : dtde.getCurrentDataFlavors()) {
Object obj = null;
try {
obj = dtde.getTransferable().getTransferData(dataFlavor);
} catch (Exception ex) {
continue;
}
if (dataFlavor.isFlavorJavaFileListType()) {
accept = dataFlavor;
value = obj;
break;
}
if ("text".equals(dataFlavor.getPrimaryType()) && "uri-list".equals(dataFlavor.getSubType()) && dataFlavor.getRepresentationClass() == String.class) {
accept = dataFlavor;
value = (String) obj;
break;
}
}
if (accept != null) {
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
}
}
示例10: testMultiTransferableForCut
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public void testMultiTransferableForCut() throws Exception {
N node = new N();
N n2 = new N();
N[] arr = { node, n2 };
Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_MOVE);
assertEquals("One call to cut ", 1, node.cut);
assertEquals("One call to cut on n2", 1, n2.cut);
assertEquals("No to drag", 0, node.drag);
assertEquals("No to drag on n2", 0, n2.drag);
assertEquals("No call to copy", 0, node.copy);
assertEquals("No call to copy on n2", 0, n2.copy);
assertNotNull("Call to convertor", last);
assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
Object obj = last.getTransferData(ExTransferable.multiFlavor);
if (!( obj instanceof MultiTransferObject)) {
fail("It should be MultiTransferObject: " + obj);
}
MultiTransferObject m = (MultiTransferObject)obj;
assertEquals("Two in multi", 2, m.getCount());
assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
示例11: test4
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
/**
* Verifies that the encoded native is added only for DataFlavors
* that has no mappings and that DataFlavor is properly encoded.
*/
public static void test4() throws ClassNotFoundException {
final DataFlavor flavor =
new DataFlavor("unknown/unknown");
final java.util.List natives = fm.getNativesForFlavor(flavor);
if (natives.size() == 1) {
String element = (String) natives.get(0);
if (SystemFlavorMap.isJavaMIMEType(element)) {
final DataFlavor decodedFlavor =
SystemFlavorMap.decodeDataFlavor(element);
if (!flavor.equals(decodedFlavor)) {
System.err.println("DataFlavor is not properly incoded:");
System.err.println(" encoded flavor: " + flavor);
System.err.println(" decoded flavor: " + decodedFlavor);
throw new RuntimeException("getFlavorsForNative() returns:"
+ natives);
}
}
} else {
throw new RuntimeException("getFlavorsForNative() returns:"
+ natives);
}
}
示例12: main
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public static void main(String[] args) {
df = new DataFlavor();
try {
eq = df.equals((Object)new DataFlavor());
if (!eq) noexc = false;
eq = df.equals(new DataFlavor());
if (!eq) noexc = false;
eq = df.equals("application/postscript;class=java.awt.datatransfer.DataFlavor");
if (eq) noexc = false;
} catch (NullPointerException e1) {
noexc = false;
}
finished = true;
if (!noexc)
throw new RuntimeException("Test FAILED");
}
示例13: getPasteTypes
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public PasteType[] getPasteTypes(final Object node, final Transferable t) throws UnknownTypeException {
if (node != TreeModel.ROOT && getWatch(node) == null) {
return null;
}
DataFlavor[] flavors = t.getTransferDataFlavors();
final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors);
if (textFlavor != null) {
return new PasteType[] { new PasteType() {
public Transferable paste() {
try {
java.io.Reader r = textFlavor.getReaderForText(t);
java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000);
r.read(cb);
cb.flip();
Watch w = getWatch(node);
if (w != null) {
w.setExpression(cb.toString());
//fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node));
} else {
// Root => add a new watch
DebuggerManager.getDebuggerManager().createWatch(cb.toString());
}
} catch (Exception ex) {}
return null;
}
} };
} else {
return null;
}
}
示例14: main
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
df = new DataFlavor("application/x-java-serialized-object;class=java.io.Serializable");
boolean fl = df.isMimeTypeSerializedObject();
finished = true;
if (!fl)
throw new RuntimeException("Test FAILED");
}
示例15: getFormatsForFlavors
import java.awt.datatransfer.DataFlavor; //导入依赖的package包/类
@Override
public SortedMap <Long, DataFlavor> getFormatsForFlavors(
DataFlavor[] flavors, FlavorTable map)
{
SortedMap <Long, DataFlavor> retval =
super.getFormatsForFlavors(flavors, map);
// The Win32 native code does not support exporting LOCALE data, nor
// should it.
retval.remove(L_CF_LOCALE);
return retval;
}