source: trunk/packages/sipb-xen-vnc-client/code/ButtonPanel.java @ 787

Last change on this file since 787 was 128, checked in by quentin, 17 years ago

Added control and alt checkboxes, for ease of typing modifier sequences

File size: 5.1 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, ItemListener {
31
32  VncViewer viewer;
33  Button disconnectButton;
34  Button optionsButton;
35  Button recordButton;
36  Button clipboardButton;
37  Button ctrlAltDelButton;
38  Button refreshButton;
39  Checkbox altCheckbox;
40  Checkbox ctrlCheckbox;
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    altCheckbox = new Checkbox("Alt");
72    altCheckbox.setEnabled(false);
73    add(altCheckbox);
74    altCheckbox.addItemListener(this);
75    ctrlCheckbox = new Checkbox("Control");
76    ctrlCheckbox.setEnabled(false);
77    add(ctrlCheckbox);
78    ctrlCheckbox.addItemListener(this);
79  }
80
81  //
82  // Enable buttons on successful connection.
83  //
84
85  public void enableButtons() {
86    disconnectButton.setEnabled(true);
87    clipboardButton.setEnabled(true);
88    refreshButton.setEnabled(true);
89  }
90
91  //
92  // Disable all buttons on disconnect.
93  //
94
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);
101
102    optionsButton.setEnabled(false);
103    clipboardButton.setEnabled(false);
104    ctrlAltDelButton.setEnabled(false);
105    refreshButton.setEnabled(false);
106
107    validate();
108  }
109
110  //
111  // Enable/disable controls that should not be available in view-only
112  // mode.
113  //
114
115  public void enableRemoteAccessControls(boolean enable) {
116    ctrlAltDelButton.setEnabled(enable);
117    ctrlCheckbox.setEnabled(enable);
118    altCheckbox.setEnabled(enable);
119  }
120
121  //
122  // Event processing.
123  //
124
125  public void actionPerformed(ActionEvent evt) {
126
127    viewer.moveFocusToDesktop();
128
129    if (evt.getSource() == disconnectButton) {
130      viewer.disconnect();
131
132    } else if (evt.getSource() == optionsButton) {
133      viewer.options.setVisible(!viewer.options.isVisible());
134
135    } else if (evt.getSource() == recordButton) {
136      viewer.rec.setVisible(!viewer.rec.isVisible());
137
138    } else if (evt.getSource() == clipboardButton) {
139      viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
140
141    } else if (evt.getSource() == ctrlAltDelButton) {
142      try {
143        final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
144
145        KeyEvent ctrlAltDelEvent =
146          new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
147        viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
148
149        ctrlAltDelEvent =
150          new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
151        viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
152
153      } catch (IOException e) {
154        e.printStackTrace();
155      }
156    } else if (evt.getSource() == refreshButton) {
157      try {
158        RfbProto rfb = viewer.rfb;
159        rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
160                                          rfb.framebufferHeight, false);
161      } catch (IOException e) {
162        e.printStackTrace();
163      }
164    }
165  }
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;
173    }
174}
175
Note: See TracBrowser for help on using the repository browser.