Example usage for java.awt.datatransfer DataFlavor isMimeTypeEqual

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

Introduction

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

Prototype

private boolean isMimeTypeEqual(MimeType mtype) 

Source Link

Document

Compares the mimeType of two DataFlavor objects.

Usage

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

    System.out.println("df1 equals df2: " + df1.isMimeTypeEqual("Plain ASCII text"));
}

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

    DataFlavor df2 = new DataFlavor(java.awt.Button.class, "AWT Button");

    System.out.println("df1 equals df2: " + df1.isMimeTypeEqual(df2));
}

From source file:MainClass.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

    DataFlavor df2 = new DataFlavor(java.awt.Button.class, "AWT Button");

    System.out.println("Mime type: " + df2.getMimeType());
    System.out.println("Primary type: " + df2.getPrimaryType());
    System.out.println("Subtype: " + df2.getSubType());
    System.out.println("Name: " + df2.getHumanPresentableName());
    String s = df2.getRepresentationClass().toString();
    System.out.println("Representation class: " + s + "\n");

    System.out.println("df1 equals df2: " + df1.isMimeTypeEqual(df2));
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @return the plain text flavor from the clipboard
 *///  w ww.  j a  v a2 s.  co m
public static String getTextFromClipboard() {
    Clipboard sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    for (DataFlavor flavor : sysClipboard.getAvailableDataFlavors()) {
        if (flavor.isMimeTypeEqual(DataFlavor.getTextPlainUnicodeFlavor())) {
            try {
                StringBuilder sb = new StringBuilder();
                Object dataObj = sysClipboard.getData(flavor);
                if (dataObj instanceof String) {
                    sb.append((String) dataObj);

                } else if (dataObj instanceof InputStreamReader) {
                    Reader reader = (InputStreamReader) sysClipboard.getData(flavor);
                    char[] buffer = new char[1024];
                    int len = reader.read(buffer);
                    sb.append(new String(buffer, 0, len));

                    while (len > -1) {
                        len = reader.read(buffer);
                        if (len > 0) {
                            sb.append(buffer);
                        }
                    }
                }

                if (sb.length() > 0) {
                    return sb.toString();
                }

            } catch (Exception ex) {
                ex.printStackTrace();
            }
            break;
        }
    }
    return null;
}

From source file:tk.tomby.tedit.core.Workspace.java

/**
 * Creates a new WorkSpace object.// w  ww.jav  a2 s.c o m
 */
public Workspace() {
    super();

    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    MessageManager.addMessageListener(MessageManager.BUFFER_GROUP_NAME, new IMessageListener<BufferMessage>() {
        public void receiveMessage(BufferMessage message) {
            Workspace.this.receiveMessage(message);
        }
    });

    MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME,
            new IMessageListener<PreferenceMessage>() {
                public void receiveMessage(PreferenceMessage message) {
                    Workspace.this.receiveMessage(message);
                }
            });

    bufferPane = new JTabbedPane();
    bufferPane.setMinimumSize(new Dimension(600, 400));
    bufferPane.setPreferredSize(new Dimension(800, 600));
    bufferPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    bottomPort = createDockingPort(0, 80);
    rightPort = createDockingPort(80, 0);
    leftPort = createDockingPort(80, 0);

    splitPaneRight = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, bufferPane, rightPort);
    splitPaneLeft = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPort, splitPaneRight);
    splitPaneBottom = createSplitPane(JSplitPane.VERTICAL_SPLIT, splitPaneLeft, bottomPort);

    bufferPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            MessageManager
                    .sendMessage(new WorkspaceMessage(evt.getSource(), bufferPane.getSelectedComponent()));
        }
    });

    bufferPane.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                splitPaneLeft.setDividerLocation(0.0d);
                splitPaneBottom.setDividerLocation(1.0d);
                splitPaneRight.setDividerLocation(1.0d);
            }
        }
    });

    DropTarget dropTarget = new DropTarget(bufferPane, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            if (log.isDebugEnabled()) {
                log.debug("drop start");
            }

            try {
                if (log.isDebugEnabled()) {
                    log.debug(dtde.getSource());
                }

                Transferable tr = dtde.getTransferable();
                DataFlavor[] flavors = tr.getTransferDataFlavors();

                for (int i = 0; i < flavors.length; i++) {
                    DataFlavor flavor = flavors[i];

                    if (log.isDebugEnabled()) {
                        log.debug("mime-type:" + flavor.getMimeType());
                    }

                    if (flavor.isMimeTypeEqual("text/plain")) {
                        final Object obj = tr.getTransferData(flavor);

                        if (log.isDebugEnabled()) {
                            log.debug(obj);
                        }

                        if (obj instanceof String) {
                            TaskManager.execute(new Runnable() {
                                public void run() {
                                    BufferFactory factory = new BufferFactory();
                                    IBuffer buffer = factory.createBuffer();
                                    buffer.open((String) obj);

                                    addBuffer(buffer);
                                }
                            });
                        }

                        dtde.dropComplete(true);

                        return;
                    }
                }
            } catch (UnsupportedFlavorException e) {
                log.warn(e.getMessage(), e);
            } catch (IOException e) {
                log.warn(e.getMessage(), e);
            }

            dtde.rejectDrop();

            if (log.isDebugEnabled()) {
                log.debug("drop end");
            }
        }
    });

    bufferPane.setDropTarget(dropTarget);

    this.add(BorderLayout.CENTER, splitPaneBottom);
}