Java Code Examples for java.awt.datatransfer.DataFlavor

The following are top voted examples for showing how to use java.awt.datatransfer.DataFlavor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: bug8059739.java   Source Code and License 7 votes vote down vote up
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);
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: MissedHtmlAndRtfBug.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 3
Project: BaseClient   File: GuiScreen.java   Source Code and License 6 votes vote down vote up
/**
 * 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 "";
}
 
Example 4
Project: incubator-netbeans   File: ViewNodeTest.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 5
Project: dead-code-detector   File: FileTransferHandler.java   Source Code and License 6 votes vote down vote up
/** {@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;
}
 
Example 6
Project: incubator-netbeans   File: ConnectionNodeTest.java   Source Code and License 6 votes vote down vote up
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"));
}
 
Example 7
Project: incubator-netbeans   File: ClipboardHistory.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 8
Project: SubtitleDownloader   File: SubtitleDownloaderUI.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 9
Project: incubator-netbeans   File: LocallDownloadDnD.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 10
Project: incubator-netbeans   File: DragDropUtilitiesTest.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 11
Project: openjdk-jdk10   File: GetNativesForFlavorTest.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 12
Project: openjdk-jdk10   File: DataFlavorEqualsTest.java   Source Code and License 6 votes vote down vote up
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");

}
 
Example 13
Project: incubator-netbeans   File: WatchesNodeModel.java   Source Code and License 5 votes vote down vote up
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;
    }
}
 
Example 14
Project: openjdk-jdk10   File: DataFlavorSerializedTest.java   Source Code and License 5 votes vote down vote up
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");
}
 
Example 15
Project: OpenJSharp   File: WDataTransferer.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 16
Project: SER316-Munich   File: HTMLEditor.java   Source Code and License 5 votes vote down vote up
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();
	}
}
 
Example 17
Project: foolqq   File: ClipboardTool.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 18
Project: OpenJSharp   File: DataTransferer.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 19
Project: VISNode   File: ObjectTransferable.java   Source Code and License 5 votes vote down vote up
@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);
    }
}
 
Example 20
Project: openjdk-jdk10   File: TargetFileListFrame.java   Source Code and License 5 votes vote down vote up
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));
}
 
Example 21
Project: SER316-Aachen   File: HTMLEditor.java   Source Code and License 5 votes vote down vote up
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();
	}
}
 
Example 22
Project: Tarski   File: mxGraphTransferable.java   Source Code and License 5 votes vote down vote up
/**
 * 
 * @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;
}
 
Example 23
Project: Moenagade   File: FileDrop.java   Source Code and License 5 votes vote down vote up
/** 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;
}
 
Example 24
Project: jdk8u-jdk   File: TargetFileListFrame.java   Source Code and License 5 votes vote down vote up
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));
}
 
Example 25
Project: marathonv5   File: ListTransferHandler.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 26
Project: KernelHive   File: TransferableKernelRepositoryEntryTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 27
Project: ClipIt   File: ClipboardUtils.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 28
Project: jdk8u-jdk   File: ImageTransferTest.java   Source Code and License 5 votes vote down vote up
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()]);
}
 
Example 29
Project: Shellcode-IDE   File: DragAndDrop.java   Source Code and License 5 votes vote down vote up
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    if (!info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }
    return true;
}
 
Example 30
Project: brModelo   File: TransferableImage.java   Source Code and License 5 votes vote down vote up
@Override
public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
    if (flavor.equals(DataFlavor.imageFlavor) && i != null) {
        return i;
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
 
Example 31
Project: incubator-netbeans   File: RectangularSelectionTransferHandler.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 32
Project: incubator-netbeans   File: RectangularSelectionTransferHandler.java   Source Code and License 5 votes vote down vote up
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (RECTANGULAR_SELECTION_FLAVOR.equals(flavor)) {
        return rectangularSelectionData;
    }
    return delegate.getTransferData(flavor);
}
 
Example 33
Project: Tarski   File: mxGraphTransferable.java   Source Code and License 5 votes vote down vote up
/**
 * 
 * @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);
  }
}
 
Example 34
Project: incubator-netbeans   File: EditorCaretTransferHandler.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 35
Project: dead-code-detector   File: FileTransferHandler.java   Source Code and License 5 votes vote down vote up
/** {@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;
}
 
Example 36
Project: powertext   File: RTATextTransferHandler.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 37
Project: ramus   File: BasicTransferable.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 38
Project: ramus   File: RowTransferHandle.java   Source Code and License 5 votes vote down vote up
@Override
public boolean canImport(final JComponent comp,
                         final DataFlavor[] transferFlavors) {
    if (comp instanceof ImportExport)
        return ((ImportExport) comp).canImport(transferFlavors);
    return false;
}
 
Example 39
Project: jdk8u-jdk   File: bug8024061.java   Source Code and License 5 votes vote down vote up
@Override
public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
    if (isDataFlavorSupported(flavor)) {
        return this;
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
 
Example 40
Project: sbc-qsystem   File: PComplexService.java   Source Code and License 5 votes vote down vote up
@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;
}