1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
//
// Copyright (C) 2001,2002 HorizonLive.com, Inc. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this software; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
//
// ButtonPanel class implements panel with four buttons in the
// VNCViewer desktop window.
//
package com.tightvnc.vncviewer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class ButtonPanel extends Panel implements ActionListener {
VncViewer viewer;
Button disconnectButton;
Button optionsButton;
Button recordButton;
Button clipboardButton;
Button ctrlAltDelButton;
Button refreshButton;
Button selectButton;
Button videoFreezeButton;
final String enableVideoFreezeLabel = "Ignore Video";
final String disableVideoFreezeLabel = "Enable Video";
final String selectEnterLabel = "Select Video Area";
final String selectLeaveLabel = "Hide Selection";
ButtonPanel(VncViewer v) {
viewer = v;
setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
disconnectButton = new Button("Disconnect");
disconnectButton.setEnabled(false);
add(disconnectButton);
disconnectButton.addActionListener(this);
optionsButton = new Button("Options");
add(optionsButton);
optionsButton.addActionListener(this);
clipboardButton = new Button("Clipboard");
clipboardButton.setEnabled(false);
add(clipboardButton);
clipboardButton.addActionListener(this);
if (viewer.rec != null) {
recordButton = new Button("Record");
add(recordButton);
recordButton.addActionListener(this);
}
ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
ctrlAltDelButton.setEnabled(false);
add(ctrlAltDelButton);
ctrlAltDelButton.addActionListener(this);
refreshButton = new Button("Refresh");
refreshButton.setEnabled(false);
add(refreshButton);
refreshButton.addActionListener(this);
}
/**
* Add video selection button to the ButtonPanel.
*/
public void addSelectButton() {
selectButton = new Button(selectEnterLabel);
selectButton.setEnabled(false);
add(selectButton);
selectButton.addActionListener(this);
}
/**
* Add video ignore button to the ButtonPanel.
*/
public void addVideoFreezeButton() {
videoFreezeButton = new Button(enableVideoFreezeLabel);
add(videoFreezeButton);
videoFreezeButton.addActionListener(this);
}
//
// Enable buttons on successful connection.
//
public void enableButtons() {
disconnectButton.setEnabled(true);
clipboardButton.setEnabled(true);
refreshButton.setEnabled(true);
if (selectButton != null) {
selectButton.setEnabled(true);
}
}
//
// Disable all buttons on disconnect.
//
public void disableButtonsOnDisconnect() {
remove(disconnectButton);
disconnectButton = new Button("Hide desktop");
disconnectButton.setEnabled(true);
add(disconnectButton, 0);
disconnectButton.addActionListener(this);
optionsButton.setEnabled(false);
clipboardButton.setEnabled(false);
ctrlAltDelButton.setEnabled(false);
refreshButton.setEnabled(false);
if (selectButton != null) {
selectButton.setEnabled(false);
}
}
//
// Enable/disable controls that should not be available in view-only
// mode.
//
public void enableRemoteAccessControls(boolean enable) {
ctrlAltDelButton.setEnabled(enable);
}
//
// Event processing.
//
public void actionPerformed(ActionEvent evt) {
viewer.moveFocusToDesktop();
if (evt.getSource() == disconnectButton) {
viewer.disconnect();
} else if (evt.getSource() == optionsButton) {
viewer.options.setVisible(!viewer.options.isVisible());
} else if (evt.getSource() == recordButton) {
viewer.rec.setVisible(!viewer.rec.isVisible());
} else if (evt.getSource() == clipboardButton) {
viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
} else if (evt.getSource() == videoFreezeButton) {
//
// Send video freeze message to server and change caption of button
//
//
// TODO: Move this code to another place.
//
boolean sendOk = true;
boolean currentFreezeState =
videoFreezeButton.getLabel().equals(disableVideoFreezeLabel);
try {
viewer.rfb.trySendVideoFreeze(!currentFreezeState);
} catch (IOException ex) {
sendOk = false;
ex.printStackTrace();
}
if (sendOk) {
if (!currentFreezeState) {
videoFreezeButton.setLabel(disableVideoFreezeLabel);
} else {
videoFreezeButton.setLabel(enableVideoFreezeLabel);
}
}
} else if (evt.getSource() == ctrlAltDelButton) {
try {
final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
KeyEvent ctrlAltDelEvent =
new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
ctrlAltDelEvent =
new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
} catch (IOException e) {
e.printStackTrace();
}
} else if (evt.getSource() == refreshButton) {
try {
RfbProto rfb = viewer.rfb;
rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
rfb.framebufferHeight, false);
} catch (IOException e) {
e.printStackTrace();
}
} else if (selectButton != null && evt.getSource() == selectButton) {
if (viewer.vc != null) {
boolean isSelecting = viewer.vc.isInSelectionMode();
if (!isSelecting) {
selectButton.setLabel(selectLeaveLabel);
viewer.vc.enableSelection(true);
} else {
selectButton.setLabel(selectEnterLabel);
viewer.vc.enableSelection(false);
}
}
}
}
}
|