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:Tcpbw100.java

public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    // System.err.println("Processing WINDOW event #" +event.getID());
    // System.err.println("Processing event " + source);

    if ((source == startTest) || (source == startTest2)) {
        if (f != null) {
            f.toBack();/*from w  w w.jav  a2  s  .  co  m*/
            f.dispose();
            f = null;
        }

        if (ff != null) {
            ff.toBack();
            ff.dispose();
            ff = null;
        }

        pub_errmsg = "Test in progress.";
        runtest();
    }

    else if (source == deTails) {
        deTails.setEnabled(false);
        f.setResizable(true);
        f.setVisible(true);
        deTails.setEnabled(true);
    }

    else if (source == disMiss) {
        f.toBack();
        f.dispose();
    }

    else if (source == disMiss2) {
        ff.toBack();
        ff.dispose();
    }

    else if (source == copy) {
        try {
            Clipboard clipbd = getToolkit().getSystemClipboard();
            cancopy = true;
            String s = diagnosis.getText();
            StringSelection ss = new StringSelection(s);
            clipbd.setContents(ss, ss);
            diagnosis.selectAll();
        } catch (SecurityException e) {
            cancopy = false;
        }
    }

    else if (source == copy2) {
        Clipboard clipbd = getToolkit().getSystemClipboard();
        String s = statistics.getText();
        StringSelection ss = new StringSelection(s);
        clipbd.setContents(ss, ss);
        statistics.selectAll();
    }

    else if (source == sTatistics) {
        sTatistics.setEnabled(false);
        ff.setResizable(true);
        ff.setVisible(true);
        sTatistics.setEnabled(true);
    }

    else if (source == mailTo) {
        int i;
        char key;
        String to[], from[], comments[];
        String Name, Host;

        mailTo.setEnabled(false);
        // envoke mailto: function
        showStatus(messages.getString("invokingMailtoFunction") + "...");

        results.append(messages.getString("generatingReport") + "\n");
        try {
            if ((Name = getParameter(TARGET1)) == null) {
                throw new IllegalArgumentException("U parameter Required:");
            }
            if ((Host = getParameter(TARGET2)) == null) {
                throw new IllegalArgumentException("H parameter Required:");
            }

            String theURL = "mailto:" + Name + "@" + Host;
            String subject = getParameter("subject");

            if (subject == null) {
                subject = messages.getString("troubleReportFrom") + " " + getCodeBase().getHost();
            }
            theURL += "?subject=" + subject;
            theURL += "&body=" + messages.getString("comments") + ":%0A%0A" + emailText + " "
                    + messages.getString("endOfEmail") + "\n%0A";
            // System.out.println("Message body is '" + emailText + "'\n");
            targetURL = new URL(theURL);

        } catch (MalformedURLException rsi) {
            throw new IllegalArgumentException("Can't create mailto: URL" + rsi.getMessage());
        }

        getAppletContext().showDocument(targetURL);
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void sourceToInternalClipboardAction(TRANSFER_TYPE pType) {
    int[] rows = jSourcesTable.getSelectedRows();

    if (rows == null || rows.length == 0) {
        showInfo("Keine Eintrge ausgewhlt");
        return;/*ww  w.  j a v a2  s  . c o  m*/
    }
    StringBuilder b = new StringBuilder();
    for (int row : rows) {
        Village v = (Village) jSourcesTable.getValueAt(row, 0);
        UnitHolder unit = (UnitHolder) jSourcesTable.getValueAt(row, 1);
        Boolean fake = (Boolean) jSourcesTable.getValueAt(row, 2);
        b.append(v.getId()).append(";").append(unit.getPlainName()).append(";").append(fake).append("\n");
    }
    try {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null);
        showSuccess(rows.length + ((rows.length == 1) ? " Eintrag kopiert" : " Eintrge kopiert"));
    } catch (HeadlessException hex) {
        showError("Fehler beim Kopieren der Eintrge");
        return;
    }

    if (pType.equals(TRANSFER_TYPE.CUT_SOURCE_TO_INTERNAL_CLIPBOARD)) {
        deleteAction(jSourcesTable);
        showSuccess(
                rows.length + ((rows.length == 1) ? " Eintrag ausgeschnitten" : " Eintrge ausgeschnitten"));
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void targetToInternalClipboardAction(TRANSFER_TYPE pType) {
    int[] rows = jVictimTable.getSelectedRows();

    if (rows == null || rows.length == 0) {
        showInfo("Keine Eintrge ausgewhlt");
        return;/*  w  ww.  j a  va 2s . c  o m*/
    }
    StringBuilder b = new StringBuilder();
    for (int row : rows) {
        Village v = (Village) jVictimTable.getValueAt(row, 1);
        Boolean fake = (Boolean) jVictimTable.getValueAt(row, 2);
        Integer attacks = (Integer) jVictimTable.getValueAt(row, 3);
        b.append(v.getId()).append(";").append(fake).append(";").append(attacks).append("\n");
    }

    try {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null);
        showSuccess(rows.length + ((rows.length == 1) ? " Eintrag kopiert" : " Eintrge kopiert"));
        //  return true;
    } catch (HeadlessException hex) {
        showError("Fehler beim Kopieren der Eintrge");
        return;
    }

    if (pType.equals(TRANSFER_TYPE.CUT_TARGET_TO_INTERNAL_CLIPBOARD)) {
        deleteAction(jVictimTable);
        showSuccess(
                rows.length + ((rows.length == 1) ? " Eintrag ausgeschnitten" : " Eintrge ausgeschnitten"));
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void attackToInternalFormatAction() {
    List<Attack> selection = getSelectedResults();
    StringBuilder b = new StringBuilder();
    int cnt = 0;/*from w  ww  .  j a v  a  2s .co  m*/
    for (Attack a : selection) {
        b.append(Attack.toInternalRepresentation(a)).append("\n");
        cnt++;
    }
    try {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null);
        showSuccess(cnt + ((cnt == 1) ? " Angriff kopiert" : " Angriffe kopiert"), true);
    } catch (HeadlessException hex) {
        showError("Fehler beim Kopieren der Angriffe", true);
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void attackToBBAction() {
    try {/* w w  w.j  av  a2  s.  c  o m*/
        List<Attack> attacks = getSelectedResults();
        if (attacks.isEmpty()) {
            showInfo("Keine Angriffe ausgewhlt", true);
            return;
        }
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(jResultFrame,
                "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]Angriffsplan[/size][/u]\n\n");
        } else {
            buffer.append("[u]Angriffsplan[/u]\n\n");
        }

        buffer.append(new AttackListFormatter().formatElements(attacks, 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(jResultFrame,
                    "Die ausgewhlten Angriffe 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);
        showInfo("BB-Codes in Zwischenablage kopiert", true);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        showError("Fehler beim Kopieren in die Zwischenablage", true);
    }
}

From source file:library.Form_Library.java

License:asdf

private void tbReaderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbReaderMouseClicked
    carActivationDate.setEnabled(true);/*from w w  w  .  ja  v a 2  s.  co m*/
    carExpiredDate.setEnabled(true);
    int donghh = this.tbReader.getSelectedRow();
    Reader t = ReaderList.getReader(donghh);
    this.viewReader(t);
    this.taPrintReader.setText("");
    this.taPrintReader.append("Receipt\n");
    this.taPrintReader.append("ReaderID: " + this.tfID.getText() + ".\n");
    this.taPrintReader.append("Name: " + this.tfName.getText() + ".\n");
    this.taPrintReader.append("IDCardNo: " + this.tfIDCardNumber.getText() + ".\n");
    this.taPrintReader.append("Gender: " + this.cbSex.getSelectedItem() + ".\n");
    this.taPrintReader.append("Birthday: " + df.format(this.carBirthday.getDate()) + ".\n");
    this.taPrintReader.append("Address: " + this.tfAddress.getText() + ".\n");
    this.taPrintReader.append("Phone: " + this.tfPhone.getText() + ".\n");
    this.taPrintReader.append("Email: " + this.tfEmail.getText() + ".\n");
    this.taPrintReader.append("Activation Date: " + df.format(this.carActivationDate.getDate()) + ".\n");
    this.taPrintReader.append("Expired Date: " + df.format(this.carExpiredDate.getDate()) + ".\n");
    this.taPrintReader.append("Paid: 80.000 VN?");
    this.taPrintReader.append("\r\n");
    jMenuItemReader.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfID.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:library.Form_Library.java

License:asdf

private void tbBookAdminMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBookAdminMouseClicked
    // TODO add your handling code here:
    int donghh = this.tbBookAdmin.getSelectedRow();
    Book b = BookList.getBook(donghh);
    this.viewBook(b);
    jMenuItemBook.addActionListener(new ActionListener() {
        @Override//from   www .j av a2 s  .c o m
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfBookID.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:library.Form_Library.java

License:asdf

private void tbAuthorAdminMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbAuthorAdminMouseClicked
    // TODO add your handling code here:
    int donghh = this.tbAuthorAdmin.getSelectedRow();
    Author b = AuthorList.getAuthor(donghh);
    this.viewAuthor(b);
    jMenuItemAuthor.addActionListener(new ActionListener() {
        @Override//  ww w . j  a v a2s .c  o  m
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfAuthorID1.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:library.Form_Library.java

License:asdf

private void tbcategoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbcategoryMouseClicked
    int donghh = this.tbcategory.getSelectedRow();
    Category t = CategoryList.getCategory(donghh);
    this.viewCategory(t);
    jMenuItemCate.addActionListener(new ActionListener() {
        @Override/*from w  w w .  j a  va 2  s. co  m*/
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfcategoryid.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:library.Form_Library.java

License:asdf

private void tbPublisherMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPublisherMouseClicked
    int donghh = this.tbPublisher.getSelectedRow();
    Publisher b = PublisherList.getPublisher(donghh);
    this.viewSupplier(b);
    jMenuItemPub.addActionListener(new ActionListener() {
        @Override/*ww  w  .  ja v a  2s .c  o  m*/
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfPublisherID.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });

}