15
|
1 package treeVnc;
|
|
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
|
20
|
32 /**
|
|
33 *
|
|
34 */
|
|
35 private static final long serialVersionUID = 1L;
|
|
36 TextArea textArea;
|
15
|
37 Button clearButton, closeButton;
|
|
38 String selection;
|
|
39 VncViewer viewer;
|
|
40
|
|
41 //
|
|
42 // Constructor.
|
|
43 //
|
|
44
|
|
45 ClipboardFrame(VncViewer v) {
|
|
46 super("TightVNC Clipboard");
|
|
47
|
|
48 viewer = v;
|
|
49
|
|
50 GridBagLayout gridbag = new GridBagLayout();
|
|
51 setLayout(gridbag);
|
|
52
|
|
53 GridBagConstraints gbc = new GridBagConstraints();
|
|
54 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
55 gbc.fill = GridBagConstraints.BOTH;
|
|
56 gbc.weighty = 1.0;
|
|
57
|
|
58 textArea = new TextArea(5, 40);
|
|
59 gridbag.setConstraints(textArea, gbc);
|
|
60 add(textArea);
|
|
61
|
|
62 gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
63 gbc.weightx = 1.0;
|
|
64 gbc.weighty = 0.0;
|
|
65 gbc.gridwidth = 1;
|
|
66
|
|
67 clearButton = new Button("Clear");
|
|
68 gridbag.setConstraints(clearButton, gbc);
|
|
69 add(clearButton);
|
|
70 clearButton.addActionListener(this);
|
|
71
|
|
72 closeButton = new Button("Close");
|
|
73 gridbag.setConstraints(closeButton, gbc);
|
|
74 add(closeButton);
|
|
75 closeButton.addActionListener(this);
|
|
76
|
|
77 pack();
|
|
78
|
|
79 addWindowListener(this);
|
|
80 }
|
|
81
|
|
82
|
|
83 //
|
|
84 // Set the cut text from the RFB server.
|
|
85 //
|
|
86
|
|
87 void setCutText(String text) {
|
|
88 selection = text;
|
|
89 textArea.setText(text);
|
|
90 if (isVisible()) {
|
|
91 textArea.selectAll();
|
|
92 }
|
|
93 }
|
|
94
|
|
95
|
|
96 //
|
|
97 // When the focus leaves the window, see if we have new cut text and
|
|
98 // if so send it to the RFB server.
|
|
99 //
|
|
100
|
|
101 public void windowDeactivated (WindowEvent evt) {
|
|
102 if (selection != null && !selection.equals(textArea.getText())) {
|
|
103 selection = textArea.getText();
|
|
104 viewer.setCutText(selection);
|
|
105 }
|
|
106 }
|
|
107
|
|
108 //
|
|
109 // Close our window properly.
|
|
110 //
|
|
111
|
|
112 public void windowClosing(WindowEvent evt) {
|
|
113 setVisible(false);
|
|
114 }
|
|
115
|
|
116 //
|
|
117 // Ignore window events we're not interested in.
|
|
118 //
|
|
119
|
|
120 public void windowActivated(WindowEvent evt) {}
|
|
121 public void windowOpened(WindowEvent evt) {}
|
|
122 public void windowClosed(WindowEvent evt) {}
|
|
123 public void windowIconified(WindowEvent evt) {}
|
|
124 public void windowDeiconified(WindowEvent evt) {}
|
|
125
|
|
126
|
|
127 //
|
|
128 // Respond to button presses
|
|
129 //
|
|
130
|
|
131 public void actionPerformed(ActionEvent evt) {
|
|
132 if (evt.getSource() == clearButton) {
|
|
133 textArea.setText("");
|
|
134 } else if (evt.getSource() == closeButton) {
|
|
135 setVisible(false);
|
|
136 }
|
|
137 }
|
|
138 }
|