Search in sources :

Example 46 with DataFlavor

use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.

the class EditPortalFrame method makeDndIconPanel.

/**
     * ******************** DnD ****************************
     */
protected JPanel makeDndIconPanel() {
    _dndPanel = new JPanel();
    String fileName = "resources/icons/throttles/RoundRedCircle20.png";
    NamedIcon icon = new NamedIcon(fileName, fileName);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), Bundle.getMessage("BeanNamePortal")));
    try {
        JLabel label = new IconDragJLabel(new DataFlavor(Editor.POSITIONABLE_FLAVOR));
        label.setIcon(icon);
        label.setName(Bundle.getMessage("BeanNamePortal"));
        panel.add(label);
    } catch (java.lang.ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    }
    _dndPanel.add(panel);
    return _dndPanel;
}
Also used : JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) JLabel(javax.swing.JLabel) DragJLabel(jmri.jmrit.catalog.DragJLabel) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 47 with DataFlavor

use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.

the class ReporterItemPanel method makeDndIconPanel.

@Override
protected void makeDndIconPanel(HashMap<String, NamedIcon> iconMap, String displayKey) {
    if (_update) {
        return;
    }
    _reporter = new ReporterIcon(_editor);
    JPanel panel = new JPanel();
    JPanel comp;
    try {
        comp = getDragger(new DataFlavor(Editor.POSITIONABLE_FLAVOR));
        comp.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
    } catch (java.lang.ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
        comp = new JPanel();
    }
    panel.add(comp);
    panel.revalidate();
    int width = Math.max(100, panel.getPreferredSize().width);
    panel.setPreferredSize(new java.awt.Dimension(width, panel.getPreferredSize().height));
    panel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
    _dragIconPanel = panel;
    _dragIconPanel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
}
Also used : ReporterIcon(jmri.jmrit.display.ReporterIcon) JPanel(javax.swing.JPanel) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 48 with DataFlavor

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

the class DataFlavorComparatorTest method main.

public static void main(String[] args) {
    DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() + " should not be equal");
    }
}
Also used : DataTransferer(sun.awt.datatransfer.DataTransferer) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 49 with DataFlavor

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

the class DataFlavorComparatorTest1 method main.

public static void main(String[] args) throws Exception {
    String[] mimes = new String[] { "text/plain;class=java.nio.ByteBuffer;charset=UTF-8", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-8", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16LE", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16LE", "application/x-java-text-encoding", "application/x-java-serialized-object;class=java.lang.String", "text/plain;class=java.io.InputStream;charset=UTF-8", "text/uri-list;class=java.io.InputStream;charset=UTF-8", "text/plain;class=java.io.InputStream;charset=windows-1252", "text/uri-list;class=java.io.InputStream;charset=windows-1252", "application/x-java-url;class=java.net.URL", "text/plain;class=java.io.Reader", "text/plain;charset=windows-1252", "text/uri-list;class=java.io.Reader", "text/uri-list;charset=windows-1252", "text/plain;charset=UTF-8", "text/uri-list;charset=UTF-8", "text/plain;class=java.io.InputStream;charset=US-ASCII", "text/uri-list;class=java.io.InputStream;charset=US-ASCII", "text/plain;class=java.io.InputStream;charset=UTF-16LE", "text/plain;charset=US-ASCII", "text/uri-list;class=java.io.InputStream;charset=UTF-16LE", "text/uri-list;charset=US-ASCII", "text/plain;charset=UTF-16LE", "text/uri-list;charset=UTF-16LE", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16BE", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16BE", "text/plain;class=java.nio.ByteBuffer;charset=ISO-8859-1", "text/uri-list;class=java.nio.ByteBuffer;charset=ISO-8859-1", "text/plain", "text/uri-list", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16", "text/plain;class=java.io.InputStream;charset=unicode", "text/uri-list;class=java.io.InputStream;charset=UTF-16", "text/plain;class=java.nio.CharBuffer", "text/uri-list;class=java.nio.CharBuffer", "text/plain;class=java.lang.String", "text/plain;charset=UTF-16BE", "text/uri-list;class=java.lang.String", "text/uri-list;charset=UTF-16BE", "text/plain;charset=ISO-8859-1", "text/uri-list;charset=ISO-8859-1", "text/plain;class=java.io.InputStream;charset=UTF-16BE", "text/uri-list;class=java.io.InputStream;charset=UTF-16BE", "text/plain;class=java.nio.ByteBuffer;charset=US-ASCII", "text/uri-list;class=java.nio.ByteBuffer;charset=US-ASCII", "text/plain;class=java.io.InputStream;charset=ISO-8859-1", "text/uri-list;class=java.io.InputStream;charset=ISO-8859-1", "text/plain;charset=UTF-16", "text/plain;class=java.nio.ByteBuffer;charset=windows-1252", "text/uri-list;charset=UTF-16", "text/uri-list;class=java.nio.ByteBuffer;charset=windows-1252", "text/plain;class=java.io.InputStream;charset=windows-1252", "text/uri-list;class=java.io.InputStream;charset=windows-1252" };
    DataFlavor[] flavors = new DataFlavor[mimes.length];
    for (int i = 0; i < flavors.length; i++) {
        flavors[i] = new DataFlavor(mimes[i]);
    }
    testComparator(new DataTransferer.DataFlavorComparator(true), flavors);
    testComparator(new DataTransferer.DataFlavorComparator(false), flavors);
}
Also used : DataTransferer(sun.awt.datatransfer.DataTransferer) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 50 with DataFlavor

use of java.awt.datatransfer.DataFlavor in project SAGU by brianmcmichael.

the class FileDrop method isDragOk.

// end dropListener
/**
     * 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++;
    }
    // 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());
    }
    return ok;
}
Also used : DataFlavor(java.awt.datatransfer.DataFlavor)

Aggregations

DataFlavor (java.awt.datatransfer.DataFlavor)53 Transferable (java.awt.datatransfer.Transferable)13 IOException (java.io.IOException)13 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)11 List (java.util.List)11 JPanel (javax.swing.JPanel)11 JLabel (javax.swing.JLabel)9 ArrayList (java.util.ArrayList)8 Point (java.awt.Point)7 Clipboard (java.awt.datatransfer.Clipboard)6 File (java.io.File)6 NamedIcon (jmri.jmrit.catalog.NamedIcon)6 URL (java.net.URL)4 DragJLabel (jmri.jmrit.catalog.DragJLabel)4 InputStream (java.io.InputStream)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 BorderLayout (java.awt.BorderLayout)2 GraphicsConfiguration (java.awt.GraphicsConfiguration)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2