blob: 63ad6a153f9c717df059c384322f280a1da386ec [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
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000026package com.tightvnc.vncviewer;
27
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;
enikey49e4a312008-12-24 10:12:11 +000042 Button videoIgnoreButton;
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000043
enikey49e4a312008-12-24 10:12:11 +000044 final String videoIgnoreLabel = "Video Ignore";
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000045 final String selectEnterLabel = "Select Video Area";
46 final String selectLeaveLabel = "Hide Selection";
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000047
48 ButtonPanel(VncViewer v) {
49 viewer = v;
50
51 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
52 disconnectButton = new Button("Disconnect");
53 disconnectButton.setEnabled(false);
54 add(disconnectButton);
55 disconnectButton.addActionListener(this);
56 optionsButton = new Button("Options");
57 add(optionsButton);
58 optionsButton.addActionListener(this);
59 clipboardButton = new Button("Clipboard");
60 clipboardButton.setEnabled(false);
61 add(clipboardButton);
62 clipboardButton.addActionListener(this);
63 if (viewer.rec != null) {
64 recordButton = new Button("Record");
65 add(recordButton);
66 recordButton.addActionListener(this);
67 }
68 ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
69 ctrlAltDelButton.setEnabled(false);
70 add(ctrlAltDelButton);
71 ctrlAltDelButton.addActionListener(this);
72 refreshButton = new Button("Refresh");
73 refreshButton.setEnabled(false);
74 add(refreshButton);
75 refreshButton.addActionListener(this);
76 }
77
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000078 /**
79 * Add video selection button to the ButtonPanel.
80 */
81 public void addSelectButton() {
82 selectButton = new Button(selectEnterLabel);
83 selectButton.setEnabled(false);
84 add(selectButton);
85 selectButton.addActionListener(this);
86 }
87
enikey49e4a312008-12-24 10:12:11 +000088 /**
89 * Add video ignore button to the ButtonPanel.
90 */
91 public void addVideoIgnoreButton() {
92 videoIgnoreButton = new Button(videoIgnoreLabel);
93 videoIgnoreButton.setEnabled(false);
94 add(selectButton);
95 videoIgnoreButton.addActionListener(this);
96 }
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());
enikey49e4a312008-12-24 10:12:11 +0000159 } else if (evt.getSource() == videoIgnoreButton) {
160 //
161 // Do something onVideoIgnoreButtonClick event
162 // ...
163 //
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000164 } else if (evt.getSource() == ctrlAltDelButton) {
165 try {
166 final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
167
168 KeyEvent ctrlAltDelEvent =
169 new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
170 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
171
172 ctrlAltDelEvent =
173 new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
174 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
175
176 } catch (IOException e) {
177 e.printStackTrace();
178 }
179 } else if (evt.getSource() == refreshButton) {
180 try {
181 RfbProto rfb = viewer.rfb;
182 rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
183 rfb.framebufferHeight, false);
184 } catch (IOException e) {
185 e.printStackTrace();
186 }
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000187 } else if (selectButton != null && evt.getSource() == selectButton) {
188 if (viewer.vc != null) {
189 boolean isSelecting = viewer.vc.isInSelectionMode();
190 if (!isSelecting) {
191 selectButton.setLabel(selectLeaveLabel);
192 viewer.vc.enableSelection(true);
193 } else {
194 selectButton.setLabel(selectEnterLabel);
195 viewer.vc.enableSelection(false);
196 }
197 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000198 }
199 }
200}
201