Example usage for java.awt.datatransfer DataFlavor getTextPlainUnicodeFlavor

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

Introduction

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

Prototype

public static final DataFlavor getTextPlainUnicodeFlavor() 

Source Link

Document

Returns a DataFlavor representing plain text with Unicode encoding, where:
 representationClass = java.io.InputStream mimeType            = "text/plain; charset=<platform default Unicode encoding>" 

Usage

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df = DataFlavor.stringFlavor;

    System.out.println(df.getTextPlainUnicodeFlavor());
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public NodeListTransferable(ArrayList nodeList, ArrayList fields, SpreadSheet spreadSheet, int[] rows,
        int[] cols, boolean nodeSelection) {
    this.nodeSelection = nodeSelection;
    try {/*from  www  .  java  2  s . co m*/
        nodeListDataFlavor = new DataFlavor(NODE_LIST_MIME_TYPE);
    } catch (ClassNotFoundException e) {
    }
    if (nodeSelection) {
        flavors = new DataFlavor[] { nodeListDataFlavor, DataFlavor.stringFlavor,
                DataFlavor.getTextPlainUnicodeFlavor() }; //TODO isRepresentationClassReader(||InputStream)||isFlavorTextType+flavor.getReaderForText()
        this.nodeList = nodeList;
        this.fields = fields;
    } else {
        flavors = new DataFlavor[] { DataFlavor.stringFlavor, DataFlavor.getTextPlainUnicodeFlavor() }; //TODO isRepresentationClassReader(||InputStream)||isFlavorTextType+flavor.getReaderForText()
        //sdata=nodeListToString(nodeList,spreadSheet,fields);
    }
    flavorSet = new HashSet();
    //Collections.addAll(flavorSet,flavors); //jdk 1.5
    //for (int i=0;i<flavors.length;i++) flavorSet.add(flavors[i]);
    CollectionUtils.addAll(flavorSet, flavors); //replaced JDK 1.5 code with this call
    this.spreadsheet = spreadSheet;
    this.rows = rows;
    this.cols = cols;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!flavorSet.contains(flavor))
        throw new UnsupportedFlavorException(flavor);
    if (nodeListDataFlavor.equals(flavor)) {
        NodeModel model = ((CommonSpreadSheetModel) spreadsheet.getModel()).getCache().getModel();
        //         ArrayList nl=nodeList;
        //         nodeList=new ArrayList(nl.size());
        //         nodeList.addAll(model.copy(nl,NodeModel.SILENT));
        return model.copy(nodeList, NodeModel.SILENT);
    } else if (DataFlavor.stringFlavor.equals(flavor))
        return selectionToString(spreadsheet, rows, cols);
    //          return (sdata==null)?nodeListToString(nodeList,spreadsheet,fields):sdata;
    else if (DataFlavor.getTextPlainUnicodeFlavor().equals(flavor))
        return new StringReader(selectionToString(spreadsheet, rows, cols));
    //return new StringReader((sdata==null)?nodeListToString(nodeList,spreadsheet,fields):sdata);
    else/*from  w  w w  .  jav  a2  s . co m*/
        throw new UnsupportedFlavorException(flavor);
}

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

/**
 * @return the plain text flavor from the clipboard
 *//*  www. jav a2  s. c o 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:org.languagetool.gui.Main.java

private String getClipboardText() {
    // get text from clipboard or selection:
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
    if (clipboard == null) { // on Windows
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }/*from w  w  w  .j  a  v a 2  s.co  m*/
    String s;
    Transferable data = clipboard.getContents(this);
    try {
        if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
            DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
            try (Reader sr = df.getReaderForText(data)) {
                s = StringTools.readerToString(sr);
            }
        } else {
            s = "";
        }
    } catch (Exception ex) {
        s = data.toString();
    }
    return s;
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public TransferHandler dragRows(final JTable table, final List<String> specs) {
    TransferHandler th = null;//  w  ww .  ja v  a2s . co m
    try {
        final DataFlavor ndf = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
        final DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
        final String charset = df.getParameter("charset");
        final Transferable transferable = new Transferable() {
            @Override
            public Object getTransferData(DataFlavor arg0) throws UnsupportedFlavorException, IOException {
                if (arg0.equals(ndf)) {
                    int[] rr = currentRowSelection; //table.getSelectedRows();
                    List<String> selseq = new ArrayList<String>(rr.length);
                    for (int r : rr) {
                        int i = table.convertRowIndexToModel(r);
                        selseq.add(specs.get(i));
                    }
                    return selseq;
                } else {
                    String ret = "";//makeCopyString();
                    for (int r = 0; r < table.getRowCount(); r++) {
                        Object o = table.getValueAt(r, 0);
                        if (o != null) {
                            ret += o.toString();
                        } else {
                            ret += "";
                        }
                        for (int c = 1; c < table.getColumnCount(); c++) {
                            o = table.getValueAt(r, c);
                            if (o != null) {
                                ret += "\t" + o.toString();
                            } else {
                                ret += "\t";
                            }
                        }
                        ret += "\n";
                    }
                    //return arg0.getReaderForText( this );
                    return new ByteArrayInputStream(ret.getBytes(charset));
                }
                //return ret;
            }

            @Override
            public DataFlavor[] getTransferDataFlavors() {
                return new DataFlavor[] { df, ndf };
            }

            @Override
            public boolean isDataFlavorSupported(DataFlavor arg0) {
                if (arg0.equals(df) || arg0.equals(ndf)) {
                    return true;
                }
                return false;
            }
        };

        th = new TransferHandler() {
            private static final long serialVersionUID = 1L;

            public int getSourceActions(JComponent c) {
                return TransferHandler.COPY_OR_MOVE;
            }

            public boolean canImport(TransferHandler.TransferSupport support) {
                return true;
            }

            protected Transferable createTransferable(JComponent c) {
                currentRowSelection = table.getSelectedRows();

                return transferable;
            }

            public boolean importData(TransferHandler.TransferSupport support) {
                try {
                    System.err.println(table.getSelectedRows().length);

                    DataFlavor[] dfs = support.getDataFlavors();
                    if (support.isDataFlavorSupported(ndf)) {
                        Object obj = support.getTransferable().getTransferData(ndf);
                        ArrayList<String> seqs = (ArrayList<String>) obj;

                        /*ArrayList<String> newlist = new ArrayList<String>( serifier.lgse.size() );
                        for( int r = 0; r < table.getRowCount(); r++ ) {
                           int i = table.convertRowIndexToModel(r);
                           newlist.add( specs.get(i) );
                        }
                        serifier.lgseq.clear();
                        serifier.lgseq = newlist;*/

                        Point p = support.getDropLocation().getDropPoint();
                        int k = table.rowAtPoint(p);

                        specs.removeAll(seqs);
                        for (String s : seqs) {
                            specs.add(k++, s);
                        }

                        TableRowSorter<TableModel> trs = (TableRowSorter<TableModel>) table.getRowSorter();
                        trs.setSortKeys(null);

                        table.tableChanged(new TableModelEvent(table.getModel()));

                        return true;
                    } /* else if( support.isDataFlavorSupported( df ) ) {                     
                        Object obj = support.getTransferable().getTransferData( df );
                        InputStream is = (InputStream)obj;
                                
                        System.err.println( charset );
                        importReader( new BufferedReader(new InputStreamReader(is, charset)) );
                                
                        updateView();
                                
                        return true;
                      }  else if( support.isDataFlavorSupported( DataFlavor.stringFlavor ) ) {                     
                        Object obj = support.getTransferable().getTransferData( DataFlavor.stringFlavor );
                        String str = (String)obj;
                        importReader( new BufferedReader( new StringReader(str) ) );
                                
                        updateView();
                                
                        return true;
                      }*/
                } catch (UnsupportedFlavorException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return false;
            }
        };
    } catch (Exception e) {
        e.printStackTrace();
    }
    return th;
}