Example usage for java.awt.datatransfer StringSelection StringSelection

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

Introduction

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

Prototype

public StringSelection(String data) 

Source Link

Document

Creates a Transferable capable of transferring the specified String .

Usage

From source file:net.minelord.gui.panes.IRCPane.java

public void connected() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from   w  w w .  j a  v  a2s. c  om*/
        public void run() {
            scroller.setBounds(scrollerWithoutTopicWithUserlist);
            scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            status = "Connected";
            client.connectAlertListener();
            TitledBorder title = BorderFactory
                    .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Connected");
            title.setTitleJustification(TitledBorder.RIGHT);
            userList = new JList(client.getUserList().toArray());
            userScroller = new JScrollPane(userList);
            userScroller.setBounds(userScrollerWithoutTopic);
            userList.setBounds(0, 0, 210, 250);
            userList.setBackground(Color.gray);
            userList.setForeground(Color.gray.darker().darker().darker());
            userScroller.setBorder(title);
            userScroller.getVerticalScrollBar().setUnitIncrement(5);
            scroller.setBorder(BorderFactory
                    .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), ""));
            if (client.getTopic().trim().length() > 0) {
                topic = new JLabel(client.getTopic());
                scroller.setBounds(scrollerWithTopicWithUserlist);
                userScroller.setBounds(userScrollWithTopic);
                userList.setBounds(0, 0, 210, 225);
                title = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
                        "Topic set by " + client.getTopicSetter());
                title.setTitleJustification(TitledBorder.LEFT);
                topic.setBorder(title);
                topic.setBounds(topicBounds);
                add(topic);
            } else
                topic = new JLabel("");
            input.setEnabled(true);
            input.requestFocus();
            final JPopupMenu userPopup = new JPopupMenu();
            JLabel breakLine = new JLabel("____");
            JLabel help = new JLabel("Politely ask for help");
            JLabel message = new JLabel("Message");
            JLabel sortNormal = new JLabel("Normal");
            JLabel sortAlphabetical = new JLabel("Alphabetical");
            JLabel sortRoles = new JLabel("Roles");

            help.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    userPopup.setVisible(false);
                    sendMessage("/me kicks " + userList.getModel().getElementAt(userList.getSelectedIndex())
                            + " in the shins");
                    sendMessage("I need help you pleb");
                }

                public void mouseReleased(MouseEvent e) {
                }
            });
            message.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseReleased(MouseEvent paramMouseEvent) {
                    userPopup.setVisible(false);
                    input.setText("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex())
                            + (input.getText().length() > 0 && input.getText().charAt(0) == ' '
                                    ? input.getText()
                                    : " " + input.getText()));
                    input.select(0, ("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex())
                            + (input.getText().length() > 0 && input.getText().charAt(0) == ' ' ? "" : " "))
                                    .length());
                    input.requestFocus();
                }
            });
            sortNormal.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent paramMouseEvent) {
                    userPopup.setVisible(false);
                    updateUserList(0);
                }
            });
            sortAlphabetical.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent paramMouseEvent) {
                    userPopup.setVisible(false);
                    updateUserList(1);
                }
            });
            sortRoles.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent paramMouseEvent) {
                    userPopup.setVisible(false);
                    updateUserList(2);
                }
            });
            userPopup.add(help);
            userPopup.add(message);
            userPopup.add(breakLine);
            userPopup.add(sortNormal);
            userPopup.add(sortAlphabetical);
            userPopup.add(sortRoles);

            userList.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    check(e);
                }

                public void mouseReleased(MouseEvent e) {
                    check(e);
                }

                public void check(MouseEvent e) {
                    userList.setSelectedIndex(userList.locationToIndex(e.getPoint()));
                    userPopup.show(userList, e.getX(), e.getY());
                }
            });
            add(userScroller);

            final JPopupMenu textPopup = new JPopupMenu();
            JLabel copy = new JLabel("Copy");
            copy.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent paramMouseEvent) {
                    textPopup.setVisible(false);
                    if (text.getSelectedText() != null && text.getSelectedText().length() != 0) {
                        StringSelection selection = new StringSelection(text.getSelectedText());
                        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                        clipboard.setContents(selection, selection);
                    }
                }
            });
            textPopup.add(copy);
            text.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                }

                public void mouseReleased(MouseEvent e) {
                    if (SwingUtilities.isRightMouseButton(e))
                        textPopup.show(text, e.getX(), e.getY());
                }
            });
            add(userScroller);
            repaint();
        }
    });
}

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

private void bbCopySelection() {
    try {//w  ww.  j  a v  a2 s .  c o  m
        int[] rows = jWatchtowerTable.getSelectedRows();
        if (rows.length == 0) {
            return;
        }

        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]Watchturmdrfer[/size][/u]\n\n");
        } else {
            buffer.append("[u]Watchturmdrfer[/u]\n\n");
        }

        buffer.append("[table]\n");
        buffer.append("[**]Spieler[||]Dorf[||]Radius[/**]\n");

        for (int row1 : rows) {
            int row = jWatchtowerTable.convertRowIndexToModel(row1);
            int tribeCol = jWatchtowerTable.convertColumnIndexToModel(0);
            int villageCol = jWatchtowerTable.convertColumnIndexToModel(1);
            int rangeCol = jWatchtowerTable.convertColumnIndexToModel(2);
            buffer.append("[*]")
                    .append(((Tribe) jWatchtowerTable.getModel().getValueAt(row, tribeCol)).toBBCode())
                    .append("[|]")
                    .append(((Village) jWatchtowerTable.getModel().getValueAt(row, villageCol)).toBBCode())
                    .append("[|]").append(jWatchtowerTable.getModel().getValueAt(row, rangeCol));
        }

        buffer.append("[/table]");

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Wachtrme bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\n"
                            + "Trotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        String result = "Daten in Zwischenablage kopiert.";
        showSuccess(result);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        String result = "Fehler beim Kopieren in die Zwischenablage.";
        showError(result);
    }
}

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

private boolean copySelectionToInternalClipboard() {
    List<Village> selection = getSelectedElements();
    if (selection.isEmpty()) {
        showInfo("Kein Dorf ausgewhlt");
        return false;
    }//from www . j  a  v a2 s.c  o  m

    StringBuilder b = new StringBuilder();
    for (Village v : selection) {
        b.append(v.getCoordAsString()).append("\n");
    }
    try {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null);
    } catch (HeadlessException he) {
        logger.error("Failed to copy data to clipboard", he);
        showError("Fehler beim Kopieren in die Zwischenablage");
    }
    showSuccess(((selection.size() == 1) ? "Dorf" : selection.size() + " Drfer") + " in kopiert");
    return true;
}

From source file:de.mycrobase.jcloudapp.Main.java

private void setClipboard(String s) {
    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    cb.setContents(new StringSelection(s), null);

    // designated use, alert user when he could finally use the URL
    Toolkit.getDefaultToolkit().beep();
}

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

private void copyVillageAsBBCode() {
    List villageSelection = jVillageList.getSelectedValuesList();
    if (villageSelection == null || villageSelection.isEmpty()) {
        showInfo("Keine Drfer ausgewhlt");
        return;/*from   w  w  w .  j  a va  2s  .  c o m*/
    }
    try {
        List<Village> villages = new LinkedList<>();
        for (Object o : villageSelection) {
            villages.add((Village) o);
        }
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]Dorfliste[/size][/u]\n\n");
        } else {
            buffer.append("[u]Dorfliste[/u]\n\n");
        }
        buffer.append(new VillageListFormatter().formatElements(villages, extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Drfer bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        String result = "Drfer in Zwischenablage kopiert.";
        showSuccess(result);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        String result = "Fehler beim Kopieren in die Zwischenablage.";
        showError(result);
    }
}

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

private void copyDefRequests() {
    List<DefenseInformation> selection = getSelectedRows();

    if (selection.isEmpty()) {
        showInfo("Keine Eintrge gewhlt");
        return;/*from w  ww  .  ja v  a  2s.  co m*/
    }
    boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
            "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
            "Nein", "Ja") == JOptionPane.YES_OPTION);

    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    StringBuilder b = new StringBuilder();
    b.append(
            "Ich bentige die aufgelisteten oder vergleichbare Untersttzungen in den folgenden Drfern:\n\n");

    for (DefenseInformation defense : selection) {
        if (!defense.isSave()) {
            Village target = defense.getTarget();
            int needed = defense.getNeededSupports();
            int available = defense.getSupports().length;
            TroopAmountFixed split = DSWorkbenchSettingsDialog.getSingleton().getDefense();
            TroopAmountFixed need = new TroopAmountFixed();
            for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
                need.setAmountForUnit(unit, (needed - available) * split.getAmountForUnit(unit));
            }

            if (extended) {
                b.append("[table]\n");
                b.append("[**]").append(target.toBBCode()).append("[|]");
                b.append("[img]").append(UnitTableInterface.createDefenderUnitTableLink(need))
                        .append("[/img][/**]\n");
                b.append("[*]Angriffe/Fakes[|]").append(defense.getAttackCount()).append("/")
                        .append(defense.getFakeCount()).append("\n");
                b.append("[*]Zeitraum[|]").append(df.format(defense.getFirstAttack())).append(" bis ")
                        .append(df.format(defense.getLastAttack())).append("\n");
                b.append("[/table]\n");
            } else {
                b.append(buildSimpleRequestTable(target, need, defense));
            }
        }
    }
    try {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null);
        showSuccess("Untersttzungsanfragen in die Zwischenablage kopiert");
    } catch (HeadlessException hex) {
        showError("Fehler beim Kopieren in die Zwischenablage");
    }
}

From source file:com.qumasoft.guitools.compare.CompareFrame.java

void copySelectedContentsToClipboard() {
    int[] selectedRows = null;
    FileContentsListModel listModel = null;
    if (FileContentsList.getLastFocus() == file1ContentsList) {
        selectedRows = file1ContentsList.getSelectedIndices();
        listModel = file1ContentsListModel;
    } else if (FileContentsList.getLastFocus() == file2ContentsList) {
        selectedRows = file2ContentsList.getSelectedIndices();
        listModel = file2ContentsListModel;
    }/*from  w w w.j  a  va2 s.  co m*/

    if ((selectedRows != null) && (listModel != null)) {
        StringBuilder selection = new StringBuilder();
        for (int i = 0; i < selectedRows.length; i++) {
            ContentRow rowContents = listModel.getElementAt(selectedRows[i]);
            if (rowContents.getRowType() != ContentRow.ROWTYPE_BLANK) {
                selection.append(rowContents.getActualText()).append("\n");
            }
        }
        StringSelection stringSelection = new StringSelection(selection.toString());
        Toolkit screenToolkit = java.awt.Toolkit.getDefaultToolkit();
        screenToolkit.getSystemClipboard().setContents(stringSelection, stringSelection);
    }
}

From source file:net.sourceforge.pmd.cpd.GUI.java

private void copyMatchListSelectionsToClipboard() {

    int[] selectionIndices = resultsTable.getSelectedRows();
    int colCount = resultsTable.getColumnCount();

    StringBuilder sb = new StringBuilder();

    for (int r = 0; r < selectionIndices.length; r++) {
        if (r > 0) {
            sb.append('\n');
        }//from   ww w  . j  av  a2s .c  o  m
        sb.append(resultsTable.getValueAt(selectionIndices[r], 0));
        for (int c = 1; c < colCount; c++) {
            sb.append('\t');
            sb.append(resultsTable.getValueAt(selectionIndices[r], c));
        }
    }

    StringSelection ss = new StringSelection(sb.toString());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
}

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

private void transferSelectedTagsAsBBCodesToClipboard() {
    List<Tag> selection = getSelectedTags();
    if (selection.isEmpty()) {
        showInfo("Keine Gruppe ausgewhlt");
        return;//from w  ww  .j  av a2 s.c  o m
    }
    boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
            "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
            "Nein", "Ja") == JOptionPane.YES_OPTION);

    try {
        String formatted = new TagListFormatter().formatElements(selection, extended);
        StringTokenizer t = new StringTokenizer(formatted, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Gruppen bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(formatted), null);
        showSuccess("BB-Codes in die Zwischenablage kopiert");
    } catch (HeadlessException he) {
        logger.error("Failed to copy data to clipboard", he);
        showError("Fehler beim Kopieren in die Zwischenablage");
    }
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public static void copyData(Component source) {
    JTextArea textarea = (JTextArea) source;
    String s = textarea.getText();

    if (s == null || s.trim().length() == 0) {
        JOptionPane.showMessageDialog(source, "There is no data selected!");
    } else {/*from   w w  w . j av  a 2 s.c o  m*/
        StringSelection selection = new StringSelection(s);
        clipboardService.setContents(selection);
    }

    if (grabFocus) {
        source.requestFocus();
    }
}