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.*; |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 25 | import java.io.File; |
| 26 | import javax.swing.JCheckBoxMenuItem; |
| 27 | import javax.swing.JDialog; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 28 | import javax.swing.JFrame; |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 29 | import javax.swing.JFileChooser; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 30 | import javax.swing.JMenuItem; |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 31 | import javax.swing.JOptionPane; |
| 32 | import javax.swing.JPopupMenu; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 33 | |
| 34 | import com.tigervnc.rfb.*; |
| 35 | |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 36 | import static com.tigervnc.vncviewer.Parameters.*; |
| 37 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 38 | public class F8Menu extends JPopupMenu implements ActionListener { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 39 | public F8Menu(CConn cc) { |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 40 | super("VNC Menu"); |
| 41 | setLightWeightPopupEnabled(false); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 42 | String os = System.getProperty("os.name"); |
| 43 | if (os.startsWith("Windows")) |
| 44 | com.sun.java.swing.plaf.windows.WindowsLookAndFeel.setMnemonicHidden(false); |
| 45 | this.cc = cc; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 46 | restore = addMenuItem("Restore",KeyEvent.VK_R); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 47 | restore.setEnabled(!embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 48 | move = addMenuItem("Move"); |
| 49 | move.setEnabled(false); |
| 50 | size = addMenuItem("Size"); |
| 51 | size.setEnabled(false); |
| 52 | minimize = addMenuItem("Minimize", KeyEvent.VK_N); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 53 | minimize.setEnabled(!embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 54 | maximize = addMenuItem("Maximize", KeyEvent.VK_X); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 55 | maximize.setEnabled(!embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 56 | addSeparator(); |
| 57 | exit = addMenuItem("Close Viewer", KeyEvent.VK_C); |
| 58 | addSeparator(); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 59 | fullScreenCheckbox = new JCheckBoxMenuItem("Full Screen"); |
| 60 | fullScreenCheckbox.setMnemonic(KeyEvent.VK_F); |
| 61 | fullScreenCheckbox.setSelected(fullScreen.getValue()); |
| 62 | fullScreenCheckbox.addActionListener(this); |
| 63 | fullScreenCheckbox.setEnabled(!embed.getValue()); |
| 64 | add(fullScreenCheckbox); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 65 | addSeparator(); |
| 66 | clipboard = addMenuItem("Clipboard..."); |
| 67 | addSeparator(); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 68 | int keyCode = MenuKey.getMenuKeyCode(); |
| 69 | String keyText = KeyEvent.getKeyText(keyCode); |
| 70 | f8 = addMenuItem("Send "+keyText, keyCode); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 71 | ctrlAltDel = addMenuItem("Send Ctrl-Alt-Del"); |
| 72 | addSeparator(); |
| 73 | refresh = addMenuItem("Refresh Screen", KeyEvent.VK_H); |
| 74 | addSeparator(); |
| 75 | newConn = addMenuItem("New connection...", KeyEvent.VK_W); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 76 | newConn.setEnabled(!embed.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 77 | options = addMenuItem("Options...", KeyEvent.VK_O); |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 78 | save = addMenuItem("Save connection info as...", KeyEvent.VK_S); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 79 | info = addMenuItem("Connection info...", KeyEvent.VK_I); |
Brian Hinz | 652953c | 2011-10-06 06:21:32 +0000 | [diff] [blame] | 80 | about = addMenuItem("About VncViewer...", KeyEvent.VK_A); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 81 | addSeparator(); |
| 82 | dismiss = addMenuItem("Dismiss menu"); |
| 83 | setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
| 84 | } |
| 85 | |
| 86 | JMenuItem addMenuItem(String str, int mnemonic) { |
| 87 | JMenuItem item = new JMenuItem(str, mnemonic); |
| 88 | item.addActionListener(this); |
| 89 | add(item); |
| 90 | return item; |
| 91 | } |
| 92 | |
| 93 | JMenuItem addMenuItem(String str) { |
| 94 | JMenuItem item = new JMenuItem(str); |
| 95 | item.addActionListener(this); |
| 96 | add(item); |
| 97 | return item; |
| 98 | } |
| 99 | |
| 100 | boolean actionMatch(ActionEvent ev, JMenuItem item) { |
| 101 | return ev.getActionCommand().equals(item.getActionCommand()); |
| 102 | } |
| 103 | |
| 104 | public void actionPerformed(ActionEvent ev) { |
| 105 | if (actionMatch(ev, exit)) { |
Brian Hinz | 932fac5 | 2012-08-26 20:52:15 +0000 | [diff] [blame] | 106 | cc.close(); |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 107 | } else if (actionMatch(ev, fullScreenCheckbox)) { |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 108 | cc.toggleFullScreen(); |
| 109 | } else if (actionMatch(ev, restore)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 110 | if (fullScreen.getValue()) cc.toggleFullScreen(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 111 | cc.viewport.setExtendedState(JFrame.NORMAL); |
| 112 | } else if (actionMatch(ev, minimize)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 113 | if (fullScreen.getValue()) cc.toggleFullScreen(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 114 | cc.viewport.setExtendedState(JFrame.ICONIFIED); |
| 115 | } else if (actionMatch(ev, maximize)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 116 | if (fullScreen.getValue()) cc.toggleFullScreen(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 117 | cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH); |
| 118 | } else if (actionMatch(ev, clipboard)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 119 | //ClipboardDialog dlg = new ClipboardDialog(cc); |
| 120 | ClipboardDialog.showDialog(cc.viewport); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 121 | } else if (actionMatch(ev, f8)) { |
Brian Hinz | 1e252c6 | 2013-02-09 02:42:14 +0000 | [diff] [blame] | 122 | cc.writeKeyEvent(MenuKey.getMenuKeySym(), true); |
| 123 | cc.writeKeyEvent(MenuKey.getMenuKeySym(), false); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 124 | } else if (actionMatch(ev, ctrlAltDel)) { |
| 125 | cc.writeKeyEvent(Keysyms.Control_L, true); |
| 126 | cc.writeKeyEvent(Keysyms.Alt_L, true); |
| 127 | cc.writeKeyEvent(Keysyms.Delete, true); |
| 128 | cc.writeKeyEvent(Keysyms.Delete, false); |
| 129 | cc.writeKeyEvent(Keysyms.Alt_L, false); |
| 130 | cc.writeKeyEvent(Keysyms.Control_L, false); |
| 131 | } else if (actionMatch(ev, refresh)) { |
| 132 | cc.refresh(); |
| 133 | } else if (actionMatch(ev, newConn)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 134 | VncViewer.newViewer(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 135 | } else if (actionMatch(ev, options)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 136 | OptionsDialog.showDialog(cc.viewport); |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 137 | } else if (actionMatch(ev, save)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 138 | String title = "Save the TigerVNC configuration to file"; |
| 139 | File dflt = new File(FileUtils.getVncHomeDir().concat("default.tigervnc")); |
| 140 | if (!dflt.exists() || !dflt.isFile()) |
| 141 | dflt = new File(FileUtils.getVncHomeDir()); |
| 142 | File f = Dialog.showChooser(title, dflt, this); |
| 143 | while (f != null && f.exists() && f.isFile()) { |
| 144 | String msg = f.getAbsolutePath(); |
| 145 | msg = msg.concat(" already exists. Do you want to overwrite?"); |
| 146 | Object[] options = {"Overwrite", "No \u21B5"}; |
| 147 | JOptionPane op = |
| 148 | new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, |
| 149 | JOptionPane.OK_CANCEL_OPTION, null, options, options[1]); |
| 150 | JDialog dlg = op.createDialog(this, "TigerVNC Viewer"); |
| 151 | dlg.setIconImage(VncViewer.frameIcon); |
| 152 | dlg.setAlwaysOnTop(true); |
| 153 | dlg.setVisible(true); |
| 154 | if (op.getValue() == options[0]) |
| 155 | break; |
| 156 | else |
| 157 | f = Dialog.showChooser(title, f, this); |
| 158 | } |
| 159 | if (f != null && (!f.exists() || f.canWrite())) |
| 160 | saveViewerParameters(f.getAbsolutePath(), vncServerName.getValue()); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 161 | } else if (actionMatch(ev, info)) { |
| 162 | cc.showInfo(); |
| 163 | } else if (actionMatch(ev, about)) { |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 164 | VncViewer.showAbout(cc.desktop); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 165 | } else if (actionMatch(ev, dismiss)) { |
| 166 | firePopupMenuCanceled(); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | CConn cc; |
| 171 | JMenuItem restore, move, size, minimize, maximize; |
| 172 | JMenuItem exit, clipboard, ctrlAltDel, refresh; |
Brian Hinz | 92ddde2 | 2012-08-29 03:56:01 +0000 | [diff] [blame] | 173 | JMenuItem newConn, options, save, info, about, dismiss; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 174 | static JMenuItem f8; |
Brian P. Hinz | c456387 | 2016-08-27 17:33:04 -0400 | [diff] [blame^] | 175 | JCheckBoxMenuItem fullScreenCheckbox; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 176 | static LogWriter vlog = new LogWriter("F8Menu"); |
| 177 | } |