2 // Copyright (C) 2001,2002 HorizonLive.com, Inc. All Rights Reserved.
3 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
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.
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.
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,
22 // ButtonPanel class implements panel with four buttons in the
23 // VNCViewer desktop window.
27 import java.awt.event.*;
30 class ButtonPanel extends Panel implements ActionListener, ItemListener {
33 Button disconnectButton;
36 Button clipboardButton;
37 Button ctrlAltDelButton;
40 Checkbox ctrlCheckbox;
42 ButtonPanel(VncViewer v) {
45 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
46 disconnectButton = new Button("Disconnect");
47 disconnectButton.setEnabled(false);
48 add(disconnectButton);
49 disconnectButton.addActionListener(this);
50 optionsButton = new Button("Options");
52 optionsButton.addActionListener(this);
53 clipboardButton = new Button("Clipboard");
54 clipboardButton.setEnabled(false);
56 clipboardButton.addActionListener(this);
57 if (viewer.rec != null) {
58 recordButton = new Button("Record");
60 recordButton.addActionListener(this);
62 ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
63 ctrlAltDelButton.setEnabled(false);
64 add(ctrlAltDelButton);
65 ctrlAltDelButton.addActionListener(this);
66 refreshButton = new Button("Refresh");
67 refreshButton.setEnabled(false);
69 refreshButton.addActionListener(this);
71 altCheckbox = new Checkbox("Alt");
72 altCheckbox.setEnabled(false);
74 altCheckbox.addItemListener(this);
75 ctrlCheckbox = new Checkbox("Control");
76 ctrlCheckbox.setEnabled(false);
78 ctrlCheckbox.addItemListener(this);
82 // Enable buttons on successful connection.
85 public void enableButtons() {
86 disconnectButton.setEnabled(true);
87 clipboardButton.setEnabled(true);
88 refreshButton.setEnabled(true);
92 // Disable all buttons on disconnect.
95 public void disableButtonsOnDisconnect() {
96 remove(disconnectButton);
97 disconnectButton = new Button("Hide desktop");
98 disconnectButton.setEnabled(true);
99 add(disconnectButton, 0);
100 disconnectButton.addActionListener(this);
102 optionsButton.setEnabled(false);
103 clipboardButton.setEnabled(false);
104 ctrlAltDelButton.setEnabled(false);
105 refreshButton.setEnabled(false);
111 // Enable/disable controls that should not be available in view-only
115 public void enableRemoteAccessControls(boolean enable) {
116 ctrlAltDelButton.setEnabled(enable);
117 ctrlCheckbox.setEnabled(enable);
118 altCheckbox.setEnabled(enable);
125 public void actionPerformed(ActionEvent evt) {
127 viewer.moveFocusToDesktop();
129 if (evt.getSource() == disconnectButton) {
132 } else if (evt.getSource() == optionsButton) {
133 viewer.options.setVisible(!viewer.options.isVisible());
135 } else if (evt.getSource() == recordButton) {
136 viewer.rec.setVisible(!viewer.rec.isVisible());
138 } else if (evt.getSource() == clipboardButton) {
139 viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
141 } else if (evt.getSource() == ctrlAltDelButton) {
143 final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
145 KeyEvent ctrlAltDelEvent =
146 new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
147 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
150 new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
151 viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
153 } catch (IOException e) {
156 } else if (evt.getSource() == refreshButton) {
158 RfbProto rfb = viewer.rfb;
159 rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
160 rfb.framebufferHeight, false);
161 } catch (IOException e) {
166 public void itemStateChanged(ItemEvent evt) {
167 viewer.moveFocusToDesktop();
168 int state = evt.getStateChange();
169 int extraModifiers = 0;
170 if (altCheckbox.getState()) { extraModifiers |= InputEvent.ALT_MASK; }
171 if (ctrlCheckbox.getState()) { extraModifiers |= InputEvent.CTRL_MASK; }
172 viewer.vc.extraModifiers = extraModifiers;