blob: c8ca77c12f764a8657ba8129b93e418c9aafadc9 [file] [log] [blame]
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00001//
2// Copyright (C) 2001,2002 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// ButtonPanel class implements panel with four buttons in the
23// VNCViewer desktop window.
24//
25
Adam Tkacf53e62a2009-03-13 13:20:26 +000026package com.tigervnc.vncviewer;
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000027
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000028import java.awt.*;
29import java.awt.event.*;
30import java.io.*;
31
32class ButtonPanel extends Panel implements ActionListener {
33
34 VncViewer viewer;
35 Button disconnectButton;
36 Button optionsButton;
37 Button recordButton;
38 Button clipboardButton;
39 Button ctrlAltDelButton;
40 Button refreshButton;
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000041 Button selectButton;
enikeyd7653562008-12-25 11:02:56 +000042 Button videoFreezeButton;
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000043
Constantin Kaplinsky3de14342008-12-27 10:50:20 +000044 final String enableVideoFreezeLabel = "Ignore Video";
45 final String disableVideoFreezeLabel = "Enable Video";
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000046 final String selectEnterLabel = "Select Video Area";
47 final String selectLeaveLabel = "Hide Selection";
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000048
49 ButtonPanel(VncViewer v) {
50 viewer = v;
51
52 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
53 disconnectButton = new Button("Disconnect");
54 disconnectButton.setEnabled(false);
55 add(disconnectButton);
56 disconnectButton.addActionListener(this);
57 optionsButton = new Button("Options");
58 add(optionsButton);
59 optionsButton.addActionListener(this);
60 clipboardButton = new Button("Clipboard");
61 clipboardButton.setEnabled(false);
62 add(clipboardButton);
63 clipboardButton.addActionListener(this);
64 if (viewer.rec != null) {
65 recordButton = new Button("Record");
66 add(recordButton);
67 recordButton.addActionListener(this);
68 }
69 ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
70 ctrlAltDelButton.setEnabled(false);
71 add(ctrlAltDelButton);
72 ctrlAltDelButton.addActionListener(this);
73 refreshButton = new Button("Refresh");
74 refreshButton.setEnabled(false);
75 add(refreshButton);
76 refreshButton.addActionListener(this);
77 }
78
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000079 /**
80 * Add video selection button to the ButtonPanel.
81 */
82 public void addSelectButton() {
83 selectButton = new Button(selectEnterLabel);
84 selectButton.setEnabled(false);
85 add(selectButton);
86 selectButton.addActionListener(this);
87 }
88
enikey49e4a312008-12-24 10:12:11 +000089 /**
90 * Add video ignore button to the ButtonPanel.
91 */
enikeyd7653562008-12-25 11:02:56 +000092 public void addVideoFreezeButton() {
93 videoFreezeButton = new Button(enableVideoFreezeLabel);
94 add(videoFreezeButton);
95 videoFreezeButton.addActionListener(this);
enikey49e4a312008-12-24 10:12:11 +000096 }
97
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000098 //
99 // Enable buttons on successful connection.
100 //
101
102 public void enableButtons() {
103 disconnectButton.setEnabled(true);
104 clipboardButton.setEnabled(true);
105 refreshButton.setEnabled(true);
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000106 if (selectButton != null) {
107 selectButton.setEnabled(true);
108 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000109 }
110
111 //
112 // Disable all buttons on disconnect.
113 //
114
115 public void disableButtonsOnDisconnect() {
116 remove(disconnectButton);
117 disconnectButton = new Button("Hide desktop");
118 disconnectButton.setEnabled(true);
119 add(disconnectButton, 0);
120 disconnectButton.addActionListener(this);
121
122 optionsButton.setEnabled(false);
123 clipboardButton.setEnabled(false);
124 ctrlAltDelButton.setEnabled(false);
125 refreshButton.setEnabled(false);
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000126 if (selectButton != null) {
127 selectButton.setEnabled(false);
128 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000129 }
130
131 //
132 // Enable/disable controls that should not be available in view-only
133 // mode.
134 //
135
136 public void enableRemoteAccessControls(boolean enable) {
137 ctrlAltDelButton.setEnabled(enable);
138 }
139
140 //
141 // Event processing.
142 //
143
144 public void actionPerformed(ActionEvent evt) {
145
146 viewer.moveFocusToDesktop();
147
148 if (evt.getSource() == disconnectButton) {
149 viewer.disconnect();
150
151 } else if (evt.getSource() == optionsButton) {
152 viewer.options.setVisible(!viewer.options.isVisible());
153
154 } else if (evt.getSource() == recordButton) {
155 viewer.rec.setVisible(!viewer.rec.isVisible());
156
157 } else if (evt.getSource() == clipboardButton) {
158 viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
enikeyd7653562008-12-25 11:02:56 +0000159 } else if (evt.getSource() == videoFreezeButton) {
160
enikey49e4a312008-12-24 10:12:11 +0000161 //
enikeyd7653562008-12-25 11:02:56 +0000162 // Send video freeze message to server and change caption of button
enikey49e4a312008-12-24 10:12:11 +0000163 //
enikeyd7653562008-12-25 11:02:56 +0000164
165 //
166 // TODO: Move this code to another place.
167 //
168
169 boolean sendOk = true;
170 boolean currentFreezeState =
171 videoFreezeButton.getLabel().equals(disableVideoFreezeLabel);
172 try {
173 viewer.rfb.trySendVideoFreeze(!currentFreezeState);
174 } catch (IOException ex) {
175 sendOk = false;
176 ex.printStackTrace();
177 }
178 if (sendOk) {
179 if (!currentFreezeState) {
180 videoFreezeButton.setLabel(disableVideoFreezeLabel);
181 } else {
182 videoFreezeButton.setLabel(enableVideoFreezeLabel);
183 }
184 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000185 } else if (evt.getSource() == ctrlAltDelButton) {
186 try {
187 final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
188
189 KeyEvent ctrlAltDelEvent =
190 new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
191 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
192
193 ctrlAltDelEvent =
194 new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
195 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
196
197 } catch (IOException e) {
198 e.printStackTrace();
199 }
200 } else if (evt.getSource() == refreshButton) {
201 try {
202 RfbProto rfb = viewer.rfb;
203 rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
204 rfb.framebufferHeight, false);
205 } catch (IOException e) {
206 e.printStackTrace();
207 }
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000208 } else if (selectButton != null && evt.getSource() == selectButton) {
209 if (viewer.vc != null) {
210 boolean isSelecting = viewer.vc.isInSelectionMode();
211 if (!isSelecting) {
212 selectButton.setLabel(selectLeaveLabel);
213 viewer.vc.enableSelection(true);
214 } else {
215 selectButton.setLabel(selectEnterLabel);
216 viewer.vc.enableSelection(false);
217 }
218 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000219 }
220 }
221}
222