Java 8 Transferable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Transferable class.

This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
 * @author mzechner */ 
public class JglfwClipboard implements Clipboard, ClipboardOwner {
	public String getContents () {
		java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		Transferable contents = clipboard.getContents(null);
		if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
			try { 
				return (String)contents.getTransferData(DataFlavor.stringFlavor);
			} catch (Exception ignored) {
			} 
		} 
		return ""; 
	} 
 
	public void setContents (String content) {
		java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		clipboard.setContents(new StringSelection(content), this);
	} 
 
	public void lostOwnership (java.awt.datatransfer.Clipboard clipboard, Transferable transferable) {
7
CodeRank
This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
	@Override 
	public String getContents () {
		String result = "";
		java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		Transferable contents = clipboard.getContents(null);
		boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
		if (hasTransferableText) {
			try { 
				result = (String)contents.getTransferData(DataFlavor.stringFlavor);
			} catch (UnsupportedFlavorException ex) {
				// doh... 
			} catch (IOException ex) {
				// doh... 
			} 
		} 
		return result;
	} 
 
	@Override 
	public void setContents (String content) {
6
CodeRank
This code example shows how to use the following methods:getTransferData, getTransferDataFlavors
 
  public static String getClipboardString() {
    java.awt.datatransfer.Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = sysClip.getContents(null);
 
    JConfig.log().logDebug("Clipboard: " + sysClip.getName() + ", valid flavors: " + Arrays.toString(t.getTransferDataFlavors()));
 
    StringBuffer stBuff = sJDL.getTransferData(t);
    String clipString;
    if (stBuff == null) {
      try { 
        clipString = (String) t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        //  Nothing really to do here... 
        clipString = null;
      } 
    } else { 
      clipString = stBuff.toString();
    } 
 
6
CodeRank
This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
This code example shows how to use the following methods:getTransferData
This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
     * @param t transferable 
     * @return improrted image 
     */ 
    public static Image getImportedImage ( final Transferable t )
    { 
        if ( t.isDataFlavorSupported ( DataFlavor.imageFlavor ) )
        { 
            try 
            { 
                final Object data = t.getTransferData ( DataFlavor.imageFlavor );
                if ( data instanceof Image )
                { 
                    return ( Image ) data;
                } 
            } 
            catch ( final UnsupportedFlavorException e )
            { 
                // 
            } 
            catch ( final IOException e )
5
CodeRank
This code example shows how to use the following methods:getTransferData, getTransferDataFlavors
This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
This code example shows how to use the following methods:getTransferData
		Transferable paste = clipboard.getContents(null);
		if (paste == null) {
			return null; 
		} 
		try { 
			return (String) paste.getTransferData(DataFlavor.stringFlavor);
		} catch (Exception ex) {
			return null; 
		} 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:getTransferData, isDataFlavorSupported
 
        /* If it represents a String, use the StringSelection object's 
         * implementation to return the correct object. */ 
        else if ( mimeType.equals( stringFlavor.getMimeType() ) ) {
            Object obj = dataMap.get( flavor );
            Transferable stringTrans = new StringSelection( (String) obj );
            assert stringTrans.isDataFlavorSupported( stringFlavor );
            return stringTrans.getTransferData( stringFlavor );
        } 
 
        /* If it represents a DataSource, we need to supply it in an 
         * InputStream. */ 
        else if ( clazz.equals( InputStream.class ) ) {
            return new SourceInputStream( (DataSource) dataMap.get( flavor ) );
        } 
 
        /* We haven't put any other objects into our map. */ 
        else { 
            throw new UnsupportedFlavorException( flavor );
        } 
5
CodeRank
See Code Examples for Java 8 Transferable Methods: