Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 1 | // |
| 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 Kaplinsky | 90d8a50 | 2008-04-14 09:45:50 +0000 | [diff] [blame] | 26 | package com.tightvnc.vncviewer; |
| 27 | |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 28 | import java.awt.*; |
| 29 | import java.awt.event.*; |
| 30 | import java.io.*; |
| 31 | |
| 32 | class 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 Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 41 | Button selectButton; |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 42 | Button videoFreezeButton; |
Constantin Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 43 | |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 44 | final String enableVideoFreezeLabel = "Enable Video Freeze"; |
| 45 | final String disableVideoFreezeLabel = "Disable Video Freeze"; |
Constantin Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 46 | final String selectEnterLabel = "Select Video Area"; |
| 47 | final String selectLeaveLabel = "Hide Selection"; |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 48 | |
| 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 Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 79 | /** |
| 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 | |
enikey | 49e4a31 | 2008-12-24 10:12:11 +0000 | [diff] [blame] | 89 | /** |
| 90 | * Add video ignore button to the ButtonPanel. |
| 91 | */ |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 92 | public void addVideoFreezeButton() { |
| 93 | videoFreezeButton = new Button(enableVideoFreezeLabel); |
| 94 | add(videoFreezeButton); |
| 95 | videoFreezeButton.addActionListener(this); |
enikey | 49e4a31 | 2008-12-24 10:12:11 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 98 | // |
| 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 Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 106 | if (selectButton != null) { |
| 107 | selectButton.setEnabled(true); |
| 108 | } |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 109 | } |
| 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 Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 126 | if (selectButton != null) { |
| 127 | selectButton.setEnabled(false); |
| 128 | } |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 129 | } |
| 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()); |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 159 | } else if (evt.getSource() == videoFreezeButton) { |
| 160 | |
enikey | 49e4a31 | 2008-12-24 10:12:11 +0000 | [diff] [blame] | 161 | // |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 162 | // Send video freeze message to server and change caption of button |
enikey | 49e4a31 | 2008-12-24 10:12:11 +0000 | [diff] [blame] | 163 | // |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 164 | |
| 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 Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 185 | } 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 Kaplinsky | f7cb2bf | 2008-05-27 08:38:28 +0000 | [diff] [blame] | 208 | } 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 Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | } |
| 222 | |