Search in sources :

Example 51 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project ACS by ACS-Community.

the class ClipboardHelper method getClipboardContents.

/**
     * Get the String in the clipboard.
     *
     * @return any text found on the Clipboard; if none found, return an
     * empty String.
     */
private String getClipboardContents() {
    String result = "";
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    //odd: the Object param of getContents is not currently used
    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) {
            //highly unlikely since we are using a standard DataFlavor
            System.out.println(ex);
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
    return result;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 52 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.

the class XDataTransferer method dragQueryURIs.

@Override
protected URI[] dragQueryURIs(InputStream stream, long format, Transferable localeTransferable) throws IOException {
    String charset = null;
    if (localeTransferable != null && isLocaleDependentTextFormat(format) && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
        try {
            charset = new String((byte[]) localeTransferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(format);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = getDefaultTextCharset();
    }
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(stream, charset));
        String line;
        ArrayList<URI> uriList = new ArrayList<URI>();
        URI uri;
        while ((line = reader.readLine()) != null) {
            try {
                uri = new URI(line);
            } catch (URISyntaxException uriSyntaxException) {
                throw new IOException(uriSyntaxException);
            }
            uriList.add(uri);
        }
        return uriList.toArray(new URI[uriList.size()]);
    } finally {
        if (reader != null)
            reader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) URI(java.net.URI)

Example 53 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.

the class HTMLCodec method translateBytes.

@Override
public Object translateBytes(byte[] bytes, DataFlavor flavor, long format, Transferable localeTransferable) throws IOException {
    if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
        if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
            throw new IOException("data translation failed");
        }
        String st = new String(bytes, 0, bytes.length, "UTF-16LE");
        String[] filenames = st.split("\0");
        if (0 == filenames.length) {
            return null;
        }
        // Convert the strings to File objects
        File[] files = new File[filenames.length];
        for (int i = 0; i < filenames.length; ++i) {
            files[i] = new File(filenames[i]);
            //They are temp-files from memory Stream, so they have to be removed on exit
            files[i].deleteOnExit();
        }
        // Turn the list of Files into a List and return
        return Arrays.asList(files);
    }
    if (format == CFSTR_INETURL && URL.class.equals(flavor.getRepresentationClass())) {
        String charset = getDefaultTextCharset();
        if (localeTransferable != null && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
            try {
                charset = new String((byte[]) localeTransferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
            } catch (UnsupportedFlavorException cannotHappen) {
            }
        }
        return new URL(new String(bytes, charset));
    }
    return super.translateBytes(bytes, flavor, format, localeTransferable);
}
Also used : IOException(java.io.IOException) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) URL(java.net.URL)

Example 54 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.

the class TargetPanel method drop.

public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    if (dtde.isDataFlavorSupported(dataFlavor)) {
        String result = null;
        try {
            Transferable t = dtde.getTransferable();
            byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
            result = new String(data, "UTF-16");
            repaint();
        } catch (UnsupportedFlavorException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        dtde.dropComplete(true);
        if (result != null && result.contains(MyTransferable.TEST_DATA)) {
            System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
            Timer t = new Timer();
            t.schedule(new TimerTask() {

                @Override
                public void run() {
                    System.exit(0);
                }
            }, 2000);
            return;
        }
    }
    dtde.rejectDrop();
    System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
    System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 55 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jabref by JabRef.

the class ClipBoardManager method getClipboardContents.

/**
     * Get the String residing on the clipboard.
     *
     * @return any text found on the Clipboard; if none found, return an
     * empty String.
     */
public String getClipboardContents() {
    String result = "";
    //odd: the Object param of getContents is not currently used
    Transferable contents = CLIPBOARD.getContents(null);
    if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException e) {
            //highly unlikely since we are using a standard DataFlavor
            LOGGER.info("problem with getting clipboard contents", e);
        }
    }
    return result;
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)106 IOException (java.io.IOException)92 Transferable (java.awt.datatransfer.Transferable)55 List (java.util.List)32 DataFlavor (java.awt.datatransfer.DataFlavor)26 File (java.io.File)25 Point (java.awt.Point)18 ArrayList (java.util.ArrayList)15 Clipboard (java.awt.datatransfer.Clipboard)14 JTree (javax.swing.JTree)9 TreePath (javax.swing.tree.TreePath)9 JComponent (javax.swing.JComponent)7 TransferHandler (javax.swing.TransferHandler)7 DropTargetContext (java.awt.dnd.DropTargetContext)6 URL (java.net.URL)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 Image (java.awt.Image)4 ActionEvent (java.awt.event.ActionEvent)4 MouseEvent (java.awt.event.MouseEvent)4 NodeInterface (com.sldeditor.common.NodeInterface)3