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