blob: 9b6178575df21380f420254a03433e20dceefec3 [file] [log] [blame]
DRCc5dc0382011-05-13 21:42:14 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19package com.tigervnc.vncviewer;
20
21import java.awt.Cursor;
22import java.awt.event.*;
23import javax.swing.JFrame;
24import javax.swing.JPopupMenu;
25import javax.swing.JMenu;
26import javax.swing.JMenuItem;
27import javax.swing.JCheckBoxMenuItem;
28
29import com.tigervnc.rfb.*;
30
31public class F8Menu extends JPopupMenu implements ActionListener {
32 public F8Menu(CConn cc_) {
33 super("VNC Menu");
34 setLightWeightPopupEnabled(false);
35 cc = cc_;
36 restore = addMenuItem("Restore",KeyEvent.VK_R);
37 move = addMenuItem("Move");
38 move.setEnabled(false);
39 size = addMenuItem("Size");
40 size.setEnabled(false);
41 minimize = addMenuItem("Minimize", KeyEvent.VK_N);
42 maximize = addMenuItem("Maximize", KeyEvent.VK_X);
43 addSeparator();
44 exit = addMenuItem("Close Viewer", KeyEvent.VK_C);
45 addSeparator();
46 fullScreen = new JCheckBoxMenuItem("Full Screen");
47 fullScreen.setMnemonic(KeyEvent.VK_F);
48 fullScreen.addActionListener(this);
49 add(fullScreen);
50 addSeparator();
51 clipboard = addMenuItem("Clipboard...");
52 addSeparator();
53 f8 = addMenuItem("Send F"+(cc.menuKey-Keysyms.F1+1));
54 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
55 addSeparator();
56 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
57 addSeparator();
58 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
59 options = addMenuItem("Options...", KeyEvent.VK_O);
60 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000061 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000062 addSeparator();
63 dismiss = addMenuItem("Dismiss menu");
64 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
65 }
66
67 JMenuItem addMenuItem(String str, int mnemonic) {
68 JMenuItem item = new JMenuItem(str, mnemonic);
69 item.addActionListener(this);
70 add(item);
71 return item;
72 }
73
74 JMenuItem addMenuItem(String str) {
75 JMenuItem item = new JMenuItem(str);
76 item.addActionListener(this);
77 add(item);
78 return item;
79 }
80
81 boolean actionMatch(ActionEvent ev, JMenuItem item) {
82 return ev.getActionCommand().equals(item.getActionCommand());
83 }
84
85 public void actionPerformed(ActionEvent ev) {
86 if (actionMatch(ev, exit)) {
87 cc.close();
88 } else if (actionMatch(ev, fullScreen)) {
89 cc.toggleFullScreen();
90 } else if (actionMatch(ev, restore)) {
91 if (cc.fullScreen) cc.toggleFullScreen();
92 cc.viewport.setExtendedState(JFrame.NORMAL);
93 } else if (actionMatch(ev, minimize)) {
94 if (cc.fullScreen) cc.toggleFullScreen();
95 cc.viewport.setExtendedState(JFrame.ICONIFIED);
96 } else if (actionMatch(ev, maximize)) {
97 if (cc.fullScreen) cc.toggleFullScreen();
98 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
99 } else if (actionMatch(ev, clipboard)) {
100 cc.clipboardDialog.showDialog();
101 } else if (actionMatch(ev, f8)) {
102 cc.writeKeyEvent(cc.menuKey, true);
103 cc.writeKeyEvent(cc.menuKey, false);
104 } else if (actionMatch(ev, ctrlAltDel)) {
105 cc.writeKeyEvent(Keysyms.Control_L, true);
106 cc.writeKeyEvent(Keysyms.Alt_L, true);
107 cc.writeKeyEvent(Keysyms.Delete, true);
108 cc.writeKeyEvent(Keysyms.Delete, false);
109 cc.writeKeyEvent(Keysyms.Alt_L, false);
110 cc.writeKeyEvent(Keysyms.Control_L, false);
111 } else if (actionMatch(ev, refresh)) {
112 cc.refresh();
113 } else if (actionMatch(ev, newConn)) {
114 VncViewer.newViewer(cc.viewer);
115 } else if (actionMatch(ev, options)) {
116 cc.options.showDialog();
117 } else if (actionMatch(ev, info)) {
118 cc.showInfo();
119 } else if (actionMatch(ev, about)) {
120 cc.showAbout();
121 } else if (actionMatch(ev, dismiss)) {
122 firePopupMenuCanceled();
123 }
124 }
125
126 CConn cc;
127 JMenuItem restore, move, size, minimize, maximize;
128 JMenuItem exit, clipboard, ctrlAltDel, refresh;
129 JMenuItem newConn, options, info, about, dismiss;
130 static JMenuItem f8;
131 JCheckBoxMenuItem fullScreen;
132 static LogWriter vlog = new LogWriter("F8Menu");
133}