DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Brian Hinz | 430d8cf | 2014-01-02 01:23:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011-2014 Brian P. Hinz |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 3 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 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. |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 8 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 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. |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 13 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 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 Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame] | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 17 | * USA. |
| 18 | */ |
| 19 | |
| 20 | package com.tigervnc.vncviewer; |
| 21 | |
Brian Hinz | 4a95c7f | 2012-09-01 19:24:26 +0000 | [diff] [blame] | 22 | import java.awt.*; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 23 | import java.awt.Cursor; |
| 24 | import java.awt.event.*; |
| 25 | import javax.swing.JFrame; |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 26 | import javax.swing.JFileChooser; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 27 | import javax.swing.JPopupMenu; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 28 | import javax.swing.JMenuItem; |
| 29 | import javax.swing.JCheckBoxMenuItem; |
| 30 | |
| 31 | import com.tigervnc.rfb.*; |
| 32 | |
| 33 | public 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); |
Brian P. Hinz | 09e1507 | 2015-08-20 18:27:15 -0400 | [diff] [blame] | 39 | restore.setEnabled(!cc.viewer.embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 40 | move = addMenuItem("Move"); |
| 41 | move.setEnabled(false); |
| 42 | size = addMenuItem("Size"); |
| 43 | size.setEnabled(false); |
| 44 | minimize = addMenuItem("Minimize", KeyEvent.VK_N); |
Brian P. Hinz | 09e1507 | 2015-08-20 18:27:15 -0400 | [diff] [blame] | 45 | minimize.setEnabled(!cc.viewer.embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 46 | maximize = addMenuItem("Maximize", KeyEvent.VK_X); |
Brian P. Hinz | 09e1507 | 2015-08-20 18:27:15 -0400 | [diff] [blame] | 47 | maximize.setEnabled(!cc.viewer.embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 48 | addSeparator(); |
| 49 | exit = addMenuItem("Close Viewer", KeyEvent.VK_C); |
| 50 | addSeparator(); |
| 51 | fullScreen = new JCheckBoxMenuItem("Full Screen"); |
| 52 | fullScreen.setMnemonic(KeyEvent.VK_F); |
Brian Hinz | 64ee6fd | 2012-04-08 19:12:50 +0000 | [diff] [blame] | 53 | fullScreen.setSelected(cc.fullScreen); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 54 | fullScreen.addActionListener(this); |
Brian Hinz | 430d8cf | 2014-01-02 01:23:56 +0000 | [diff] [blame] | 55 | fullScreen.setEnabled(!cc.viewer.embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 56 | add(fullScreen); |
| 57 | addSeparator(); |
| 58 | clipboard = addMenuItem("Clipboard..."); |
| 59 | addSeparator(); |
Brian Hinz | 3b5ce72 | 2012-08-26 18:06:52 +0000 | [diff] [blame] | 60 | f8 = addMenuItem("Send "+KeyEvent.getKeyText(MenuKey.getMenuKeyCode()), MenuKey.getMenuKeyCode()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 61 | ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del"); |
| 62 | addSeparator(); |
| 63 | refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H); |
| 64 | addSeparator(); |
| 65 | newConn = addMenuItem("New connection...", KeyEvent.VK_W); |
Brian Hinz | 430d8cf | 2014-01-02 01:23:56 +0000 | [diff] [blame] | 66 | newConn.setEnabled(!cc.viewer.embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 67 | options = addMenuItem("Options...", KeyEvent.VK_O); |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 68 | save = addMenuItem("Save connection info as...", KeyEvent.VK_S); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 69 | info = addMenuItem("Connection info...", KeyEvent.VK_I); |
Brian Hinz | 652953c | 2011-10-06 06:21:32 +0000 | [diff] [blame] | 70 | about = addMenuItem("About VncViewer...", KeyEvent.VK_A); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 71 | addSeparator(); |
| 72 | dismiss = addMenuItem("Dismiss menu"); |
| 73 | setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
| 74 | } |
| 75 | |
| 76 | JMenuItem addMenuItem(String str, int mnemonic) { |
| 77 | JMenuItem item = new JMenuItem(str, mnemonic); |
| 78 | item.addActionListener(this); |
| 79 | add(item); |
| 80 | return item; |
| 81 | } |
| 82 | |
| 83 | JMenuItem addMenuItem(String str) { |
| 84 | JMenuItem item = new JMenuItem(str); |
| 85 | item.addActionListener(this); |
| 86 | add(item); |
| 87 | return item; |
| 88 | } |
| 89 | |
| 90 | boolean actionMatch(ActionEvent ev, JMenuItem item) { |
| 91 | return ev.getActionCommand().equals(item.getActionCommand()); |
| 92 | } |
| 93 | |
| 94 | public void actionPerformed(ActionEvent ev) { |
| 95 | if (actionMatch(ev, exit)) { |
Brian Hinz | 932fac5 | 2012-08-26 20:52:15 +0000 | [diff] [blame] | 96 | cc.close(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 97 | } else if (actionMatch(ev, fullScreen)) { |
| 98 | cc.toggleFullScreen(); |
| 99 | } else if (actionMatch(ev, restore)) { |
| 100 | if (cc.fullScreen) cc.toggleFullScreen(); |
| 101 | cc.viewport.setExtendedState(JFrame.NORMAL); |
| 102 | } else if (actionMatch(ev, minimize)) { |
| 103 | if (cc.fullScreen) cc.toggleFullScreen(); |
| 104 | cc.viewport.setExtendedState(JFrame.ICONIFIED); |
| 105 | } else if (actionMatch(ev, maximize)) { |
| 106 | if (cc.fullScreen) cc.toggleFullScreen(); |
| 107 | cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH); |
| 108 | } else if (actionMatch(ev, clipboard)) { |
Brian Hinz | 06b92cf | 2011-10-24 02:11:53 +0000 | [diff] [blame] | 109 | cc.clipboardDialog.showDialog(cc.viewport); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 110 | } else if (actionMatch(ev, f8)) { |
Brian Hinz | 1e252c6 | 2013-02-09 02:42:14 +0000 | [diff] [blame] | 111 | cc.writeKeyEvent(MenuKey.getMenuKeySym(), true); |
| 112 | cc.writeKeyEvent(MenuKey.getMenuKeySym(), false); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 113 | } else if (actionMatch(ev, ctrlAltDel)) { |
| 114 | cc.writeKeyEvent(Keysyms.Control_L, true); |
| 115 | cc.writeKeyEvent(Keysyms.Alt_L, true); |
| 116 | cc.writeKeyEvent(Keysyms.Delete, true); |
| 117 | cc.writeKeyEvent(Keysyms.Delete, false); |
| 118 | cc.writeKeyEvent(Keysyms.Alt_L, false); |
| 119 | cc.writeKeyEvent(Keysyms.Control_L, false); |
| 120 | } else if (actionMatch(ev, refresh)) { |
| 121 | cc.refresh(); |
| 122 | } else if (actionMatch(ev, newConn)) { |
| 123 | VncViewer.newViewer(cc.viewer); |
| 124 | } else if (actionMatch(ev, options)) { |
Brian Hinz | 06b92cf | 2011-10-24 02:11:53 +0000 | [diff] [blame] | 125 | cc.options.showDialog(cc.viewport); |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 126 | } else if (actionMatch(ev, save)) { |
| 127 | JFileChooser fc = new JFileChooser(); |
| 128 | fc.setDialogTitle("Save current configuration as:"); |
| 129 | fc.setApproveButtonText("OK"); |
| 130 | fc.setFileHidingEnabled(false); |
Brian Hinz | 4a95c7f | 2012-09-01 19:24:26 +0000 | [diff] [blame] | 131 | Window fullScreenWindow = Viewport.getFullScreenWindow(); |
| 132 | if (fullScreenWindow != null) |
| 133 | Viewport.setFullScreenWindow(null); |
Brian Hinz | 8b61dd5 | 2013-03-01 00:55:42 +0000 | [diff] [blame] | 134 | int ret = fc.showOpenDialog(cc.viewport); |
Brian Hinz | 4a95c7f | 2012-09-01 19:24:26 +0000 | [diff] [blame] | 135 | if (fullScreenWindow != null) |
| 136 | Viewport.setFullScreenWindow(fullScreenWindow); |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 137 | if (ret == JFileChooser.APPROVE_OPTION) { |
| 138 | String filename = fc.getSelectedFile().toString(); |
| 139 | if (filename != null) |
| 140 | Configuration.save(filename); |
| 141 | } |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 142 | } else if (actionMatch(ev, info)) { |
| 143 | cc.showInfo(); |
| 144 | } else if (actionMatch(ev, about)) { |
| 145 | cc.showAbout(); |
| 146 | } else if (actionMatch(ev, dismiss)) { |
| 147 | firePopupMenuCanceled(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | CConn cc; |
| 152 | JMenuItem restore, move, size, minimize, maximize; |
| 153 | JMenuItem exit, clipboard, ctrlAltDel, refresh; |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 154 | JMenuItem newConn, options, save, info, about, dismiss; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 155 | static JMenuItem f8; |
| 156 | JCheckBoxMenuItem fullScreen; |
| 157 | static LogWriter vlog = new LogWriter("F8Menu"); |
| 158 | } |