You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OptionsDialog.java 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011-2015 Brian P. Hinz
  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
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  17. * USA.
  18. */
  19. package com.tigervnc.vncviewer;
  20. import java.awt.*;
  21. import java.awt.event.*;
  22. import java.io.File;
  23. import java.text.Format;
  24. import java.text.NumberFormat;
  25. import javax.swing.*;
  26. import javax.swing.border.*;
  27. import com.tigervnc.rfb.*;
  28. class OptionsDialog extends Dialog implements
  29. ActionListener,
  30. ItemListener
  31. {
  32. private class IntegerTextField extends JFormattedTextField {
  33. public IntegerTextField(Format format) {
  34. super(format);
  35. }
  36. @Override
  37. protected void processFocusEvent(final FocusEvent e) {
  38. if (e.isTemporary())
  39. return;
  40. if (e.getID() == FocusEvent.FOCUS_LOST)
  41. if (getText() == null || getText().isEmpty())
  42. setValue(null);
  43. super.processFocusEvent(e);
  44. }
  45. }
  46. // Constants
  47. // Static variables
  48. static LogWriter vlog = new LogWriter("OptionsDialog");
  49. CConn cc;
  50. JPanel FormatPanel, InputsPanel, MiscPanel, DefaultsPanel, SecPanel, ScreenPanel;
  51. JCheckBox autoSelect, customCompressLevel, noJpeg;
  52. @SuppressWarnings({"rawtypes"})
  53. JComboBox menuKey, compressLevel, qualityLevel, scalingFactor;
  54. ButtonGroup encodingGroup, colourGroup;
  55. JRadioButton zrle, hextile, tight, raw;
  56. JRadioButton fullColour, mediumColour, lowColour, veryLowColour;
  57. JCheckBox viewOnly, acceptClipboard, sendClipboard, acceptBell;
  58. JCheckBox desktopSize, fullScreen, fullScreenAllMonitors, shared, useLocalCursor;
  59. JCheckBox secVeNCrypt, encNone, encTLS, encX509;
  60. JCheckBox secNone, secVnc, secPlain, secIdent, sendLocalUsername;
  61. JButton okButton, cancelButton;
  62. JButton ca, crl;
  63. JButton cfLoadButton, cfSaveAsButton, defSaveButton, defReloadButton, defClearButton;
  64. JTextField desktopWidth, desktopHeight;
  65. @SuppressWarnings({"rawtypes","unchecked"})
  66. public OptionsDialog(CConn cc_) {
  67. super(true);
  68. cc = cc_;
  69. setResizable(false);
  70. setTitle("VNC Viewer Options");
  71. getContentPane().setLayout(
  72. new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
  73. JTabbedPane tabPane = new JTabbedPane();
  74. tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
  75. ButtonGroup encodingGroup = new ButtonGroup();
  76. ButtonGroup colourGroup = new ButtonGroup();
  77. // Compression tab
  78. FormatPanel=new JPanel(new GridBagLayout());
  79. autoSelect = new JCheckBox("Auto Select");
  80. autoSelect.addItemListener(this);
  81. JPanel encodingPanel = new JPanel(new GridBagLayout());
  82. encodingPanel.setBorder(BorderFactory.createTitledBorder("Preferred encoding"));
  83. tight = addRadioCheckbox("Tight", encodingGroup, encodingPanel);
  84. zrle = addRadioCheckbox("ZRLE", encodingGroup, encodingPanel);
  85. hextile = addRadioCheckbox("Hextile", encodingGroup, encodingPanel);
  86. raw = addRadioCheckbox("Raw", encodingGroup, encodingPanel);
  87. JPanel tightPanel = new JPanel(new GridBagLayout());
  88. customCompressLevel = new JCheckBox("Custom Compression Level");
  89. customCompressLevel.addItemListener(this);
  90. Object[] compressionLevels = { 1, 2, 3, 4, 5, 6 };
  91. compressLevel = new JComboBox(compressionLevels);
  92. JLabel compressionLabel = new JLabel("Level (1=fast, 6=best [4-6 are rarely useful])");
  93. noJpeg = new JCheckBox("Allow JPEG Compression");
  94. noJpeg.addItemListener(this);
  95. Object[] qualityLevels = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  96. qualityLevel = new JComboBox(qualityLevels);
  97. JLabel qualityLabel = new JLabel("Quality (0=poor, 9=best)");
  98. // Hack to set the left inset on editable JComboBox
  99. if (UIManager.getLookAndFeel().getID() == "Windows") {
  100. compressLevel.setBorder(BorderFactory.createCompoundBorder(compressLevel.getBorder(),
  101. BorderFactory.createEmptyBorder(0,1,0,0)));
  102. } else if (UIManager.getLookAndFeel().getID() == "Metal") {
  103. ComboBoxEditor editor = compressLevel.getEditor();
  104. JTextField jtf = (JTextField)editor.getEditorComponent();
  105. jtf.setBorder(new CompoundBorder(jtf.getBorder(), new EmptyBorder(0,2,0,0)));
  106. }
  107. Dimension size = compressLevel.getPreferredSize();
  108. compressLevel.setEditable(true);
  109. compressLevel.setPreferredSize(size);
  110. addGBComponent(customCompressLevel, tightPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(0,0,0,0));
  111. addGBComponent(compressLevel, tightPanel, 0, 1, 1, 1, 2, 2, 0, 0, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(0,20,0,0));
  112. addGBComponent(compressionLabel, tightPanel, 1, 1, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,5,0,0));
  113. addGBComponent(noJpeg, tightPanel, 0, 2, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(4,0,0,0));
  114. addGBComponent(qualityLevel, tightPanel, 0, 3, 1, 1, 2, 2, 0, 0, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(0,20,0,0));
  115. addGBComponent(qualityLabel, tightPanel, 1, 3, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,5,0,0));
  116. JPanel colourPanel = new JPanel(new GridBagLayout());
  117. colourPanel.setBorder(BorderFactory.createTitledBorder("Color level"));
  118. fullColour = addRadioCheckbox("Full (all available colors)", colourGroup, colourPanel);
  119. mediumColour = addRadioCheckbox("Medium (256 colors)", colourGroup, colourPanel);
  120. lowColour = addRadioCheckbox("Low (64 colours)", colourGroup, colourPanel);
  121. veryLowColour = addRadioCheckbox("Very low(8 colors)", colourGroup, colourPanel);
  122. addGBComponent(autoSelect,FormatPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,5));
  123. addGBComponent(encodingPanel,FormatPanel, 0, 1, 1, 1, 2, 2, 3, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,5,0,5));
  124. addGBComponent(colourPanel,FormatPanel, 1, 1, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_END, new Insets(0,0,0,5));
  125. addGBComponent(tightPanel,FormatPanel, 0, 2, 2, GridBagConstraints.REMAINDER, 2, 2, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(0,5,0,5));
  126. // Input tab
  127. InputsPanel=new JPanel(new GridBagLayout());
  128. viewOnly = new JCheckBox("View Only (ignore mouse & keyboard)");
  129. viewOnly.addItemListener(this);
  130. acceptClipboard = new JCheckBox("Accept clipboard from server");
  131. acceptClipboard.addItemListener(this);
  132. sendClipboard = new JCheckBox("Send clipboard to server");
  133. sendClipboard.addItemListener(this);
  134. JLabel menuKeyLabel = new JLabel("Menu Key");
  135. String[] menuKeys = new String[MenuKey.getMenuKeySymbolCount()];
  136. for (int i = 0; i < MenuKey.getMenuKeySymbolCount(); i++)
  137. menuKeys[i] = KeyEvent.getKeyText(MenuKey.getMenuKeySymbols()[i].keycode);
  138. menuKey = new JComboBox(menuKeys);
  139. menuKey.addItemListener(this);
  140. addGBComponent(viewOnly,InputsPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  141. addGBComponent(acceptClipboard,InputsPanel, 0, 1, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  142. addGBComponent(sendClipboard,InputsPanel, 0, 2, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  143. addGBComponent(menuKeyLabel,InputsPanel, 0, 3, 1, GridBagConstraints.REMAINDER, 2, 2, 1, 1, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(8,8,0,5));
  144. addGBComponent(menuKey,InputsPanel, 1, 3, 1, GridBagConstraints.REMAINDER, 2, 2, 25, 1, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,5));
  145. // Screen tab
  146. ScreenPanel=new JPanel(new GridBagLayout());
  147. desktopSize = new JCheckBox("Resize remote session on connect");
  148. desktopSize.addItemListener(this);
  149. desktopSize.setEnabled(cc.viewer.desktopSize.getValue() != null);
  150. NumberFormat format = NumberFormat.getIntegerInstance();
  151. format.setMaximumIntegerDigits(5);
  152. format.setMinimumIntegerDigits(0);
  153. format.setGroupingUsed(false);
  154. desktopWidth = new IntegerTextField(format);
  155. desktopWidth.setColumns(4);
  156. desktopWidth.setEnabled(desktopSize.isSelected());
  157. desktopHeight = new IntegerTextField(format);
  158. desktopHeight.setColumns(4);
  159. desktopHeight.setEnabled(desktopSize.isSelected());
  160. JPanel desktopSizePanel = new JPanel();
  161. desktopSizePanel.add(desktopWidth);
  162. desktopSizePanel.add(new JLabel("x"));
  163. desktopSizePanel.add(desktopHeight);
  164. fullScreen = new JCheckBox("Full-screen mode");
  165. fullScreen.addItemListener(this);
  166. fullScreen.setEnabled(!cc.viewer.embed.getValue());
  167. fullScreenAllMonitors = new JCheckBox("Enable full-screen mode over all monitors");
  168. fullScreenAllMonitors.addItemListener(this);
  169. fullScreenAllMonitors.setEnabled(!cc.viewer.embed.getValue());
  170. JLabel scalingFactorLabel = new JLabel("Scaling Factor");
  171. Object[] scalingFactors = {
  172. "Auto", "Fixed Aspect Ratio", "50%", "75%", "95%", "100%", "105%",
  173. "125%", "150%", "175%", "200%", "250%", "300%", "350%", "400%" };
  174. scalingFactor = new JComboBox(scalingFactors);
  175. // Hack to set the left inset on editable JComboBox
  176. if (UIManager.getLookAndFeel().getID() == "Windows") {
  177. scalingFactor.setBorder(BorderFactory.createCompoundBorder(scalingFactor.getBorder(),
  178. BorderFactory.createEmptyBorder(0,1,0,0)));
  179. } else if (UIManager.getLookAndFeel().getID() == "Metal") {
  180. ComboBoxEditor sfe = scalingFactor.getEditor();
  181. JTextField sfeTextField = (JTextField)sfe.getEditorComponent();
  182. sfeTextField.setBorder(new CompoundBorder(sfeTextField.getBorder(),
  183. new EmptyBorder(0,2,0,0)));
  184. }
  185. scalingFactor.setEditable(true);
  186. scalingFactor.addItemListener(this);
  187. scalingFactor.setEnabled(!cc.viewer.embed.getValue());
  188. addGBComponent(desktopSize,ScreenPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  189. addGBComponent(desktopSizePanel,ScreenPanel, 0, 1, 2, 1, 2, 2, 1, 0, GridBagConstraints.REMAINDER, GridBagConstraints.LINE_START, new Insets(0,20,0,0));
  190. addGBComponent(fullScreen,ScreenPanel, 0, 2, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,5,0,5));
  191. addGBComponent(fullScreenAllMonitors,ScreenPanel, 0, 3, 4, 1, 2, 2, 1, 0, GridBagConstraints.REMAINDER, GridBagConstraints.LINE_START, new Insets(4,25,0,5));
  192. addGBComponent(scalingFactorLabel,ScreenPanel, 0, 4, 1, GridBagConstraints.REMAINDER, 2, 2, 1, 1, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(8,8,0,5));
  193. addGBComponent(scalingFactor,ScreenPanel, 1, 4, 1, GridBagConstraints.REMAINDER, 2, 2, 25, 1, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,5));
  194. // Misc tab
  195. MiscPanel=new JPanel(new GridBagLayout());
  196. shared = new JCheckBox("Shared connection (do not disconnect other viewers)");
  197. shared.addItemListener(this);
  198. useLocalCursor = new JCheckBox("Render cursor locally");
  199. useLocalCursor.addItemListener(this);
  200. acceptBell = new JCheckBox("Beep when requested by the server");
  201. acceptBell.addItemListener(this);
  202. addGBComponent(shared,MiscPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  203. addGBComponent(useLocalCursor,MiscPanel, 0, 1, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,5,0,5));
  204. addGBComponent(acceptBell,MiscPanel, 0, 2, 2, 1, 2, 2, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,5));
  205. // load/save tab
  206. DefaultsPanel=new JPanel(new GridBagLayout());
  207. JPanel configPanel = new JPanel(new GridBagLayout());
  208. configPanel.setBorder(BorderFactory.createTitledBorder("Configuration File"));
  209. cfLoadButton = new JButton("Load");
  210. cfLoadButton.addActionListener(this);
  211. addGBComponent(cfLoadButton,configPanel, 0, 0, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
  212. cfSaveAsButton = new JButton("Save As...");
  213. cfSaveAsButton.addActionListener(this);
  214. addGBComponent(cfSaveAsButton,configPanel, 0, 1, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
  215. JPanel defaultsPanel = new JPanel(new GridBagLayout());
  216. defaultsPanel.setBorder(BorderFactory.createTitledBorder("Defaults"));
  217. defClearButton = new JButton("Clear");
  218. defClearButton.addActionListener(this);
  219. addGBComponent(defClearButton,defaultsPanel, 0, 0, 1, 1, 0, 0, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
  220. defReloadButton = new JButton("Reload");
  221. defReloadButton.addActionListener(this);
  222. addGBComponent(defReloadButton,defaultsPanel, 0, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
  223. defSaveButton = new JButton("Save");
  224. defSaveButton.addActionListener(this);
  225. addGBComponent(defSaveButton,defaultsPanel, 0, 2, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
  226. addGBComponent(configPanel,DefaultsPanel, 0, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,5,4,5));
  227. addGBComponent(defaultsPanel,DefaultsPanel, 1, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,0,4,5));
  228. // security tab
  229. SecPanel=new JPanel(new GridBagLayout());
  230. JPanel encryptionPanel = new JPanel(new GridBagLayout());
  231. encryptionPanel.setBorder(BorderFactory.createTitledBorder("Encryption"));
  232. encNone = addCheckbox("None", null, encryptionPanel);
  233. encTLS = addCheckbox("Anonymous TLS", null, encryptionPanel);
  234. encX509 = addJCheckBox("TLS with X.509 certificates", null, encryptionPanel, new GridBagConstraints(0,2,3,1,1,1,GridBagConstraints.LINE_START,GridBagConstraints.REMAINDER,new Insets(0,0,0,0),0,0));
  235. ca = new JButton("Load CA certificate");
  236. ca.addActionListener(this);
  237. crl = new JButton("Load CRL certificate");
  238. crl.addActionListener(this);
  239. addGBComponent(ca, encryptionPanel, 0, 3, 1, 1, 2, 2, 1, 0, GridBagConstraints.NONE, GridBagConstraints.LINE_START, new Insets(2,20,2,2));
  240. addGBComponent(crl, encryptionPanel, 1, 3, 1, 1, 2, 2, 1, 0, GridBagConstraints.NONE, GridBagConstraints.LINE_START, new Insets(2,2,2,2));
  241. JPanel authPanel = new JPanel(new GridBagLayout());
  242. authPanel.setBorder(BorderFactory.createTitledBorder("Authentication"));
  243. secNone = addCheckbox("None", null, authPanel);
  244. secVnc = addCheckbox("Standard VNC", null, authPanel);
  245. secPlain = addJCheckBox("Plaintext", null, authPanel, new GridBagConstraints(0,2,1,1,1,1,GridBagConstraints.LINE_START,GridBagConstraints.NONE,new Insets(0,0,0,5),0,0));
  246. secIdent = addJCheckBox("Ident", null, authPanel, new GridBagConstraints(0,3,1,1,1,1,GridBagConstraints.LINE_START,GridBagConstraints.NONE,new Insets(0,0,0,5),0,0));
  247. sendLocalUsername = new JCheckBox("Send Local Username");
  248. sendLocalUsername.addItemListener(this);
  249. addGBComponent(sendLocalUsername, authPanel, 1, 2, 1, 2, 0, 0, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,20,0,0));
  250. secVeNCrypt = new JCheckBox("Extended encryption and authentication methods (VeNCrypt)");
  251. secVeNCrypt.addItemListener(this);
  252. addGBComponent(secVeNCrypt,SecPanel, 0, 0, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,30));
  253. addGBComponent(encryptionPanel,SecPanel, 0, 1, 1, 1, 2, 2, 1, 0, GridBagConstraints.NONE, GridBagConstraints.LINE_START, new Insets(0,10,2,5));
  254. addGBComponent(authPanel,SecPanel, 0, 3, 1, 1, 2, 2, 1, 1, GridBagConstraints.NONE, GridBagConstraints.FIRST_LINE_START, new Insets(2,10,2,5));
  255. tabPane.add(FormatPanel);
  256. tabPane.add(ScreenPanel);
  257. tabPane.add(InputsPanel);
  258. tabPane.add(MiscPanel);
  259. tabPane.add(DefaultsPanel);
  260. tabPane.add(SecPanel);
  261. tabPane.addTab("Compression", FormatPanel);
  262. tabPane.addTab("Security", SecPanel);
  263. tabPane.addTab("Input", InputsPanel);
  264. tabPane.addTab("Screen", ScreenPanel);
  265. tabPane.addTab("Misc", MiscPanel);
  266. tabPane.addTab("Load / Save", DefaultsPanel);
  267. tabPane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
  268. okButton = new JButton("OK");
  269. okButton.setPreferredSize(new Dimension(90,30));
  270. okButton.addActionListener(this);
  271. cancelButton = new JButton("Cancel");
  272. cancelButton.setPreferredSize(new Dimension(90,30));
  273. cancelButton.addActionListener(this);
  274. JPanel buttonPane = new JPanel();
  275. buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
  276. buttonPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  277. buttonPane.add(Box.createHorizontalGlue());
  278. buttonPane.add(okButton);
  279. buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
  280. buttonPane.add(cancelButton);
  281. buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
  282. this.getContentPane().add(tabPane);
  283. this.getContentPane().add(buttonPane);
  284. pack();
  285. }
  286. public void initDialog() {
  287. if (cc != null) cc.setOptions();
  288. zrle.setEnabled(!autoSelect.isSelected());
  289. hextile.setEnabled(!autoSelect.isSelected());
  290. tight.setEnabled(!autoSelect.isSelected());
  291. raw.setEnabled(!autoSelect.isSelected());
  292. fullColour.setEnabled(!autoSelect.isSelected());
  293. mediumColour.setEnabled(!autoSelect.isSelected());
  294. lowColour.setEnabled(!autoSelect.isSelected());
  295. veryLowColour.setEnabled(!autoSelect.isSelected());
  296. compressLevel.setEnabled(customCompressLevel.isSelected());
  297. qualityLevel.setEnabled(noJpeg.isSelected());
  298. fullScreenAllMonitors.setEnabled(fullScreen.isSelected());
  299. sendLocalUsername.setEnabled(secVeNCrypt.isEnabled()&&
  300. (secPlain.isSelected()||secIdent.isSelected()));
  301. }
  302. private void updatePreferences() {
  303. if (autoSelect.isSelected()) {
  304. UserPreferences.set("global", "AutoSelect", true);
  305. } else {
  306. UserPreferences.set("global", "AutoSelect", false);
  307. if (zrle.isSelected()) {
  308. UserPreferences.set("global", "PreferredEncoding", "ZRLE");
  309. } else if (hextile.isSelected()) {
  310. UserPreferences.set("global", "PreferredEncoding", "hextile");
  311. } else if (tight.isSelected()) {
  312. UserPreferences.set("global", "PreferredEncoding", "Tight");
  313. } else if (raw.isSelected()) {
  314. UserPreferences.set("global", "PreferredEncoding", "raw");
  315. }
  316. }
  317. if (fullColour.isSelected()) {
  318. UserPreferences.set("global", "FullColour", true);
  319. } else {
  320. UserPreferences.set("global", "FullColour", false);
  321. if (mediumColour.isSelected()) {
  322. UserPreferences.set("global", "LowColorLevel", 2);
  323. } else if (lowColour.isSelected()) {
  324. UserPreferences.set("global", "LowColorLevel", 1);
  325. } else if (veryLowColour.isSelected()) {
  326. UserPreferences.set("global", "LowColorLevel", 0);
  327. }
  328. }
  329. UserPreferences.set("global", "NoJPEG", !noJpeg.isSelected());
  330. UserPreferences.set("global", "QualityLevel", (Integer)qualityLevel.getSelectedItem());
  331. UserPreferences.set("global", "CustomCompressLevel", customCompressLevel.isSelected());
  332. UserPreferences.set("global", "CompressLevel", (Integer)compressLevel.getSelectedItem());
  333. UserPreferences.set("global", "ViewOnly", viewOnly.isSelected());
  334. UserPreferences.set("global", "AcceptClipboard", acceptClipboard.isSelected());
  335. UserPreferences.set("global", "SendClipboard", sendClipboard.isSelected());
  336. String menuKeyStr = MenuKey.getMenuKeySymbols()[menuKey.getSelectedIndex()].name;
  337. UserPreferences.set("global", "MenuKey", menuKeyStr);
  338. String desktopSizeString =
  339. desktopSize.isSelected() ? desktopWidth.getText() + "x" + desktopHeight.getText() : "";
  340. UserPreferences.set("global", "DesktopSize", desktopSizeString);
  341. UserPreferences.set("global", "FullScreen", fullScreen.isSelected());
  342. UserPreferences.set("global", "FullScreenAllMonitors", fullScreenAllMonitors.isSelected());
  343. UserPreferences.set("global", "Shared", shared.isSelected());
  344. UserPreferences.set("global", "UseLocalCursor", useLocalCursor.isSelected());
  345. UserPreferences.set("global", "AcceptBell", acceptBell.isSelected());
  346. String scaleString = scalingFactor.getSelectedItem().toString();
  347. if (scaleString.equalsIgnoreCase("Auto")) {
  348. UserPreferences.set("global", "ScalingFactor", "Auto");
  349. } else if(scaleString.equalsIgnoreCase("Fixed Aspect Ratio")) {
  350. UserPreferences.set("global", "ScalingFactor", "FixedRatio");
  351. } else {
  352. scaleString=scaleString.substring(0, scaleString.length()-1);
  353. UserPreferences.set("global", "ScalingFactor", scaleString);
  354. }
  355. UserPreferences.set("viewer", "secVeNCrypt", secVeNCrypt.isSelected());
  356. UserPreferences.set("viewer", "encNone", encNone.isSelected());
  357. UserPreferences.set("viewer", "encTLS", encTLS.isSelected());
  358. UserPreferences.set("viewer", "encX509", encX509.isSelected());
  359. UserPreferences.set("viewer", "secNone", secNone.isSelected());
  360. UserPreferences.set("viewer", "secVnc", secVnc.isSelected());
  361. UserPreferences.set("viewer", "secPlain", secPlain.isSelected());
  362. UserPreferences.set("viewer", "secIdent", secIdent.isSelected());
  363. UserPreferences.set("global", "SendLocalUsername", sendLocalUsername.isSelected());
  364. if (CSecurityTLS.x509ca.getValueStr() != "")
  365. UserPreferences.set("viewer", "x509ca", CSecurityTLS.x509ca.getValueStr());
  366. if (CSecurityTLS.x509crl.getValueStr() != "")
  367. UserPreferences.set("viewer", "x509crl", CSecurityTLS.x509crl.getValueStr());
  368. }
  369. private void restorePreferences() {
  370. autoSelect.setSelected(UserPreferences.getBool("global", "AutoSelect"));
  371. if (!autoSelect.isSelected()) {
  372. if (UserPreferences.getBool("global", "FullColour")) {
  373. fullColour.setSelected(true);
  374. } else {
  375. switch (UserPreferences.getInt("global", "LowColorLevel")) {
  376. case 2:
  377. mediumColour.setSelected(true);
  378. break;
  379. case 1:
  380. lowColour.setSelected(true);
  381. break;
  382. case 0:
  383. veryLowColour.setSelected(true);
  384. break;
  385. }
  386. }
  387. String encoding = UserPreferences.get("global", "PreferredEncoding");
  388. if (encoding != null) {
  389. switch (Encodings.encodingNum(encoding)) {
  390. case Encodings.encodingZRLE:
  391. zrle.setSelected(true);
  392. break;
  393. case Encodings.encodingHextile:
  394. hextile.setSelected(true);
  395. break;
  396. case Encodings.encodingRaw:
  397. raw.setSelected(true);
  398. break;
  399. default:
  400. tight.setSelected(true);
  401. }
  402. }
  403. }
  404. noJpeg.setSelected(!UserPreferences.getBool("global", "NoJPEG"));
  405. qualityLevel.setSelectedItem(UserPreferences.getInt("global", "QualityLevel"));
  406. customCompressLevel.setSelected(UserPreferences.getBool("global", "CustomCompressLevel"));
  407. compressLevel.setSelectedItem(UserPreferences.getInt("global", "CompressLevel"));
  408. viewOnly.setSelected(UserPreferences.getBool("global", "ViewOnly"));
  409. acceptClipboard.setSelected(UserPreferences.getBool("global", "AcceptClipboard"));
  410. sendClipboard.setSelected(UserPreferences.getBool("global", "SendClipboard"));
  411. menuKey.setSelectedItem(UserPreferences.get("global", "MenuKey"));
  412. desktopSize.setSelected(UserPreferences.get("global", "DesktopSize") != null);
  413. if (desktopSize.isSelected()) {
  414. String desktopSizeString = UserPreferences.get("global", "DesktopSize");
  415. desktopWidth.setText(desktopSizeString.split("x")[0]);
  416. desktopHeight.setText(desktopSizeString.split("x")[1]);
  417. }
  418. fullScreen.setSelected(UserPreferences.getBool("global", "FullScreen"));
  419. fullScreenAllMonitors.setSelected(UserPreferences.getBool("global", "FullScreenAllMonitors"));
  420. if (shared.isEnabled())
  421. shared.setSelected(UserPreferences.getBool("global", "Shared"));
  422. useLocalCursor.setSelected(UserPreferences.getBool("global", "UseLocalCursor"));
  423. acceptBell.setSelected(UserPreferences.getBool("global", "AcceptBell"));
  424. String scaleString = UserPreferences.get("global", "ScalingFactor");
  425. if (scaleString != null) {
  426. if (scaleString.equalsIgnoreCase("Auto")) {
  427. scalingFactor.setSelectedItem("Auto");
  428. } else if (scaleString.equalsIgnoreCase("FixedRatio")) {
  429. scalingFactor.setSelectedItem("Fixed Aspect Ratio");
  430. } else {
  431. scalingFactor.setSelectedItem(scaleString+"%");
  432. }
  433. }
  434. if (secVeNCrypt.isEnabled()) {
  435. secVeNCrypt.setSelected(UserPreferences.getBool("viewer", "secVeNCrypt", true));
  436. if (secVeNCrypt.isSelected()) {
  437. encNone.setSelected(UserPreferences.getBool("viewer", "encNone", true));
  438. encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
  439. encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
  440. secPlain.setSelected(UserPreferences.getBool("viewer", "secPlain", true));
  441. secIdent.setSelected(UserPreferences.getBool("viewer", "secIdent", true));
  442. sendLocalUsername.setSelected(UserPreferences.getBool("global", "SendLocalUsername"));
  443. }
  444. }
  445. if (secNone.isEnabled())
  446. secNone.setSelected(UserPreferences.getBool("viewer", "secNone", true));
  447. if (secVnc.isEnabled())
  448. secVnc.setSelected(UserPreferences.getBool("viewer", "secVnc", true));
  449. }
  450. JRadioButton addRadioCheckbox(String str, ButtonGroup group, JPanel panel) {
  451. JRadioButton c = new JRadioButton(str);
  452. GridBagConstraints gbc = new GridBagConstraints();
  453. gbc.anchor = GridBagConstraints.LINE_START;
  454. gbc.gridwidth = GridBagConstraints.REMAINDER;
  455. gbc.weightx = 1;
  456. gbc.weighty = 1;
  457. panel.add(c,gbc);
  458. group.add(c);
  459. c.addItemListener(this);
  460. return c;
  461. }
  462. JCheckBox addCheckbox(String str, ButtonGroup group, JPanel panel) {
  463. JCheckBox c = new JCheckBox(str);
  464. GridBagConstraints gbc = new GridBagConstraints();
  465. gbc.anchor = GridBagConstraints.LINE_START;
  466. gbc.gridwidth = GridBagConstraints.REMAINDER;
  467. gbc.weightx = 1;
  468. gbc.weighty = 1;
  469. panel.add(c,gbc);
  470. if (group != null)
  471. group.add(c);
  472. c.addItemListener(this);
  473. return c;
  474. }
  475. JCheckBox addJCheckBox(String str, ButtonGroup group, JPanel panel,
  476. GridBagConstraints gbc) {
  477. JCheckBox c = new JCheckBox(str);
  478. panel.add(c,gbc);
  479. if (group != null)
  480. group.add(c);
  481. c.addItemListener(this);
  482. return c;
  483. }
  484. public void endDialog() {
  485. super.endDialog();
  486. if (cc.viewport != null && cc.viewport.isVisible()) {
  487. cc.viewport.toFront();
  488. cc.viewport.requestFocus();
  489. }
  490. }
  491. public void actionPerformed(ActionEvent e) {
  492. Object s = e.getSource();
  493. if (s instanceof JButton && (JButton)s == okButton) {
  494. if (cc != null) cc.getOptions();
  495. endDialog();
  496. } else if (s instanceof JButton && (JButton)s == cancelButton) {
  497. endDialog();
  498. } else if (s instanceof JButton && (JButton)s == cfLoadButton) {
  499. JFileChooser fc = new JFileChooser();
  500. fc.setDialogTitle("Path to configuration file");
  501. fc.setApproveButtonText("OK");
  502. fc.setFileHidingEnabled(false);
  503. int ret = fc.showOpenDialog(this);
  504. if (ret == JFileChooser.APPROVE_OPTION) {
  505. String filename = fc.getSelectedFile().toString();
  506. if (filename != null)
  507. Configuration.load(filename);
  508. cc.setOptions();
  509. }
  510. } else if (s instanceof JButton && (JButton)s == cfSaveAsButton) {
  511. JFileChooser fc = new JFileChooser();
  512. fc.setDialogTitle("Save current configuration as:");
  513. fc.setApproveButtonText("OK");
  514. fc.setFileHidingEnabled(false);
  515. int ret = fc.showOpenDialog(this);
  516. if (ret == JFileChooser.APPROVE_OPTION) {
  517. String filename = fc.getSelectedFile().toString();
  518. if (filename != null)
  519. Configuration.save(filename);
  520. }
  521. } else if (s instanceof JButton && (JButton)s == defSaveButton) {
  522. updatePreferences();
  523. UserPreferences.save();
  524. } else if (s instanceof JButton && (JButton)s == defReloadButton) {
  525. restorePreferences();
  526. } else if (s instanceof JButton && (JButton)s == defClearButton) {
  527. UserPreferences.clear();
  528. cc.setOptions();
  529. } else if (s instanceof JButton && (JButton)s == ca) {
  530. JFileChooser fc = new JFileChooser(new File(CSecurityTLS.getDefaultCA()));
  531. fc.setDialogTitle("Path to X509 CA certificate");
  532. fc.setApproveButtonText("OK");
  533. fc.setFileHidingEnabled(false);
  534. int ret = fc.showOpenDialog(this);
  535. if (ret == JFileChooser.APPROVE_OPTION)
  536. CSecurityTLS.x509ca.setParam(fc.getSelectedFile().toString());
  537. } else if (s instanceof JButton && (JButton)s == crl) {
  538. JFileChooser fc = new JFileChooser(new File(CSecurityTLS.getDefaultCRL()));
  539. fc.setDialogTitle("Path to X509 CRL file");
  540. fc.setApproveButtonText("OK");
  541. fc.setFileHidingEnabled(false);
  542. int ret = fc.showOpenDialog(this);
  543. if (ret == JFileChooser.APPROVE_OPTION)
  544. CSecurityTLS.x509crl.setParam(fc.getSelectedFile().toString());
  545. }
  546. }
  547. public void itemStateChanged(ItemEvent e) {
  548. Object s = e.getSource();
  549. if (s instanceof JCheckBox && (JCheckBox)s == autoSelect) {
  550. zrle.setEnabled(!autoSelect.isSelected());
  551. hextile.setEnabled(!autoSelect.isSelected());
  552. tight.setEnabled(!autoSelect.isSelected());
  553. raw.setEnabled(!autoSelect.isSelected());
  554. fullColour.setEnabled(!autoSelect.isSelected());
  555. mediumColour.setEnabled(!autoSelect.isSelected());
  556. lowColour.setEnabled(!autoSelect.isSelected());
  557. veryLowColour.setEnabled(!autoSelect.isSelected());
  558. }
  559. if (s instanceof JCheckBox && (JCheckBox)s == customCompressLevel) {
  560. compressLevel.setEnabled(customCompressLevel.isSelected());
  561. }
  562. if (s instanceof JCheckBox && (JCheckBox)s == desktopSize) {
  563. desktopWidth.setEnabled(desktopSize.isSelected());
  564. desktopHeight.setEnabled(desktopSize.isSelected());
  565. }
  566. if (s instanceof JCheckBox && (JCheckBox)s == noJpeg) {
  567. qualityLevel.setEnabled(noJpeg.isSelected());
  568. }
  569. if (s instanceof JCheckBox && (JCheckBox)s == secVeNCrypt) {
  570. encNone.setEnabled(secVeNCrypt.isSelected());
  571. encTLS.setEnabled(secVeNCrypt.isSelected());
  572. encX509.setEnabled(secVeNCrypt.isSelected());
  573. ca.setEnabled(secVeNCrypt.isSelected());
  574. crl.setEnabled(secVeNCrypt.isSelected());
  575. secIdent.setEnabled(secVeNCrypt.isSelected());
  576. secPlain.setEnabled(secVeNCrypt.isSelected());
  577. sendLocalUsername.setEnabled(secVeNCrypt.isSelected());
  578. }
  579. if (s instanceof JCheckBox && (JCheckBox)s == encNone) {
  580. secNone.setSelected(encNone.isSelected() &&
  581. UserPreferences.getBool("viewer", "secNone", true));
  582. secVnc.setSelected(encNone.isSelected() &&
  583. UserPreferences.getBool("viewer", "secVnc", true));
  584. }
  585. if (s instanceof JCheckBox && (JCheckBox)s == secIdent ||
  586. s instanceof JCheckBox && (JCheckBox)s == secPlain) {
  587. sendLocalUsername.setEnabled(secIdent.isSelected()||secPlain.isSelected());
  588. }
  589. }
  590. }