blob: ee7ae872c9e95e2499bc66a0599cf567aa943e25 [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
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);
52 add(fullScreen);
53 addSeparator();
54 clipboard = addMenuItem("Clipboard...");
55 addSeparator();
Brian Hinz3b5ce722012-08-26 18:06:52 +000056 f8 = addMenuItem("Send "+KeyEvent.getKeyText(MenuKey.getMenuKeyCode()), MenuKey.getMenuKeyCode());
DRCc5dc0382011-05-13 21:42:14 +000057 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
58 addSeparator();
59 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
60 addSeparator();
61 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
62 options = addMenuItem("Options...", KeyEvent.VK_O);
Brian Hinz92ddde22012-08-29 03:56:01 +000063 save = addMenuItem("Save connection info as...", KeyEvent.VK_S);
DRCc5dc0382011-05-13 21:42:14 +000064 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000065 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000066 addSeparator();
67 dismiss = addMenuItem("Dismiss menu");
68 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
69 }
70
71 JMenuItem addMenuItem(String str, int mnemonic) {
72 JMenuItem item = new JMenuItem(str, mnemonic);
73 item.addActionListener(this);
74 add(item);
75 return item;
76 }
77
78 JMenuItem addMenuItem(String str) {
79 JMenuItem item = new JMenuItem(str);
80 item.addActionListener(this);
81 add(item);
82 return item;
83 }
84
85 boolean actionMatch(ActionEvent ev, JMenuItem item) {
86 return ev.getActionCommand().equals(item.getActionCommand());
87 }
88
89 public void actionPerformed(ActionEvent ev) {
90 if (actionMatch(ev, exit)) {
Brian Hinz932fac52012-08-26 20:52:15 +000091 cc.close();
DRCc5dc0382011-05-13 21:42:14 +000092 } else if (actionMatch(ev, fullScreen)) {
93 cc.toggleFullScreen();
94 } else if (actionMatch(ev, restore)) {
95 if (cc.fullScreen) cc.toggleFullScreen();
96 cc.viewport.setExtendedState(JFrame.NORMAL);
97 } else if (actionMatch(ev, minimize)) {
98 if (cc.fullScreen) cc.toggleFullScreen();
99 cc.viewport.setExtendedState(JFrame.ICONIFIED);
100 } else if (actionMatch(ev, maximize)) {
101 if (cc.fullScreen) cc.toggleFullScreen();
102 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
103 } else if (actionMatch(ev, clipboard)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000104 cc.clipboardDialog.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000105 } else if (actionMatch(ev, f8)) {
Brian Hinz60530532012-05-16 03:51:42 +0000106 cc.writeKeyEvent(cc.menuKeyCode, true);
107 cc.writeKeyEvent(cc.menuKeyCode, false);
DRCc5dc0382011-05-13 21:42:14 +0000108 } else if (actionMatch(ev, ctrlAltDel)) {
109 cc.writeKeyEvent(Keysyms.Control_L, true);
110 cc.writeKeyEvent(Keysyms.Alt_L, true);
111 cc.writeKeyEvent(Keysyms.Delete, true);
112 cc.writeKeyEvent(Keysyms.Delete, false);
113 cc.writeKeyEvent(Keysyms.Alt_L, false);
114 cc.writeKeyEvent(Keysyms.Control_L, false);
115 } else if (actionMatch(ev, refresh)) {
116 cc.refresh();
117 } else if (actionMatch(ev, newConn)) {
118 VncViewer.newViewer(cc.viewer);
119 } else if (actionMatch(ev, options)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000120 cc.options.showDialog(cc.viewport);
Brian Hinz92ddde22012-08-29 03:56:01 +0000121 } else if (actionMatch(ev, save)) {
122 JFileChooser fc = new JFileChooser();
123 fc.setDialogTitle("Save current configuration as:");
124 fc.setApproveButtonText("OK");
125 fc.setFileHidingEnabled(false);
Brian Hinz4a95c7f2012-09-01 19:24:26 +0000126 Window fullScreenWindow = Viewport.getFullScreenWindow();
127 if (fullScreenWindow != null)
128 Viewport.setFullScreenWindow(null);
Brian Hinz92ddde22012-08-29 03:56:01 +0000129 int ret = fc.showOpenDialog(this);
Brian Hinz4a95c7f2012-09-01 19:24:26 +0000130 if (fullScreenWindow != null)
131 Viewport.setFullScreenWindow(fullScreenWindow);
Brian Hinz92ddde22012-08-29 03:56:01 +0000132 if (ret == JFileChooser.APPROVE_OPTION) {
133 String filename = fc.getSelectedFile().toString();
134 if (filename != null)
135 Configuration.save(filename);
136 }
DRCc5dc0382011-05-13 21:42:14 +0000137 } else if (actionMatch(ev, info)) {
138 cc.showInfo();
139 } else if (actionMatch(ev, about)) {
140 cc.showAbout();
141 } else if (actionMatch(ev, dismiss)) {
142 firePopupMenuCanceled();
143 }
144 }
145
146 CConn cc;
147 JMenuItem restore, move, size, minimize, maximize;
148 JMenuItem exit, clipboard, ctrlAltDel, refresh;
Brian Hinz92ddde22012-08-29 03:56:01 +0000149 JMenuItem newConn, options, save, info, about, dismiss;
DRCc5dc0382011-05-13 21:42:14 +0000150 static JMenuItem f8;
151 JCheckBoxMenuItem fullScreen;
152 static LogWriter vlog = new LogWriter("F8Menu");
153}