DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Brian Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 Brian P. Hinz |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 3 | * |
| 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 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 | |
| 22 | import java.awt.Cursor; |
| 23 | import java.awt.event.*; |
| 24 | import javax.swing.JFrame; |
| 25 | import javax.swing.JPopupMenu; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 26 | import javax.swing.JMenuItem; |
| 27 | import javax.swing.JCheckBoxMenuItem; |
| 28 | |
| 29 | import com.tigervnc.rfb.*; |
| 30 | |
| 31 | public 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 Hinz | 64ee6fd | 2012-04-08 19:12:50 +0000 | [diff] [blame] | 48 | fullScreen.setSelected(cc.fullScreen); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 49 | fullScreen.addActionListener(this); |
| 50 | add(fullScreen); |
| 51 | addSeparator(); |
| 52 | clipboard = addMenuItem("Clipboard..."); |
| 53 | addSeparator(); |
Brian Hinz | 3b5ce72 | 2012-08-26 18:06:52 +0000 | [diff] [blame] | 54 | f8 = addMenuItem("Send "+KeyEvent.getKeyText(MenuKey.getMenuKeyCode()), MenuKey.getMenuKeyCode()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 55 | 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 Hinz | 652953c | 2011-10-06 06:21:32 +0000 | [diff] [blame] | 62 | about = addMenuItem("About VncViewer...", KeyEvent.VK_A); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 63 | 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)) { |
Brian Hinz | 8d9c463 | 2012-07-22 20:25:57 +0000 | [diff] [blame] | 88 | cc.deleteWindow(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 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 Hinz | 06b92cf | 2011-10-24 02:11:53 +0000 | [diff] [blame] | 101 | cc.clipboardDialog.showDialog(cc.viewport); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 102 | } else if (actionMatch(ev, f8)) { |
Brian Hinz | 6053053 | 2012-05-16 03:51:42 +0000 | [diff] [blame] | 103 | cc.writeKeyEvent(cc.menuKeyCode, true); |
| 104 | cc.writeKeyEvent(cc.menuKeyCode, false); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 105 | } 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 Hinz | 06b92cf | 2011-10-24 02:11:53 +0000 | [diff] [blame] | 117 | cc.options.showDialog(cc.viewport); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 118 | } 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 | } |