blob: 5045b77f14a1ae6421b80e39054162c019e9ca38 [file] [log] [blame]
DRCc5dc0382011-05-13 21:42:14 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Brian Hinz430d8cf2014-01-02 01:23:56 +00002 * Copyright (C) 2011-2014 Brian P. Hinz
Brian Hinzc0a36092013-05-12 15:46:09 +00003 *
DRCc5dc0382011-05-13 21:42:14 +00004 * 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.
Brian Hinzc0a36092013-05-12 15:46:09 +00008 *
DRCc5dc0382011-05-13 21:42:14 +00009 * 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.
Brian Hinzc0a36092013-05-12 15:46:09 +000013 *
DRCc5dc0382011-05-13 21:42:14 +000014 * 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
Brian Hinz4a95c7f2012-09-01 19:24:26 +000022import java.awt.*;
DRCc5dc0382011-05-13 21:42:14 +000023import java.awt.Cursor;
24import java.awt.event.*;
25import javax.swing.JFrame;
Brian Hinz92ddde22012-08-29 03:56:01 +000026import javax.swing.JFileChooser;
DRCc5dc0382011-05-13 21:42:14 +000027import javax.swing.JPopupMenu;
DRCc5dc0382011-05-13 21:42:14 +000028import javax.swing.JMenuItem;
29import javax.swing.JCheckBoxMenuItem;
30
31import com.tigervnc.rfb.*;
32
33public class F8Menu extends JPopupMenu implements ActionListener {
34 public F8Menu(CConn cc_) {
35 super("VNC Menu");
36 setLightWeightPopupEnabled(false);
37 cc = cc_;
38 restore = addMenuItem("Restore",KeyEvent.VK_R);
39 move = addMenuItem("Move");
40 move.setEnabled(false);
41 size = addMenuItem("Size");
42 size.setEnabled(false);
43 minimize = addMenuItem("Minimize", KeyEvent.VK_N);
44 maximize = addMenuItem("Maximize", KeyEvent.VK_X);
45 addSeparator();
46 exit = addMenuItem("Close Viewer", KeyEvent.VK_C);
47 addSeparator();
48 fullScreen = new JCheckBoxMenuItem("Full Screen");
49 fullScreen.setMnemonic(KeyEvent.VK_F);
Brian Hinz64ee6fd2012-04-08 19:12:50 +000050 fullScreen.setSelected(cc.fullScreen);
DRCc5dc0382011-05-13 21:42:14 +000051 fullScreen.addActionListener(this);
Brian Hinz430d8cf2014-01-02 01:23:56 +000052 fullScreen.setEnabled(!cc.viewer.embed.getValue());
DRCc5dc0382011-05-13 21:42:14 +000053 add(fullScreen);
54 addSeparator();
55 clipboard = addMenuItem("Clipboard...");
56 addSeparator();
Brian Hinz3b5ce722012-08-26 18:06:52 +000057 f8 = addMenuItem("Send "+KeyEvent.getKeyText(MenuKey.getMenuKeyCode()), MenuKey.getMenuKeyCode());
DRCc5dc0382011-05-13 21:42:14 +000058 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
59 addSeparator();
60 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
61 addSeparator();
62 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
Brian Hinz430d8cf2014-01-02 01:23:56 +000063 newConn.setEnabled(!cc.viewer.embed.getValue());
DRCc5dc0382011-05-13 21:42:14 +000064 options = addMenuItem("Options...", KeyEvent.VK_O);
Brian Hinz92ddde22012-08-29 03:56:01 +000065 save = addMenuItem("Save connection info as...", KeyEvent.VK_S);
DRCc5dc0382011-05-13 21:42:14 +000066 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000067 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000068 addSeparator();
69 dismiss = addMenuItem("Dismiss menu");
70 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
71 }
72
73 JMenuItem addMenuItem(String str, int mnemonic) {
74 JMenuItem item = new JMenuItem(str, mnemonic);
75 item.addActionListener(this);
76 add(item);
77 return item;
78 }
79
80 JMenuItem addMenuItem(String str) {
81 JMenuItem item = new JMenuItem(str);
82 item.addActionListener(this);
83 add(item);
84 return item;
85 }
86
87 boolean actionMatch(ActionEvent ev, JMenuItem item) {
88 return ev.getActionCommand().equals(item.getActionCommand());
89 }
90
91 public void actionPerformed(ActionEvent ev) {
92 if (actionMatch(ev, exit)) {
Brian Hinz932fac52012-08-26 20:52:15 +000093 cc.close();
DRCc5dc0382011-05-13 21:42:14 +000094 } else if (actionMatch(ev, fullScreen)) {
95 cc.toggleFullScreen();
96 } else if (actionMatch(ev, restore)) {
97 if (cc.fullScreen) cc.toggleFullScreen();
98 cc.viewport.setExtendedState(JFrame.NORMAL);
99 } else if (actionMatch(ev, minimize)) {
100 if (cc.fullScreen) cc.toggleFullScreen();
101 cc.viewport.setExtendedState(JFrame.ICONIFIED);
102 } else if (actionMatch(ev, maximize)) {
103 if (cc.fullScreen) cc.toggleFullScreen();
104 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
105 } else if (actionMatch(ev, clipboard)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000106 cc.clipboardDialog.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000107 } else if (actionMatch(ev, f8)) {
Brian Hinz1e252c62013-02-09 02:42:14 +0000108 cc.writeKeyEvent(MenuKey.getMenuKeySym(), true);
109 cc.writeKeyEvent(MenuKey.getMenuKeySym(), false);
DRCc5dc0382011-05-13 21:42:14 +0000110 } else if (actionMatch(ev, ctrlAltDel)) {
111 cc.writeKeyEvent(Keysyms.Control_L, true);
112 cc.writeKeyEvent(Keysyms.Alt_L, true);
113 cc.writeKeyEvent(Keysyms.Delete, true);
114 cc.writeKeyEvent(Keysyms.Delete, false);
115 cc.writeKeyEvent(Keysyms.Alt_L, false);
116 cc.writeKeyEvent(Keysyms.Control_L, false);
117 } else if (actionMatch(ev, refresh)) {
118 cc.refresh();
119 } else if (actionMatch(ev, newConn)) {
120 VncViewer.newViewer(cc.viewer);
121 } else if (actionMatch(ev, options)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000122 cc.options.showDialog(cc.viewport);
Brian Hinz92ddde22012-08-29 03:56:01 +0000123 } else if (actionMatch(ev, save)) {
124 JFileChooser fc = new JFileChooser();
125 fc.setDialogTitle("Save current configuration as:");
126 fc.setApproveButtonText("OK");
127 fc.setFileHidingEnabled(false);
Brian Hinz4a95c7f2012-09-01 19:24:26 +0000128 Window fullScreenWindow = Viewport.getFullScreenWindow();
129 if (fullScreenWindow != null)
130 Viewport.setFullScreenWindow(null);
Brian Hinz8b61dd52013-03-01 00:55:42 +0000131 int ret = fc.showOpenDialog(cc.viewport);
Brian Hinz4a95c7f2012-09-01 19:24:26 +0000132 if (fullScreenWindow != null)
133 Viewport.setFullScreenWindow(fullScreenWindow);
Brian Hinz92ddde22012-08-29 03:56:01 +0000134 if (ret == JFileChooser.APPROVE_OPTION) {
135 String filename = fc.getSelectedFile().toString();
136 if (filename != null)
137 Configuration.save(filename);
138 }
DRCc5dc0382011-05-13 21:42:14 +0000139 } else if (actionMatch(ev, info)) {
140 cc.showInfo();
141 } else if (actionMatch(ev, about)) {
142 cc.showAbout();
143 } else if (actionMatch(ev, dismiss)) {
144 firePopupMenuCanceled();
145 }
146 }
147
148 CConn cc;
149 JMenuItem restore, move, size, minimize, maximize;
150 JMenuItem exit, clipboard, ctrlAltDel, refresh;
Brian Hinz92ddde22012-08-29 03:56:01 +0000151 JMenuItem newConn, options, save, info, about, dismiss;
DRCc5dc0382011-05-13 21:42:14 +0000152 static JMenuItem f8;
153 JCheckBoxMenuItem fullScreen;
154 static LogWriter vlog = new LogWriter("F8Menu");
155}