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