Example usage for java.awt.datatransfer DataFlavor DataFlavor

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

Introduction

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

Prototype

public DataFlavor(String mimeType) throws ClassNotFoundException 

Source Link

Document

Constructs a DataFlavor from a mimeType string.

Usage

From source file:Main.java

public static void main(String[] args) {

    try {/*from   w w w  .  j a v a2s.c om*/
        DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

static DataFlavor newDataFlavor(final String mimeType) {
    try {/*www  . java  2 s  . c  o  m*/
        return new DataFlavor(mimeType);
    } catch (final ClassNotFoundException e) {
        throw new IllegalArgumentException("Cannot create data flavor for " + mimeType, e);
    }
}

From source file:com.codecrate.shard.ui.dragdrop.FileTransferHandler.java

public FileTransferHandler() {
    fileDataFlavor = DataFlavor.javaFileListFlavor;
    try {/*from   ww w .  j ava2  s  . c  om*/
        uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}

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

public RtfSelection(String s) {
    content = s;/*from w  w w . j a  v a2 s  .  c  o m*/
    try {
        rtfFlavor = new DataFlavor("text/rtf; class=java.io.InputStream");
        supportedFlavors = new DataFlavor[] { rtfFlavor, DataFlavor.stringFlavor };
    } catch (ClassNotFoundException ex) {
        LOGGER.warn("Cannot find class", ex);
    }
}

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 {//w ww .  j a  v  a  2  s .  c  o m
        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:net.sf.jabref.gui.fieldeditors.FileListEditorTransferHandler.java

/**
 *
 * @param frame//ww w. j a  v a  2  s.  c o m
 * @param entryContainer
 * @param textTransferHandler is an instance of javax.swing.plaf.basic.BasicTextUI.TextTransferHandler. That class is not visible. Therefore, we have to "cheat"
 */
public FileListEditorTransferHandler(JabRefFrame frame, EntryContainer entryContainer,
        TransferHandler textTransferHandler) {
    this.frame = frame;
    this.entryContainer = entryContainer;
    this.textTransferHandler = textTransferHandler;
    stringFlavor = DataFlavor.stringFlavor;
    try {
        urlFlavor = new DataFlavor("application/x-java-url; class=java.net.URL");
    } catch (ClassNotFoundException e) {
        LOGGER.info("Unable to configure drag and drop for file link table", e);
    }
}

From source file:DnDDemo2.java

public TextColor(String text, Color color) {
    String colorMimeType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.awt.Color";
    DataFlavor colorFlavor = null;
    try {/* ww  w .ja va  2  s.  c  o  m*/
        colorFlavor = new DataFlavor(colorMimeType);
    } catch (ClassNotFoundException e) {
    }
    flavors = new DataFlavor[2];
    flavors[0] = DataFlavor.stringFlavor;
    flavors[1] = colorFlavor;
    this.text = text;
    this.color = color;
}

From source file:edu.clemson.cs.nestbed.client.gui.ProgramTreeTransferHandler.java

public ProgramTreeTransferHandler() throws ClassNotFoundException {
    log.debug("ProgramTreeTransferHandler created.");

    localProgramFlavor = new DataFlavor(localProgramType);
    localProgramSymbolFlavor = new DataFlavor(localProgramSymbolType);
    localProgramMessageSymbolFlavor = new DataFlavor(localProgramMessageSymbolType);

    serialProgramFlavor = new DataFlavor(Program.class, "Program");
    serialProgramSymbolFlavor = new DataFlavor(ProgramSymbol.class, "ProgramSymbol");
    serialProgramMessageSymbolFlavor = new DataFlavor(ProgramMessageSymbol.class, "ProgramMessageSymbol");
}

From source file:net.sf.jabref.gui.entryeditor.SimpleUrlDragDrop.java

@Override
public void drop(DropTargetDropEvent event) {
    Transferable tsf = event.getTransferable();
    event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    //try with an URL
    DataFlavor dataFlavor = null;
    try {//from  w ww . ja va2  s  .c  o  m
        dataFlavor = new DataFlavor("application/x-java-url; class=java.net.URL");
    } catch (ClassNotFoundException e) {
        LOGGER.warn("Could not find DropTargetDropEvent class", e);
    }
    try {
        URL url = (URL) tsf.getTransferData(dataFlavor);
        //insert URL
        editor.setText(url.toString());
        storeFieldAction.actionPerformed(new ActionEvent(editor, 0, ""));
    } catch (UnsupportedFlavorException nfe) {
        // if not an URL
        JOptionPane.showMessageDialog((Component) editor, Localization.lang("Operation not supported"),
                Localization.lang("Drag and Drop Error"), JOptionPane.ERROR_MESSAGE);
        LOGGER.warn("Could not perform drage and drop", nfe);
    } catch (IOException ioex) {
        LOGGER.warn("Could not perform drage and drop", ioex);
    }
}

From source file:SerialTransferTest.java

/**
 * Pastes the color from the system clipboard into the chooser.
 *//*from  w w  w  . j  a va2s.c  om*/
private void paste() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        DataFlavor flavor = new DataFlavor("application/x-java-serialized-object;class=java.awt.Color");
        if (clipboard.isDataFlavorAvailable(flavor)) {
            Color color = (Color) clipboard.getData(flavor);
            chooser.setColor(color);
        }
    } catch (ClassNotFoundException e) {
        JOptionPane.showMessageDialog(this, e);
    } catch (UnsupportedFlavorException e) {
        JOptionPane.showMessageDialog(this, e);
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, e);
    }
}