You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClipboardDialog.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 Brian P. Hinz
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  17. * USA.
  18. */
  19. package com.tigervnc.vncviewer;
  20. import java.awt.*;
  21. import java.awt.event.*;
  22. import java.awt.datatransfer.Clipboard;
  23. import java.awt.datatransfer.StringSelection;
  24. import javax.swing.*;
  25. import javax.swing.border.*;
  26. import com.tigervnc.rfb.LogWriter;
  27. class ClipboardDialog extends Dialog implements ActionListener {
  28. public ClipboardDialog(CConn cc_) {
  29. super(false);
  30. cc = cc_;
  31. setTitle("VNC clipboard");
  32. JPanel pt = new JPanel();
  33. textArea = new JTextArea(5,50);
  34. textArea.setBorder(BorderFactory.createLineBorder(Color.gray));
  35. textArea.setLineWrap(true);
  36. textArea.setWrapStyleWord(true);
  37. JScrollPane sp = new JScrollPane(textArea);
  38. pt.add(sp, BorderLayout.CENTER);
  39. getContentPane().add("North", pt);
  40. JPanel pb = new JPanel();
  41. clearButton = new JButton("Clear");
  42. pb.add(clearButton);
  43. clearButton.addActionListener(this);
  44. sendButton = new JButton("Send to VNC server");
  45. pb.add(sendButton);
  46. sendButton.addActionListener(this);
  47. cancelButton = new JButton("Cancel");
  48. pb.add(cancelButton);
  49. cancelButton.addActionListener(this);
  50. getContentPane().add("South", pb);
  51. pack();
  52. }
  53. public void setContents(String str) {
  54. textArea.setText(str);
  55. }
  56. public String getContents() {
  57. return textArea.getText();
  58. }
  59. public void serverCutText(String str, int len) {
  60. setContents(str);
  61. SecurityManager sm = System.getSecurityManager();
  62. try {
  63. if (sm != null) sm.checkSystemClipboardAccess();
  64. Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
  65. if (cb != null) {
  66. StringSelection ss = new StringSelection(str);
  67. try {
  68. cb.setContents(ss, null);
  69. } catch(Exception e) {
  70. vlog.debug(e.getMessage());
  71. }
  72. }
  73. } catch(SecurityException e) {
  74. vlog.debug("Cannot access the system clipboard: "+e.getMessage());
  75. }
  76. }
  77. public void setSendingEnabled(boolean b) {
  78. sendButton.setEnabled(b);
  79. }
  80. public void actionPerformed(ActionEvent e) {
  81. Object s = e.getSource();
  82. if (s instanceof JButton && (JButton)s == clearButton) {
  83. serverCutText(new String(""), 0);
  84. } else if (s instanceof JButton && (JButton)s == sendButton) {
  85. cc.writeClientCutText(textArea.getText(), textArea.getText().length());
  86. endDialog();
  87. } else if (s instanceof JButton && (JButton)s == cancelButton) {
  88. endDialog();
  89. }
  90. }
  91. CConn cc;
  92. JTextArea textArea;
  93. JButton clearButton, sendButton, cancelButton;
  94. static LogWriter vlog = new LogWriter("ClipboardDialog");
  95. }