blob: 422e6e2c53a05feb425572321d901ff30114ca26 [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;
42
43 final String selectEnterLabel = "Select Video Area";
44 final String selectLeaveLabel = "Hide Selection";
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000045
46 ButtonPanel(VncViewer v) {
47 viewer = v;
48
49 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
50 disconnectButton = new Button("Disconnect");
51 disconnectButton.setEnabled(false);
52 add(disconnectButton);
53 disconnectButton.addActionListener(this);
54 optionsButton = new Button("Options");
55 add(optionsButton);
56 optionsButton.addActionListener(this);
57 clipboardButton = new Button("Clipboard");
58 clipboardButton.setEnabled(false);
59 add(clipboardButton);
60 clipboardButton.addActionListener(this);
61 if (viewer.rec != null) {
62 recordButton = new Button("Record");
63 add(recordButton);
64 recordButton.addActionListener(this);
65 }
66 ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
67 ctrlAltDelButton.setEnabled(false);
68 add(ctrlAltDelButton);
69 ctrlAltDelButton.addActionListener(this);
70 refreshButton = new Button("Refresh");
71 refreshButton.setEnabled(false);
72 add(refreshButton);
73 refreshButton.addActionListener(this);
74 }
75
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000076 /**
77 * Add video selection button to the ButtonPanel.
78 */
79 public void addSelectButton() {
80 selectButton = new Button(selectEnterLabel);
81 selectButton.setEnabled(false);
82 add(selectButton);
83 selectButton.addActionListener(this);
84 }
85
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000086 //
87 // Enable buttons on successful connection.
88 //
89
90 public void enableButtons() {
91 disconnectButton.setEnabled(true);
92 clipboardButton.setEnabled(true);
93 refreshButton.setEnabled(true);
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +000094 if (selectButton != null) {
95 selectButton.setEnabled(true);
96 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000097 }
98
99 //
100 // Disable all buttons on disconnect.
101 //
102
103 public void disableButtonsOnDisconnect() {
104 remove(disconnectButton);
105 disconnectButton = new Button("Hide desktop");
106 disconnectButton.setEnabled(true);
107 add(disconnectButton, 0);
108 disconnectButton.addActionListener(this);
109
110 optionsButton.setEnabled(false);
111 clipboardButton.setEnabled(false);
112 ctrlAltDelButton.setEnabled(false);
113 refreshButton.setEnabled(false);
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000114 if (selectButton != null) {
115 selectButton.setEnabled(false);
116 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000117 }
118
119 //
120 // Enable/disable controls that should not be available in view-only
121 // mode.
122 //
123
124 public void enableRemoteAccessControls(boolean enable) {
125 ctrlAltDelButton.setEnabled(enable);
126 }
127
128 //
129 // Event processing.
130 //
131
132 public void actionPerformed(ActionEvent evt) {
133
134 viewer.moveFocusToDesktop();
135
136 if (evt.getSource() == disconnectButton) {
137 viewer.disconnect();
138
139 } else if (evt.getSource() == optionsButton) {
140 viewer.options.setVisible(!viewer.options.isVisible());
141
142 } else if (evt.getSource() == recordButton) {
143 viewer.rec.setVisible(!viewer.rec.isVisible());
144
145 } else if (evt.getSource() == clipboardButton) {
146 viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
147
148 } else if (evt.getSource() == ctrlAltDelButton) {
149 try {
150 final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
151
152 KeyEvent ctrlAltDelEvent =
153 new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
154 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
155
156 ctrlAltDelEvent =
157 new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
158 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
159
160 } catch (IOException e) {
161 e.printStackTrace();
162 }
163 } else if (evt.getSource() == refreshButton) {
164 try {
165 RfbProto rfb = viewer.rfb;
166 rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
167 rfb.framebufferHeight, false);
168 } catch (IOException e) {
169 e.printStackTrace();
170 }
Constantin Kaplinskyf7cb2bf2008-05-27 08:38:28 +0000171 } else if (selectButton != null && evt.getSource() == selectButton) {
172 if (viewer.vc != null) {
173 boolean isSelecting = viewer.vc.isInSelectionMode();
174 if (!isSelecting) {
175 selectButton.setLabel(selectLeaveLabel);
176 viewer.vc.enableSelection(true);
177 } else {
178 selectButton.setLabel(selectEnterLabel);
179 viewer.vc.enableSelection(false);
180 }
181 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000182 }
183 }
184}
185