source: trunk/packages/invirt-vnc-client/ButtonPanel.java @ 1843

Last change on this file since 1843 was 1438, checked in by broder, 16 years ago

Isolate our patches to the VNC client from the upstream TightVNC
source

File size: 4.4 KB
Line 
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
26import java.awt.*;
27import java.awt.event.*;
28import java.io.*;
29
30class ButtonPanel extends Panel implements ActionListener {
31
32  VncViewer viewer;
33  Button disconnectButton;
34  Button optionsButton;
35  Button recordButton;
36  Button clipboardButton;
37  Button ctrlAltDelButton;
38  Button refreshButton;
39
40  ButtonPanel(VncViewer v) {
41    viewer = v;
42
43    setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
44    disconnectButton = new Button("Disconnect");
45    disconnectButton.setEnabled(false);
46    add(disconnectButton);
47    disconnectButton.addActionListener(this);
48    optionsButton = new Button("Options");
49    add(optionsButton);
50    optionsButton.addActionListener(this);
51    clipboardButton = new Button("Clipboard");
52    clipboardButton.setEnabled(false);
53    add(clipboardButton);
54    clipboardButton.addActionListener(this);
55    if (viewer.rec != null) {
56      recordButton = new Button("Record");
57      add(recordButton);
58      recordButton.addActionListener(this);
59    }
60    ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
61    ctrlAltDelButton.setEnabled(false);
62    add(ctrlAltDelButton);
63    ctrlAltDelButton.addActionListener(this);
64    refreshButton = new Button("Refresh");
65    refreshButton.setEnabled(false);
66    add(refreshButton);
67    refreshButton.addActionListener(this);
68  }
69
70  //
71  // Enable buttons on successful connection.
72  //
73
74  public void enableButtons() {
75    disconnectButton.setEnabled(true);
76    clipboardButton.setEnabled(true);
77    refreshButton.setEnabled(true);
78  }
79
80  //
81  // Disable all buttons on disconnect.
82  //
83
84  public void disableButtonsOnDisconnect() {
85    remove(disconnectButton);
86    disconnectButton = new Button("Hide desktop");
87    disconnectButton.setEnabled(true);
88    add(disconnectButton, 0);
89    disconnectButton.addActionListener(this);
90
91    optionsButton.setEnabled(false);
92    clipboardButton.setEnabled(false);
93    ctrlAltDelButton.setEnabled(false);
94    refreshButton.setEnabled(false);
95
96    validate();
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());
127
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      }
151    }
152  }
153}
154
Note: See TracBrowser for help on using the repository browser.