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.

ClipboardFrame.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // Copyright (C) 2001 HorizonLive.com, Inc. All Rights Reserved.
  3. // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
  4. //
  5. // This is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This software is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this software; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. // USA.
  19. //
  20. //
  21. // Clipboard frame.
  22. //
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. class ClipboardFrame extends Frame
  26. implements WindowListener, ActionListener {
  27. TextArea textArea;
  28. Button clearButton, closeButton;
  29. String selection;
  30. VncViewer viewer;
  31. //
  32. // Constructor.
  33. //
  34. ClipboardFrame(VncViewer v) {
  35. super("TightVNC Clipboard");
  36. viewer = v;
  37. GridBagLayout gridbag = new GridBagLayout();
  38. setLayout(gridbag);
  39. GridBagConstraints gbc = new GridBagConstraints();
  40. gbc.gridwidth = GridBagConstraints.REMAINDER;
  41. gbc.fill = GridBagConstraints.BOTH;
  42. gbc.weighty = 1.0;
  43. textArea = new TextArea(5, 40);
  44. gridbag.setConstraints(textArea, gbc);
  45. add(textArea);
  46. gbc.fill = GridBagConstraints.HORIZONTAL;
  47. gbc.weightx = 1.0;
  48. gbc.weighty = 0.0;
  49. gbc.gridwidth = 1;
  50. clearButton = new Button("Clear");
  51. gridbag.setConstraints(clearButton, gbc);
  52. add(clearButton);
  53. clearButton.addActionListener(this);
  54. closeButton = new Button("Close");
  55. gridbag.setConstraints(closeButton, gbc);
  56. add(closeButton);
  57. closeButton.addActionListener(this);
  58. pack();
  59. addWindowListener(this);
  60. }
  61. //
  62. // Set the cut text from the RFB server.
  63. //
  64. void setCutText(String text) {
  65. selection = text;
  66. textArea.setText(text);
  67. if (isVisible()) {
  68. textArea.selectAll();
  69. }
  70. }
  71. //
  72. // When the focus leaves the window, see if we have new cut text and
  73. // if so send it to the RFB server.
  74. //
  75. public void windowDeactivated (WindowEvent evt) {
  76. if (selection != null && !selection.equals(textArea.getText())) {
  77. selection = textArea.getText();
  78. viewer.setCutText(selection);
  79. }
  80. }
  81. //
  82. // Close our window properly.
  83. //
  84. public void windowClosing(WindowEvent evt) {
  85. setVisible(false);
  86. }
  87. //
  88. // Ignore window events we're not interested in.
  89. //
  90. public void windowActivated(WindowEvent evt) {}
  91. public void windowOpened(WindowEvent evt) {}
  92. public void windowClosed(WindowEvent evt) {}
  93. public void windowIconified(WindowEvent evt) {}
  94. public void windowDeiconified(WindowEvent evt) {}
  95. //
  96. // Respond to button presses
  97. //
  98. public void actionPerformed(ActionEvent evt) {
  99. if (evt.getSource() == clearButton) {
  100. textArea.setText("");
  101. } else if (evt.getSource() == closeButton) {
  102. setVisible(false);
  103. }
  104. }
  105. }