blob: 375849c172e062892228098a7181a107018ae576 [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;
DRCc5dc0382011-05-13 21:42:14 +000025import javax.swing.JMenuItem;
26import javax.swing.JCheckBoxMenuItem;
27
28import com.tigervnc.rfb.*;
29
30public class F8Menu extends JPopupMenu implements ActionListener {
31 public F8Menu(CConn cc_) {
32 super("VNC Menu");
33 setLightWeightPopupEnabled(false);
34 cc = cc_;
35 restore = addMenuItem("Restore",KeyEvent.VK_R);
36 move = addMenuItem("Move");
37 move.setEnabled(false);
38 size = addMenuItem("Size");
39 size.setEnabled(false);
40 minimize = addMenuItem("Minimize", KeyEvent.VK_N);
41 maximize = addMenuItem("Maximize", KeyEvent.VK_X);
42 addSeparator();
43 exit = addMenuItem("Close Viewer", KeyEvent.VK_C);
44 addSeparator();
45 fullScreen = new JCheckBoxMenuItem("Full Screen");
46 fullScreen.setMnemonic(KeyEvent.VK_F);
47 fullScreen.addActionListener(this);
48 add(fullScreen);
49 addSeparator();
50 clipboard = addMenuItem("Clipboard...");
51 addSeparator();
52 f8 = addMenuItem("Send F"+(cc.menuKey-Keysyms.F1+1));
53 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
54 addSeparator();
55 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
56 addSeparator();
57 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
58 options = addMenuItem("Options...", KeyEvent.VK_O);
59 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000060 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000061 addSeparator();
62 dismiss = addMenuItem("Dismiss menu");
63 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
64 }
65
66 JMenuItem addMenuItem(String str, int mnemonic) {
67 JMenuItem item = new JMenuItem(str, mnemonic);
68 item.addActionListener(this);
69 add(item);
70 return item;
71 }
72
73 JMenuItem addMenuItem(String str) {
74 JMenuItem item = new JMenuItem(str);
75 item.addActionListener(this);
76 add(item);
77 return item;
78 }
79
80 boolean actionMatch(ActionEvent ev, JMenuItem item) {
81 return ev.getActionCommand().equals(item.getActionCommand());
82 }
83
84 public void actionPerformed(ActionEvent ev) {
85 if (actionMatch(ev, exit)) {
86 cc.close();
87 } else if (actionMatch(ev, fullScreen)) {
88 cc.toggleFullScreen();
89 } else if (actionMatch(ev, restore)) {
90 if (cc.fullScreen) cc.toggleFullScreen();
91 cc.viewport.setExtendedState(JFrame.NORMAL);
92 } else if (actionMatch(ev, minimize)) {
93 if (cc.fullScreen) cc.toggleFullScreen();
94 cc.viewport.setExtendedState(JFrame.ICONIFIED);
95 } else if (actionMatch(ev, maximize)) {
96 if (cc.fullScreen) cc.toggleFullScreen();
97 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
98 } else if (actionMatch(ev, clipboard)) {
99 cc.clipboardDialog.showDialog();
100 } else if (actionMatch(ev, f8)) {
101 cc.writeKeyEvent(cc.menuKey, true);
102 cc.writeKeyEvent(cc.menuKey, false);
103 } else if (actionMatch(ev, ctrlAltDel)) {
104 cc.writeKeyEvent(Keysyms.Control_L, true);
105 cc.writeKeyEvent(Keysyms.Alt_L, true);
106 cc.writeKeyEvent(Keysyms.Delete, true);
107 cc.writeKeyEvent(Keysyms.Delete, false);
108 cc.writeKeyEvent(Keysyms.Alt_L, false);
109 cc.writeKeyEvent(Keysyms.Control_L, false);
110 } else if (actionMatch(ev, refresh)) {
111 cc.refresh();
112 } else if (actionMatch(ev, newConn)) {
113 VncViewer.newViewer(cc.viewer);
114 } else if (actionMatch(ev, options)) {
115 cc.options.showDialog();
116 } else if (actionMatch(ev, info)) {
117 cc.showInfo();
118 } else if (actionMatch(ev, about)) {
119 cc.showAbout();
120 } else if (actionMatch(ev, dismiss)) {
121 firePopupMenuCanceled();
122 }
123 }
124
125 CConn cc;
126 JMenuItem restore, move, size, minimize, maximize;
127 JMenuItem exit, clipboard, ctrlAltDel, refresh;
128 JMenuItem newConn, options, info, about, dismiss;
129 static JMenuItem f8;
130 JCheckBoxMenuItem fullScreen;
131 static LogWriter vlog = new LogWriter("F8Menu");
132}