Example usage for java.awt.datatransfer DataFlavor stringFlavor

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

Introduction

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

Prototype

DataFlavor stringFlavor

To view the source code for java.awt.datatransfer DataFlavor stringFlavor.

Click Source Link

Document

The DataFlavor representing a Java Unicode String class, where:
 representationClass = java.lang.String mimeType            = "application/x-java-serialized-object" 

Usage

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;/* w  w w. j  a v  a 2  s  .  com*/
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(clipboard.getData(DataFlavor.stringFlavor));
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    System.out.println(clipboard.getName());

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;//from w  w  w.  j  a va2s  .c o m
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    Clipboard myClipboard = new Clipboard("name");

    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;//from ww  w.j  a  v  a2s  .  co m
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(clipboard.getData(DataFlavor.stringFlavor));
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    DataFlavor[] fla = clipboard.getAvailableDataFlavors();
    for (DataFlavor f : fla) {
        System.out.println(f);/* w  w  w  . ja  v  a  2 s.  c om*/
    }

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    FlavorListener lis = new FlavorListener() {
        @Override/*from w ww  .  j ava  2 s  . c  om*/
        public void flavorsChanged(FlavorEvent e) {
            System.out.println(e);
        }
    };
    clipboard.addFlavorListener(lis);
    clipboard.removeFlavorListener(lis);
    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    FlavorListener lis = new FlavorListener() {
        @Override/*from  ww w.ja  v  a  2  s  .c o  m*/
        public void flavorsChanged(FlavorEvent e) {
            System.out.println(e);
        }
    };
    clipboard.addFlavorListener(lis);
    FlavorListener[] flavors = clipboard.getFlavorListeners();
    for (FlavorListener f : flavors) {
        System.out.println(f);
    }

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public boolean canImport(JComponent com, DataFlavor[] dataFlavors) {
    for (int i = 0; i < dataFlavors.length; i++) {
        DataFlavor flavor = dataFlavors[i];
        if (flavor.equals(DataFlavor.javaFileListFlavor)) {
            System.out.println("canImport: JavaFileList FLAVOR: " + flavor);
            return true;
        }//from  w ww .  ja va2  s  .c o  m
        if (flavor.equals(DataFlavor.stringFlavor)) {
            System.out.println("canImport: String FLAVOR: " + flavor);
            return true;
        }
        System.err.println("canImport: Rejected Flavor: " + flavor);
    }
    return false;
}

From source file:coolmap.canvas.action.PasteRowNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*from w w  w  . j  a  va 2  s  .c om*/
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        ArrayList<Range<Integer>> selectedRows = obj.getCoolMapView().getSelectedRows();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedRows != null && !selectedRows.isEmpty()) {
            insertionIndex = selectedRows.get(0).lowerEndpoint();
            //System.out.println(lower);

        } //else
        else {
            //append at beginning

        }

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(0, insertionIndex, 1, 1);
        if (obj.getCoolMapView().getSelectedColumns() != null
                && !obj.getCoolMapView().getSelectedColumns().isEmpty()) {
            centerTo.x = ((Range<Integer>) (obj.getCoolMapView().getSelectedColumns().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateRows("Insert Row Nodes", obj, null);
        obj.insertRowNodes(insertionIndex, newNodes, true);
        obj.getCoolMapView().centerToRegion(centerTo);
        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        System.err.println("Exception in pasting rows:" + ex);
    }
}

From source file:Clipboard.java

/**
* Get the String residing on the clipboard.
*
* @return any text found on the Clipboard; if none found, return an
* empty String.//  w w  w .j ava 2s.c  om
*/
public String getClipboardContents() {
    String result = "";
    java.awt.datatransfer.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);
            ex.printStackTrace();
        } catch (IOException ex) {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }
    return result;
}

From source file:coolmap.canvas.action.PasteColumnNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {// w w w  .j  av a 2  s  .c  o  m
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        System.out.println(json);

        //System.out.println(((JMenuItem)(e.getSource())).getParent());
        ArrayList<Range<Integer>> selectedColumns = obj.getCoolMapView().getSelectedColumns();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedColumns != null && !selectedColumns.isEmpty()) {
            insertionIndex = selectedColumns.get(0).lowerEndpoint();

        } //else

        System.out.println(insertionIndex);

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(insertionIndex, 0, 1, 1);
        if (obj.getCoolMapView().getSelectedRows() != null
                && !obj.getCoolMapView().getSelectedRows().isEmpty()) {
            centerTo.y = ((Range<Integer>) (obj.getCoolMapView().getSelectedRows().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateColumns("Insert Column Nodes", obj, null);
        obj.insertColumnNodes(insertionIndex, newNodes, true);
        //need to center to inserted
        obj.getCoolMapView().centerToRegion(centerTo);

        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        //Return
        System.err.println("Exception in pasting columns:" + ex);
    }
}