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:com.egangotri.transliteratorAsSwing.TransliteratorJFrame.java

public void copyToClipBoard(String source) {
    Clipboard clipboard;//  w  w w. j ava 2  s .  c  o m
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable content = clipboard.getContents(this);
    try {
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        StringSelection contents;
        if ("cb1".equalsIgnoreCase(source))
            contents = new StringSelection(tb1.getText());
        else if ("cb2".equalsIgnoreCase(source))
            contents = new StringSelection(tb2.getText());
        else
            contents = new StringSelection(tb3.getText());
        clipboard.setContents(contents, this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.igormaznitsa.sciareto.ui.editors.mmeditors.NoteEditor.java

private void buttonPasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPasteActionPerformed
    try {//from   ww  w.  ja v  a2 s.  co m
        this.editorPane.replaceSelection(
                (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor));
    } catch (UnsupportedFlavorException ex) {
        // no text data in clipboard
    } catch (IOException ex) {
        LOGGER.error("Error during paste from clipboard", ex); //NOI18N
    }
}

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

public static void pasteSpec(RuntimeBean runtime)
        throws IOException, URISyntaxException, UnsupportedFlavorException, ParseException {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clipboard.getContents(null);
    if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        String json = (String) contents.getTransferData(DataFlavor.stringFlavor);
        JSONObject jspec = (JSONObject) mParser.parse(json);
        AppSpecBean spec = FromJSONLogic.fromJSONAppSpec(jspec);
        selectMRU(runtime, spec);/*from w ww  .ja  v  a2s. c o  m*/
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchDistanceFrame.java

private void pasteFromClipboard() {
    try {//from   w w  w. ja va2 s .c o m
        Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
        List<Village> villages = PluginManager.getSingleton()
                .executeVillageParser((String) t.getTransferData(DataFlavor.stringFlavor));//VillageParser.parse((String) t.getTransferData(DataFlavor.stringFlavor));
        if (villages == null || villages.isEmpty()) {
            showError("Es konnten keine Dorfkoodinaten in der Zwischenablage gefunden werden.");
            return;
        } else {
            //jDistanceTable.invalidate();
            for (Village v : villages) {
                DistanceManager.getSingleton().addVillage(v);
            }
            ((DistanceTableModel) jDistanceTable.getModel()).fireTableStructureChanged();
            resetView(false);
        }
        showSuccess(villages.size() + ((villages.size() == 1) ? " Dorf " : " Drfer ")
                + "aus der Zwischenablage eingefgt");
    } catch (Exception e) {
        logger.error("Failed to paste villages from clipboard", e);
        showError("Fehler beim Einfgen aus der Zwischenablage");
    }
}

From source file:view.App.java

private void initGUI() {
    try {//from  w  w  w  .ja  va2  s.  co  m
        {
            jPanel1 = new JPanel();
            BorderLayout jPanel1Layout = new BorderLayout();
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.CENTER);
            jPanel1.setPreferredSize(new java.awt.Dimension(901, 398));
            {
                jPanel2 = new JPanel();
                BoxLayout jPanel2Layout = new BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS);
                jPanel2.setLayout(jPanel2Layout);
                jPanel1.add(jPanel2, BorderLayout.WEST);
                jPanel2.setPreferredSize(new java.awt.Dimension(292, 446));
                {
                    jPanel5 = new JPanel();
                    jPanel2.add(jPanel5);
                    jPanel5.setPreferredSize(new java.awt.Dimension(292, 109));
                    {
                        {
                            jTextArea1 = new JTextArea();
                            jTextArea1.setWrapStyleWord(true);
                            jTextArea1.setLineWrap(true);
                            DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret();
                            caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

                            jTextArea1.addFocusListener(new FocusAdapter() {
                                public void focusGained(FocusEvent evt) {

                                    if (jTable1.getModel().getRowCount() == 0 && !jButton1.isEnabled()) {
                                        jButton1.setEnabled(true);
                                        jTextArea1.setText("");
                                    }

                                }
                            });
                            JScrollPane sp = new JScrollPane();
                            sp.setPreferredSize(new java.awt.Dimension(281, 97));
                            sp.setViewportView(jTextArea1);

                            jPanel5.add(sp, BorderLayout.CENTER);
                        }
                    }

                }
                {
                    jPanel4 = new JPanel();
                    jPanel2.add(jPanel4);
                    FlowLayout jPanel4Layout = new FlowLayout();
                    jPanel4Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel4.setPreferredSize(new java.awt.Dimension(292, 45));
                    jPanel4.setSize(102, 51);
                    jPanel4.setLayout(jPanel4Layout);
                    {
                        jButton1 = new JButton();
                        jPanel4.add(jButton1);
                        jButton1.setText("Get Quotes");
                        jButton1.setSize(100, 50);
                        jButton1.setPreferredSize(new java.awt.Dimension(100, 26));
                        jButton1.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                //   
                                String tickerStr = jTextArea1.getText();
                                if (tickerStr.equals("") || tickerStr.equals(null)
                                        || tickerStr.equals(" ")) {
                                    jTextArea1.setText(" ");
                                    return;
                                }
                                StringTokenizer tokenizer = new StringTokenizer(tickerStr, " ");
                                String[] tickers = new String[tokenizer.countTokens()];
                                int i = 0;
                                while (tokenizer.hasMoreTokens()) {
                                    tickers[i] = tokenizer.nextToken();
                                    i++;
                                }
                                try {
                                    Controller.getQuotes(tickers);
                                } catch (CloneNotSupportedException e) {
                                    JOptionPane.showMessageDialog(jPanel1, "   ");
                                }
                                jButton1.setEnabled(false);
                            }
                        });
                    }
                }
                {
                    jPanel6 = new JPanel();
                    BorderLayout jPanel6Layout = new BorderLayout();
                    jPanel6.setLayout(jPanel6Layout);
                    jPanel2.add(jPanel6);
                    {
                        jScrollPane1 = new JScrollPane();
                        jPanel6.add(jScrollPane1, BorderLayout.CENTER);
                        jScrollPane1.setPreferredSize(new java.awt.Dimension(292, 341));
                        {
                            TableModel jTable1Model = new DefaultTableModel(null,
                                    new String[] { "", "MA Value", "", "MA Value" });
                            jTable1 = new JTable();

                            jScrollPane1.setViewportView(jTable1);
                            jTable1.setModel(jTable1Model);
                            jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

                        }
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jPanel1.add(jPanel3, BorderLayout.CENTER);
                {
                    //                  chart = ChartFactory.createLineChart(" ", "dates", "correlation ratio", null, 
                    //                        PlotOrientation.VERTICAL, true, true, false);
                    //                  ChartPanel chartPanel = new ChartPanel(chart);
                    //                  chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );
                    //                  jPanel3.add(chartPanel);
                }
                {

                }
            }
        }
        this.setSize(966, 531);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenu3.setText("File");
                {
                    //                  newFileMenuItem = new JMenuItem();
                    //                  jMenu3.add(newFileMenuItem);
                    //                  newFileMenuItem.setText("New");
                    //                  newFileMenuItem.addActionListener(new ActionListener() {
                    //                     public void actionPerformed(ActionEvent evt) {
                    ////                        jTextArea1.setText("");
                    ////                        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
                    ////                        model.setRowCount(0);
                    ////                        Controller.clearPortfolio();
                    //                     }
                    //                  });
                }
                {
                    jSeparator2 = new JSeparator();
                    jMenu3.add(jSeparator2);
                }
                {
                    exitMenuItem = new JMenuItem();
                    jMenu3.add(exitMenuItem);
                    exitMenuItem.setText("Exit");
                    exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            int action = JOptionPane.showConfirmDialog(jPanel1,
                                    "     ?", "Confirm Exit",
                                    JOptionPane.OK_CANCEL_OPTION);

                            if (action == JOptionPane.OK_OPTION)
                                System.exit(0);

                        }
                    });
                }
            }
            {
                jMenu4 = new JMenu();
                jMenuBar1.add(jMenu4);
                jMenu4.setText("Edit");
                {
                    cutMenuItem = new JMenuItem();
                    jMenu4.add(cutMenuItem);
                    cutMenuItem.setText("Cut");
                    cutMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);
                            jTextArea1.setText("");

                        }
                    });
                }
                {
                    copyMenuItem = new JMenuItem();
                    jMenu4.add(copyMenuItem);
                    copyMenuItem.setText("Copy");
                    copyMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);

                        }
                    });
                }
                {
                    pasteMenuItem = new JMenuItem();
                    jMenu4.add(pasteMenuItem);
                    pasteMenuItem.setText("Paste");
                    pasteMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            try {
                                String data = (String) clp.getData(DataFlavor.stringFlavor);
                                jTextArea1.setText(data);
                            } catch (UnsupportedFlavorException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            } catch (IOException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        }
                    });
                }
            }
            {
                jMenu5 = new JMenu();
                jMenuBar1.add(jMenu5);
                jMenu5.setText("Help");
                {
                    helpMenuItem = new JMenuItem();
                    jMenu5.add(helpMenuItem);
                    helpMenuItem.setText("About");
                    helpMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            JOptionPane.showMessageDialog(jPanel1,
                                    "    .    r.zhumagulov@gmail.com",
                                    "About", JOptionPane.PLAIN_MESSAGE);

                        }
                    });
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.kstenschke.copypastestack.ToolWindow.java

/**
 * Refresh listed items from distinct merged sum of:
 * 0. option to preview the current clipboard contents
 * 1. previous clipboard items still in prefs
 * 2. current clipboard items//  ww w .j  av  a  2  s  .c  o  m
 */
private void refreshClipboardList() {
    Transferable[] copiedItems = CopyPasteManager.getInstance().getAllContents();
    int amountItems = UtilsClipboard.getAmountStringItemsInTransferables(copiedItems);
    String[] itemsUnique = null;
    boolean hasClipboardContent = UtilsClipboard.hasContent();

    String[] copyItemsList = new String[amountItems];
    if (amountItems > 0 || hasClipboardContent) {
        // Add copied string items, historic and current
        int index = 0;
        for (Transferable currentItem : copiedItems) {
            if (currentItem.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                try {
                    String itemStr = currentItem.getTransferData(DataFlavor.stringFlavor).toString();
                    if (!itemStr.trim().isEmpty()) {
                        copyItemsList[index] = itemStr;
                        index++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        // Tidy items: distinct items, none empty
        String[] copyItemsPref = Preferences.getItems();
        Object[] allItems = (copyItemsPref.length > 0) ? ArrayUtils.addAll(copyItemsList, copyItemsPref)
                : copyItemsList;
        itemsUnique = UtilsArray.tidy(allItems);
        if (itemsUnique.length > 0) {
            this.setClipboardListData(itemsUnique, false);
            this.sortClipboardListByTags(this.form.checkboxKeepSorted.isSelected());

            Preferences.saveCopyItems(itemsUnique);
        }
    }

    initStatusLabel(itemsUnique == null ? 0 : itemsUnique.length);
}

From source file:com.pironet.tda.TDA.java

private void getLogfileFromClipboard() {
    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    String text = null;//from   w w w . j a  v  a 2  s.com

    try {
        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            text = (String) t.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        ex.printStackTrace();
    }

    if (text != null) {
        if (topNodes == null) {
            initDumpDisplay(text);
        } else {
            addDumpStream(new ByteArrayInputStream(text.getBytes()),
                    "Clipboard at " + new Date(System.currentTimeMillis()), false);
            addToLogfile(text);
            if (this.getRootPane() != null) {
                this.getRootPane().revalidate();
            }
            displayContent(null);
        }

        if (!this.runningAsVisualVMPlugin) {
            getMainMenu().getFindLRThreadsToolBarButton().setEnabled(true);
            getMainMenu().getExpandButton().setEnabled(true);
            getMainMenu().getCollapseButton().setEnabled(true);
        }
    }
}

From source file:Samples.Advanced.GraphEditorDemo.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 a v a 2  s.co m
*/
public String getClipboardContents() {
    String result = "";
    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:com.igormaznitsa.nbmindmap.nb.swing.PlainTextEditor.java

private void buttonPasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPasteActionPerformed
    try {//from   w w  w . j  a v a  2  s .c  o  m
        this.lastEditor.replaceSelection(
                (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor));
    } catch (UnsupportedFlavorException ex) {
        // no text data in clipboard
    } catch (IOException ex) {
        LOGGER.error("Error during paste from clipboard", ex); //NOI18N
    }

}

From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java

private void pasteSelectionFromClipboard() {
    int startRow = (m_TestRequirementTable.getSelectedRows())[0];
    int startCol = (m_TestRequirementTable.getSelectedColumns())[0];
    try {//  w w  w.  j av a  2s. c o  m
        String clipboardContent = (String) (m_systemClipboard.getContents(this)
                .getTransferData(DataFlavor.stringFlavor));
        StringTokenizer tokenizerRow = new StringTokenizer(clipboardContent, "\n");
        for (int i = 0; tokenizerRow.hasMoreTokens(); i++) {
            String rowString = tokenizerRow.nextToken();
            StringTokenizer tokenizerTab = new StringTokenizer(rowString, "\t");
            for (int j = 0; tokenizerTab.hasMoreTokens(); j++) {
                String value = tokenizerTab.nextToken();
                int row = startRow + i;
                int col = startCol + j;
                // add new row if necessary
                if (row == m_TestRequirementTable.getRowCount()) {
                    addNewRow();
                }
                if (col < m_TestRequirementTable.getColumnCount()) {
                    m_TestRequirementTable.setValueAt(value, row, col);
                }
            }
        }
    } catch (Exception e) {
        logger.warn("Error while pasting clipboard content into test requirement editor", e);
    }
}