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); }
/** * 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 ""; }
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); }
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); } } }
/** {@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; }
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")); }
@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); } }
@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); } }
@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); } }
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); }
/** * 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); } }
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"); }
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; } }
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"); }
@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; }
private void doPaste() { Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { Transferable content = clip.getContents(this); if (content == null) return; String txt = content .getTransferData(new DataFlavor(String.class, "String")) .toString(); document.replace( editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart(), txt, editorKit.getInputAttributes()); //editor.replaceSelection(content.getTransferData(new // DataFlavor(String.class, "String")).toString()); //editor.paste(); //insertHTML(content.getTransferData(new DataFlavor(String.class, // "String")).toString(), editor.getCaretPosition()); /* * Element el = * document.getParagraphElement(editor.getCaretPosition()); * insertTextInElement(el, content.getTransferData(new * DataFlavor(String.class, "String")).toString(), */ } catch (Exception ex) { ex.printStackTrace(); } }
public static String getSystemClipboard() { Clipboard sysClb = null; sysClb = Toolkit.getDefaultToolkit().getSystemClipboard(); try { Transferable t = sysClb.getContents(null); if (null != t && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { String text = (String) t.getTransferData(DataFlavor.stringFlavor); return text; } } catch (Exception e) { e.printStackTrace(); } return null; }
/** * Helper function to convert a Set of DataFlavors to a sorted array. * The array will be sorted according to <code>DataFlavorComparator</code>. */ public static DataFlavor[] setToSortedDataFlavorArray(Set flavorsSet) { DataFlavor[] flavors = new DataFlavor[flavorsSet.size()]; flavorsSet.toArray(flavors); final Comparator comparator = new DataFlavorComparator(IndexedComparator.SELECT_WORST); Arrays.sort(flavors, comparator); return flavors; }
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(DataFlavors.object())) { return value; } else if (flavor.equals(DataFlavors.string())) { return value.toString(); } else { throw new UnsupportedFlavorException(flavor); } }
TargetFileListFrame(Point location, int expectationTransferredFilesNumber) { try { dropFlavor = new DataFlavor("text/uri-list;class=java.io.Reader"); } catch (Exception ex) { } this.expectationTransferredFilesNumber = expectationTransferredFilesNumber; initGUI(location); setDropTarget(new DropTarget(list, DnDConstants.ACTION_COPY, this)); }
private void doPaste() { Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { Transferable content = clip.getContents(this); if (content == null) { return; } String txt = content .getTransferData(new DataFlavor(String.class, "String")) .toString(); document.replace( editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart(), txt, editorKit.getInputAttributes()); //editor.replaceSelection(content.getTransferData(new // DataFlavor(String.class, "String")).toString()); //editor.paste(); //insertHTML(content.getTransferData(new DataFlavor(String.class, // "String")).toString(), editor.getCaretPosition()); /* * Element el = * document.getParagraphElement(editor.getCaretPosition()); * insertTextInElement(el, content.getTransferData(new * DataFlavor(String.class, "String")).toString(), */ } catch (Exception ex) { ex.printStackTrace(); } }
/** * * @param flavor * @return Returns true if the given flavor is an image flavor of this transferable. */ protected boolean isImageFlavor(DataFlavor flavor) { int nFlavors = (imageFlavors != null) ? imageFlavors.length : 0; for (int i = 0; i < nFlavors; i++) { if (imageFlavors[i].equals(flavor)) { return true; } } return false; }
/** Determine if the dragged data is a file list. */ private boolean isDragOk( final java.io.PrintStream out, final java.awt.dnd.DropTargetDragEvent evt ) { boolean ok = false; // Get data flavors being dragged java.awt.datatransfer.DataFlavor[] flavors = evt.getCurrentDataFlavors(); // See if any of the flavors are a file list int i = 0; while( !ok && i < flavors.length ) { // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. // Is the flavor a file list? final DataFlavor curFlavor = flavors[i]; if( curFlavor.equals( java.awt.datatransfer.DataFlavor.javaFileListFlavor ) || curFlavor.isRepresentationClassReader()){ ok = true; } // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. i++; } // end while: through flavors // If logging is enabled, show data flavors if( out != null ) { if( flavors.length == 0 ) log( out, "FileDrop: no data flavors." ); for( i = 0; i < flavors.length; i++ ) log( out, flavors[i].toString() ); } // end if: logging enabled return ok; }
@Override public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } JList list = (JList) info.getComponent(); DefaultListModel listModel = (DefaultListModel) list.getModel(); JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Perform the actual import. if (insert) { listModel.add(index, data); } else { listModel.set(index, data); } return true; }
@Test public void testGetTransferDataFlavors() { DataFlavor[] df = tkre.getTransferDataFlavors(); DataFlavor d = null; for (DataFlavor i : df) { if (i.equals(TransferableKernelRepositoryEntry.entryFlavour)) { d = i; break; } } assertNotNull(d); }
public static Clipboard getClipboard() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); while (true) { Throwable throwable = null; try { clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); } catch (IllegalStateException e) { throwable = e; } if (throwable == null) { break; } } return clipboard; }
static String[] retrieveFormatsToTest() { SystemFlavorMap sfm = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap(); java.util.List<String> ln = sfm.getNativesForFlavor(DataFlavor.imageFlavor); if (OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType()) && !ln.contains("METAFILEPICT")) { // for test failing on JDK without this fix ln.add("METAFILEPICT"); } return ln.toArray(new String[ln.size()]); }
@Override public boolean canImport(TransferHandler.TransferSupport info) { if (!info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } return true; }
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(DataFlavor.imageFlavor) && i != null) { return i; } else { throw new UnsupportedFlavorException(flavor); } }
@Override public synchronized DataFlavor[] getTransferDataFlavors() { if (transferDataFlavorsCache != null) { return transferDataFlavorsCache; } DataFlavor[] flavors = delegate.getTransferDataFlavors(); DataFlavor[] result = Arrays.copyOf(flavors, flavors.length + 1); result[flavors.length] = RECTANGULAR_SELECTION_FLAVOR; return transferDataFlavorsCache = result; }
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (RECTANGULAR_SELECTION_FLAVOR.equals(flavor)) { return rectangularSelectionData; } return delegate.getTransferData(flavor); }
/** * * @param flavor * @return the richer data flavor of this and the specified * @throws UnsupportedFlavorException */ public Object getRicherData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(dataFlavor)) { return this; } else { throw new UnsupportedFlavorException(flavor); } }
/** {@inheritDoc} */ @Override public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { // We only support file lists for (final DataFlavor transferFlavor : transferFlavors) { if (!DataFlavor.javaFileListFlavor.equals(transferFlavor)) { return false; } } return true; }
/** * Returns whether or not the specified data flavor is a String flavor that * is supported. * @param flavor the requested flavor for the data * @return boolean indicating whether or not the data flavor is supported */ protected boolean isStringFlavor(DataFlavor flavor) { DataFlavor[] flavors = stringFlavors; for (int i = 0; i < flavors.length; i++) { if (flavors[i].equals(flavor)) { return true; } } return false; }
/** * Returns an array of DataFlavor objects indicating the flavors the data * can be provided in. The array should be ordered according to preference * for providing the data (from most richly descriptive to least * descriptive). * * @return an array of data flavors in which this data can be transferred */ public DataFlavor[] getTransferDataFlavors() { DataFlavor[] richerFlavors = getRicherFlavors(); int nRicher = (richerFlavors != null) ? richerFlavors.length : 0; int nHTML = (isHTMLSupported()) ? htmlFlavors.length : 0; int nPlain = (isPlainSupported()) ? plainFlavors.length : 0; int nString = (isPlainSupported()) ? stringFlavors.length : 0; int nFlavors = nRicher + nHTML + nPlain + nString; DataFlavor[] flavors = new DataFlavor[nFlavors]; // fill in the array int nDone = 0; if (nRicher > 0) { System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher); nDone += nRicher; } if (nHTML > 0) { System.arraycopy(htmlFlavors, 0, flavors, nDone, nHTML); nDone += nHTML; } if (nPlain > 0) { System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain); nDone += nPlain; } if (nString > 0) { System.arraycopy(stringFlavors, 0, flavors, nDone, nString); nDone += nString; } return flavors; }
@Override public boolean canImport(final JComponent comp, final DataFlavor[] transferFlavors) { if (comp instanceof ImportExport) return ((ImportExport) comp).canImport(transferFlavors); return false; }
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) { return this; } else { throw new UnsupportedFlavorException(flavor); } }
@Override public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } final Transferable t = info.getTransferable(); final ArrayList<QService> dataA; try { dataA = (ArrayList<QService>) t.getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { System.err.println(e); return false; } if (dataA == null || dataA.isEmpty()) { return false; } final DefaultListModel<QService> sl = (DefaultListModel<QService>) (((JList) (info .getComponent())).getModel()); dataA.stream().forEach((data) -> { if (data.isLeaf() && isGood(data)) { sl.addElement(data); } else { QServiceTree.sailToStorm(data, (TreeNode service) -> { if (service.isLeaf() && isGood((QService) service)) { sl.addElement((QService) service); } }); } }); return true; }