blob: 07e8974ee8b5944e27d0dd23ee7e02fa477c5f67 [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;
Brian Hinz92ddde22012-08-29 03:56:01 +000025import javax.swing.JFileChooser;
DRCc5dc0382011-05-13 21:42:14 +000026import javax.swing.JPopupMenu;
DRCc5dc0382011-05-13 21:42:14 +000027import javax.swing.JMenuItem;
28import javax.swing.JCheckBoxMenuItem;
29
30import com.tigervnc.rfb.*;
31
32public class F8Menu extends JPopupMenu implements ActionListener {
33 public F8Menu(CConn cc_) {
34 super("VNC Menu");
35 setLightWeightPopupEnabled(false);
36 cc = cc_;
37 restore = addMenuItem("Restore",KeyEvent.VK_R);
38 move = addMenuItem("Move");
39 move.setEnabled(false);
40 size = addMenuItem("Size");
41 size.setEnabled(false);
42 minimize = addMenuItem("Minimize", KeyEvent.VK_N);
43 maximize = addMenuItem("Maximize", KeyEvent.VK_X);
44 addSeparator();
45 exit = addMenuItem("Close Viewer", KeyEvent.VK_C);
46 addSeparator();
47 fullScreen = new JCheckBoxMenuItem("Full Screen");
48 fullScreen.setMnemonic(KeyEvent.VK_F);
Brian Hinz64ee6fd2012-04-08 19:12:50 +000049 fullScreen.setSelected(cc.fullScreen);
DRCc5dc0382011-05-13 21:42:14 +000050 fullScreen.addActionListener(this);
51 add(fullScreen);
52 addSeparator();
53 clipboard = addMenuItem("Clipboard...");
54 addSeparator();
Brian Hinz3b5ce722012-08-26 18:06:52 +000055 f8 = addMenuItem("Send "+KeyEvent.getKeyText(MenuKey.getMenuKeyCode()), MenuKey.getMenuKeyCode());
DRCc5dc0382011-05-13 21:42:14 +000056 ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del");
57 addSeparator();
58 refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H);
59 addSeparator();
60 newConn = addMenuItem("New connection...", KeyEvent.VK_W);
61 options = addMenuItem("Options...", KeyEvent.VK_O);
Brian Hinz92ddde22012-08-29 03:56:01 +000062 save = addMenuItem("Save connection info as...", KeyEvent.VK_S);
DRCc5dc0382011-05-13 21:42:14 +000063 info = addMenuItem("Connection info...", KeyEvent.VK_I);
Brian Hinz652953c2011-10-06 06:21:32 +000064 about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
DRCc5dc0382011-05-13 21:42:14 +000065 addSeparator();
66 dismiss = addMenuItem("Dismiss menu");
67 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
68 }
69
70 JMenuItem addMenuItem(String str, int mnemonic) {
71 JMenuItem item = new JMenuItem(str, mnemonic);
72 item.addActionListener(this);
73 add(item);
74 return item;
75 }
76
77 JMenuItem addMenuItem(String str) {
78 JMenuItem item = new JMenuItem(str);
79 item.addActionListener(this);
80 add(item);
81 return item;
82 }
83
84 boolean actionMatch(ActionEvent ev, JMenuItem item) {
85 return ev.getActionCommand().equals(item.getActionCommand());
86 }
87
88 public void actionPerformed(ActionEvent ev) {
89 if (actionMatch(ev, exit)) {
Brian Hinz932fac52012-08-26 20:52:15 +000090 cc.close();
DRCc5dc0382011-05-13 21:42:14 +000091 } else if (actionMatch(ev, fullScreen)) {
92 cc.toggleFullScreen();
93 } else if (actionMatch(ev, restore)) {
94 if (cc.fullScreen) cc.toggleFullScreen();
95 cc.viewport.setExtendedState(JFrame.NORMAL);
96 } else if (actionMatch(ev, minimize)) {
97 if (cc.fullScreen) cc.toggleFullScreen();
98 cc.viewport.setExtendedState(JFrame.ICONIFIED);
99 } else if (actionMatch(ev, maximize)) {
100 if (cc.fullScreen) cc.toggleFullScreen();
101 cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
102 } else if (actionMatch(ev, clipboard)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000103 cc.clipboardDialog.showDialog(cc.viewport);
DRCc5dc0382011-05-13 21:42:14 +0000104 } else if (actionMatch(ev, f8)) {
Brian Hinz60530532012-05-16 03:51:42 +0000105 cc.writeKeyEvent(cc.menuKeyCode, true);
106 cc.writeKeyEvent(cc.menuKeyCode, false);
DRCc5dc0382011-05-13 21:42:14 +0000107 } else if (actionMatch(ev, ctrlAltDel)) {
108 cc.writeKeyEvent(Keysyms.Control_L, true);
109 cc.writeKeyEvent(Keysyms.Alt_L, true);
110 cc.writeKeyEvent(Keysyms.Delete, true);
111 cc.writeKeyEvent(Keysyms.Delete, false);
112 cc.writeKeyEvent(Keysyms.Alt_L, false);
113 cc.writeKeyEvent(Keysyms.Control_L, false);
114 } else if (actionMatch(ev, refresh)) {
115 cc.refresh();
116 } else if (actionMatch(ev, newConn)) {
117 VncViewer.newViewer(cc.viewer);
118 } else if (actionMatch(ev, options)) {
Brian Hinz06b92cf2011-10-24 02:11:53 +0000119 cc.options.showDialog(cc.viewport);
Brian Hinz92ddde22012-08-29 03:56:01 +0000120 } else if (actionMatch(ev, save)) {
121 JFileChooser fc = new JFileChooser();
122 fc.setDialogTitle("Save current configuration as:");
123 fc.setApproveButtonText("OK");
124 fc.setFileHidingEnabled(false);
125 int ret = fc.showOpenDialog(this);
126 if (ret == JFileChooser.APPROVE_OPTION) {
127 String filename = fc.getSelectedFile().toString();
128 if (filename != null)
129 Configuration.save(filename);
130 }
DRCc5dc0382011-05-13 21:42:14 +0000131 } else if (actionMatch(ev, info)) {
132 cc.showInfo();
133 } else if (actionMatch(ev, about)) {
134 cc.showAbout();
135 } else if (actionMatch(ev, dismiss)) {
136 firePopupMenuCanceled();
137 }
138 }
139
140 CConn cc;
141 JMenuItem restore, move, size, minimize, maximize;
142 JMenuItem exit, clipboard, ctrlAltDel, refresh;
Brian Hinz92ddde22012-08-29 03:56:01 +0000143 JMenuItem newConn, options, save, info, about, dismiss;
DRCc5dc0382011-05-13 21:42:14 +0000144 static JMenuItem f8;
145 JCheckBoxMenuItem fullScreen;
146 static LogWriter vlog = new LogWriter("F8Menu");
147}