blob: 8c5843c75d923838dc940f8e598207637ab62c5d [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);
Brian Hinz64ee6fd2012-04-08 19:12:50 +000047 fullScreen.setSelected(cc.fullScreen);
DRCc5dc0382011-05-13 21:42:14 +000048 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)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000100 cc.clipboardDialog.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000101 } 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)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000116 cc.options.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000117 } 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}