Example usage for java.awt.datatransfer DataFlavor stringFlavor

List of usage examples for java.awt.datatransfer DataFlavor stringFlavor

Introduction

In this page you can find the example usage for java.awt.datatransfer DataFlavor stringFlavor.

Prototype

DataFlavor stringFlavor

To view the source code for java.awt.datatransfer DataFlavor stringFlavor.

Click Source Link

Document

The DataFlavor representing a Java Unicode String class, where:
 representationClass = java.lang.String mimeType            = "application/x-java-serialized-object" 

Usage

From source file:net.sf.keystore_explorer.gui.dnd.KeyStoreEntryTransferable.java

/**
 * Get supported transfer data flavors.//from ww w .  j  av  a  2s  . c  o m
 *
 * @return Supported data flavors
 */
@Override
public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor };
}

From source file:TransferableColor.java

/** Check whether a specified DataFlavor is available */
public boolean isDataFlavorSupported(DataFlavor flavor) {
    if (flavor.equals(colorFlavor) || flavor.equals(DataFlavor.stringFlavor)
            || flavor.equals(DataFlavor.plainTextFlavor))
        return true;
    return false;
}

From source file:net.sf.jabref.exporter.RtfSelection.java

@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {

    if (flavor.equals(DataFlavor.stringFlavor)) {
        return content;
    } else if (flavor.equals(rtfFlavor)) {
        byte[] byteArray = content.getBytes();
        return new ByteArrayInputStream(byteArray);
    }/*from   w w w  . j a v  a  2s. c  o m*/
    throw new UnsupportedFlavorException(flavor);
}

From source file:de.cebitec.readXplorer.util.GeneralUtils.java

/**
 * @param parent the parent component/*w w  w.  ja va 2 s .  c  o m*/
 * @return Any text found in the clipboard. If none is found, an empty
 * String is returned.
 */
public static String getClipboardContents(Component parent) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    String result = "";
    Transferable contents = clipboard.getContents(null);
    final boolean hasTransferableText = (contents != null)
            && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (hasTransferableText) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException ex) {
            JOptionPane.showMessageDialog(parent, "Unsupported DataFlavor for clipboard copying.",
                    "Paste Error", JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(parent,
                    "IOException occured during recovering of text from clipboard.", "Paste Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    return result;
}

From source file:net.sf.keystore_explorer.gui.dnd.KeyStoreEntryTransferable.java

/**
 * Is supplied data flavor supported?/* w w w  . j av  a 2 s .  c  o m*/
 *
 * @param dataFlavor
 *            Data flavor
 * @return True if it is
 */
@Override
public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
    return (dataFlavor == DataFlavor.javaFileListFlavor) || (dataFlavor == DataFlavor.stringFlavor);
}

From source file:DnDDemo2.java

public boolean importData(JComponent component, Transferable transferable) {
    String colorMimeType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.awt.Color";
    JTextComponent textComponent = (JTextComponent) component;
    try {//from   www . jav  a2  s.com
        DataFlavor colorFlavor = new DataFlavor(colorMimeType);
        Color color = (Color) transferable.getTransferData(colorFlavor);
        String text = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        textComponent.setForeground(color);
        textComponent.setText(text);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}

From source file:de.drop_converter.plugins.binary_convert.Base642Data.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {// w  w  w . j  ava  2 s .  c  o m
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, false);
                    out = getOutputStream(file, ".bin");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().decode(data.getBytes());
                out = getOutputStream(null, ".bin");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:de.drop_converter.plugins.binary_convert.Data2Base64.java

@Override
public boolean importData(TransferSupport support) throws ConverterException {
    try {/*from   www  .j a v a  2 s  . co  m*/
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> files = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);
            for (File file : files) {
                FileInputStream fis = null;
                Base64InputStream base64IS = null;
                OutputStream out = null;
                try {
                    fis = new FileInputStream(file);
                    base64IS = new Base64InputStream(fis, true);
                    out = getOutputStream(file, ".base64");
                    IOUtils.copy(base64IS, out);
                } catch (Exception e) {
                    throw new ConverterException(e);
                } finally {
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(base64IS);
                    IOUtils.closeQuietly(fis);
                }
            }
            return true;
        } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            OutputStream out = null;
            try {
                byte[] encode = new Base64().encode(data.getBytes());
                out = getOutputStream(null, ".base64");
                out.write(encode);
            } catch (Exception e) {
                throw new ConverterException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }

        }
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    return false;
}

From source file:ja.lingo.application.gui.drophandler.DropHandler.java

public boolean importData(JComponent c, Transferable t) {
    if (engine.getFinder().isEmpty()) {
        return false;
    }/* w w w .  j  ava  2 s  .  co m*/

    if (canImport(c, t.getTransferDataFlavors())) {
        try {
            String value = (String) t.getTransferData(DataFlavor.stringFlavor);

            model.navigateAndTranslate(value.trim());
            model.main_showAtTop();

            return true;
        } catch (Throwable tt) {
            LOG.warn("Could not drop object", tt);
            Messages.info(c, resources.text("couldNotDropObject"));
        }
    }
    return false;
}

From source file:Main.java

public boolean importData(JComponent comp, Transferable t) {
    DataFlavor[] flavors = t.getTransferDataFlavors();
    System.out.println("Trying to import:" + t);
    for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        try {//from  www. ja va 2s. c o  m
            if (flavor.equals(DataFlavor.javaFileListFlavor)) {
                System.out.println("importData: FileListFlavor");
                List l = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
                Iterator iter = l.iterator();
                while (iter.hasNext()) {
                    File file = (File) iter.next();
                    System.out.println("GOT FILE: " + file.getCanonicalPath());
                }
                return true;
            } else if (flavor.equals(DataFlavor.stringFlavor)) {
                System.out.println("importData: String Flavor");
                String fileOrURL = (String) t.getTransferData(flavor);
                System.out.println("GOT STRING: " + fileOrURL);
                try {
                    URL url = new URL(fileOrURL);
                    System.out.println("Valid URL: " + url.toString());
                    return true;
                } catch (MalformedURLException ex) {
                    System.err.println("Not a valid URL");
                    return false;
                }
            } else {
                System.out.println("importData rejected: " + flavor);
            }
        } catch (IOException ex) {
            System.err.println("IOError getting data: " + ex);
        } catch (UnsupportedFlavorException e) {
            System.err.println("Unsupported Flavor: " + e);
        }
    }
    return false;
}