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