blob: ca09ac200eee8cc2f465d3c54847f3379691b878 [file] [log] [blame]
DRCc5dc0382011-05-13 21:42:14 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Brian Hinzb213da62012-04-11 22:00:55 +00002 * Copyright (C) 2011 Brian P. Hinz
DRCc5dc0382011-05-13 21:42:14 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
Brian Hinzb213da62012-04-11 22:00:55 +000016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
DRCc5dc0382011-05-13 21:42:14 +000017 * USA.
18 */
19
20package com.tigervnc.vncviewer;
21
22import java.awt.Cursor;
23import java.awt.event.*;
24import javax.swing.JFrame;
25import javax.swing.JPopupMenu;
DRCc5dc0382011-05-13 21:42:14 +000026import 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);
Brian Hinz64ee6fd2012-04-08 19:12:50 +000048 fullScreen.setSelected(cc.fullScreen);
DRCc5dc0382011-05-13 21:42:14 +000049 fullScreen.addActionListener(this);
50 add(fullScreen);
51 addSeparator();
52 clipboard = addMenuItem("Clipboard...");
53 addSeparator();
Brian Hinz60530532012-05-16 03:51:42 +000054 f8 = addMenuItem("Send "+KeyEvent.getKeyText(menukey.getMenuKeyCode()), menukey.getMenuKeyCode());
DRCc5dc0382011-05-13 21:42:14 +000055 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
56 addSeparator();
57 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
58 addSeparator();
59 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
60 options = addMenuItem("Options...", KeyEvent.VK_O);
61 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000062 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000063 addSeparator();
64 dismiss = addMenuItem("Dismiss menu");
65 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
66 }
67
68 JMenuItem addMenuItem(String str, int mnemonic) {
69 JMenuItem item = new JMenuItem(str, mnemonic);
70 item.addActionListener(this);
71 add(item);
72 return item;
73 }
74
75 JMenuItem addMenuItem(String str) {
76 JMenuItem item = new JMenuItem(str);
77 item.addActionListener(this);
78 add(item);
79 return item;
80 }
81
82 boolean actionMatch(ActionEvent ev, JMenuItem item) {
83 return ev.getActionCommand().equals(item.getActionCommand());
84 }
85
86 public void actionPerformed(ActionEvent ev) {
87 if (actionMatch(ev, exit)) {
88 cc.close();
89 } else if (actionMatch(ev, fullScreen)) {
90 cc.toggleFullScreen();
91 } else if (actionMatch(ev, restore)) {
92 if (cc.fullScreen) cc.toggleFullScreen();
93 cc.viewport.setExtendedState(JFrame.NORMAL);
94 } else if (actionMatch(ev, minimize)) {
95 if (cc.fullScreen) cc.toggleFullScreen();
96 cc.viewport.setExtendedState(JFrame.ICONIFIED);
97 } else if (actionMatch(ev, maximize)) {
98 if (cc.fullScreen) cc.toggleFullScreen();
99 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
100 } else if (actionMatch(ev, clipboard)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000101 cc.clipboardDialog.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000102 } else if (actionMatch(ev, f8)) {
Brian Hinz60530532012-05-16 03:51:42 +0000103 cc.writeKeyEvent(cc.menuKeyCode, true);
104 cc.writeKeyEvent(cc.menuKeyCode, false);
DRCc5dc0382011-05-13 21:42:14 +0000105 } else if (actionMatch(ev, ctrlAltDel)) {
106 cc.writeKeyEvent(Keysyms.Control_L, true);
107 cc.writeKeyEvent(Keysyms.Alt_L, true);
108 cc.writeKeyEvent(Keysyms.Delete, true);
109 cc.writeKeyEvent(Keysyms.Delete, false);
110 cc.writeKeyEvent(Keysyms.Alt_L, false);
111 cc.writeKeyEvent(Keysyms.Control_L, false);
112 } else if (actionMatch(ev, refresh)) {
113 cc.refresh();
114 } else if (actionMatch(ev, newConn)) {
115 VncViewer.newViewer(cc.viewer);
116 } else if (actionMatch(ev, options)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000117 cc.options.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000118 } else if (actionMatch(ev, info)) {
119 cc.showInfo();
120 } else if (actionMatch(ev, about)) {
121 cc.showAbout();
122 } else if (actionMatch(ev, dismiss)) {
123 firePopupMenuCanceled();
124 }
125 }
126
127 CConn cc;
128 JMenuItem restore, move, size, minimize, maximize;
129 JMenuItem exit, clipboard, ctrlAltDel, refresh;
130 JMenuItem newConn, options, info, about, dismiss;
131 static JMenuItem f8;
132 JCheckBoxMenuItem fullScreen;
133 static LogWriter vlog = new LogWriter("F8Menu");
134}