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 | |
Adam Tkac | f53e62a | 2009-03-13 13:20:26 +0000 | [diff] [blame] | 26 | package com.tigervnc.vncviewer; |
Constantin Kaplinsky | 90d8a50 | 2008-04-14 09:45:50 +0000 | [diff] [blame] | 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; |
| 41 | |
| 42 | ButtonPanel(VncViewer v) { |
| 43 | viewer = v; |
| 44 | |
| 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"); |
| 51 | add(optionsButton); |
| 52 | optionsButton.addActionListener(this); |
| 53 | clipboardButton = new Button("Clipboard"); |
| 54 | clipboardButton.setEnabled(false); |
| 55 | add(clipboardButton); |
| 56 | clipboardButton.addActionListener(this); |
| 57 | if (viewer.rec != null) { |
| 58 | recordButton = new Button("Record"); |
| 59 | add(recordButton); |
| 60 | recordButton.addActionListener(this); |
| 61 | } |
| 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); |
| 68 | add(refreshButton); |
| 69 | refreshButton.addActionListener(this); |
| 70 | } |
| 71 | |
| 72 | // |
| 73 | // Enable buttons on successful connection. |
| 74 | // |
| 75 | |
| 76 | public void enableButtons() { |
| 77 | disconnectButton.setEnabled(true); |
| 78 | clipboardButton.setEnabled(true); |
| 79 | refreshButton.setEnabled(true); |
| 80 | } |
| 81 | |
| 82 | // |
| 83 | // Disable all buttons on disconnect. |
| 84 | // |
| 85 | |
| 86 | public void disableButtonsOnDisconnect() { |
| 87 | remove(disconnectButton); |
| 88 | disconnectButton = new Button("Hide desktop"); |
| 89 | disconnectButton.setEnabled(true); |
| 90 | add(disconnectButton, 0); |
| 91 | disconnectButton.addActionListener(this); |
| 92 | |
| 93 | optionsButton.setEnabled(false); |
| 94 | clipboardButton.setEnabled(false); |
| 95 | ctrlAltDelButton.setEnabled(false); |
| 96 | refreshButton.setEnabled(false); |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | // |
| 100 | // Enable/disable controls that should not be available in view-only |
| 101 | // mode. |
| 102 | // |
| 103 | |
| 104 | public void enableRemoteAccessControls(boolean enable) { |
| 105 | ctrlAltDelButton.setEnabled(enable); |
| 106 | } |
| 107 | |
| 108 | // |
| 109 | // Event processing. |
| 110 | // |
| 111 | |
| 112 | public void actionPerformed(ActionEvent evt) { |
| 113 | |
| 114 | viewer.moveFocusToDesktop(); |
| 115 | |
| 116 | if (evt.getSource() == disconnectButton) { |
| 117 | viewer.disconnect(); |
| 118 | |
| 119 | } else if (evt.getSource() == optionsButton) { |
| 120 | viewer.options.setVisible(!viewer.options.isVisible()); |
| 121 | |
| 122 | } else if (evt.getSource() == recordButton) { |
| 123 | viewer.rec.setVisible(!viewer.rec.isVisible()); |
| 124 | |
| 125 | } else if (evt.getSource() == clipboardButton) { |
| 126 | viewer.clipboard.setVisible(!viewer.clipboard.isVisible()); |
enikey | d765356 | 2008-12-25 11:02:56 +0000 | [diff] [blame] | 127 | |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 128 | } else if (evt.getSource() == ctrlAltDelButton) { |
| 129 | try { |
| 130 | final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK; |
| 131 | |
| 132 | KeyEvent ctrlAltDelEvent = |
| 133 | new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127); |
| 134 | viewer.rfb.writeKeyEvent(ctrlAltDelEvent); |
| 135 | |
| 136 | ctrlAltDelEvent = |
| 137 | new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127); |
| 138 | viewer.rfb.writeKeyEvent(ctrlAltDelEvent); |
| 139 | |
| 140 | } catch (IOException e) { |
| 141 | e.printStackTrace(); |
| 142 | } |
| 143 | } else if (evt.getSource() == refreshButton) { |
| 144 | try { |
| 145 | RfbProto rfb = viewer.rfb; |
| 146 | rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth, |
| 147 | rfb.framebufferHeight, false); |
| 148 | } catch (IOException e) { |
| 149 | e.printStackTrace(); |
| 150 | } |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | } |
| 154 | |