Mercurial > hg > Applications > TightVNC_orginal
comparison src/viewer_swing/java/com/glavsoft/viewer/swing/gui/OptionsDialog.java @ 52:472a9bcacb21 draft default tip
TightVNC 2.7.1.0
author | you@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 07 Aug 2013 19:01:17 +0900 |
parents | 4689cc86d6cb |
children |
comparison
equal
deleted
inserted
replaced
0:4689cc86d6cb | 52:472a9bcacb21 |
---|---|
1 // Copyright (C) 2010, 2011 GlavSoft LLC. | 1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 //------------------------------------------------------------------------- | 4 //------------------------------------------------------------------------- |
5 // This file is part of the TightVNC software. Please visit our Web site: | 5 // This file is part of the TightVNC software. Please visit our Web site: |
6 // | 6 // |
25 package com.glavsoft.viewer.swing.gui; | 25 package com.glavsoft.viewer.swing.gui; |
26 | 26 |
27 import com.glavsoft.rfb.encoding.EncodingType; | 27 import com.glavsoft.rfb.encoding.EncodingType; |
28 import com.glavsoft.rfb.protocol.LocalPointer; | 28 import com.glavsoft.rfb.protocol.LocalPointer; |
29 import com.glavsoft.rfb.protocol.ProtocolSettings; | 29 import com.glavsoft.rfb.protocol.ProtocolSettings; |
30 import com.glavsoft.viewer.swing.LocalMouseCursorShape; | |
31 import com.glavsoft.viewer.UiSettings; | |
30 | 32 |
31 import javax.swing.*; | 33 import javax.swing.*; |
32 import java.awt.*; | 34 import java.awt.*; |
33 import java.awt.event.*; | 35 import java.awt.event.*; |
34 import java.util.HashMap; | 36 import java.util.HashMap; |
41 public class OptionsDialog extends JDialog { | 43 public class OptionsDialog extends JDialog { |
42 private JSlider jpegQuality; | 44 private JSlider jpegQuality; |
43 private JSlider compressionLevel; | 45 private JSlider compressionLevel; |
44 private JCheckBox viewOnlyCheckBox; | 46 private JCheckBox viewOnlyCheckBox; |
45 private ProtocolSettings settings; | 47 private ProtocolSettings settings; |
46 private JCheckBox sharedSession; | 48 private UiSettings uiSettings; |
49 private JCheckBox sharedSession; | |
47 | 50 |
48 private RadioButtonSelectedState<LocalPointer> mouseCursorTrackSelected; | 51 private RadioButtonSelectedState<LocalPointer> mouseCursorTrackSelected; |
49 private Map<LocalPointer, JRadioButton> mouseCursorTrackMap; | 52 private Map<LocalPointer, JRadioButton> mouseCursorTrackMap; |
50 | |
51 // private RadioButtonSelectedState<Integer> colorDepthSelected; | |
52 // private Map<Integer, JRadioButton> colorDepthMap; | |
53 | |
54 private JCheckBox useCompressionLevel; | 53 private JCheckBox useCompressionLevel; |
55 private JCheckBox useJpegQuality; | 54 private JCheckBox useJpegQuality; |
56 private JLabel jpegQualityPoorLabel; | 55 private JLabel jpegQualityPoorLabel; |
57 private JLabel jpegQualityBestLabel; | 56 private JLabel jpegQualityBestLabel; |
58 private JLabel compressionLevelFastLabel; | 57 private JLabel compressionLevelFastLabel; |
59 private JLabel compressionLevelBestLabel; | 58 private JLabel compressionLevelBestLabel; |
60 private JCheckBox allowCopyRect; | 59 private JCheckBox allowCopyRect; |
61 private JComboBox encodings; | 60 private JComboBox encodings; |
62 private JCheckBox disableClipboardTransfer; | 61 private JCheckBox disableClipboardTransfer; |
63 private JComboBox colorDepth; | 62 private JComboBox colorDepth; |
64 | 63 private RadioButtonSelectedState<LocalMouseCursorShape> mouseCursorShapeSelected; |
65 public OptionsDialog(Window owner) { | 64 private HashMap<LocalMouseCursorShape, JRadioButton> mouseCursorShapeMap; |
66 super(owner, "Connection Options", ModalityType.MODELESS); | 65 |
66 public OptionsDialog(Window owner) { | |
67 super(owner, "Connection Options", ModalityType.DOCUMENT_MODAL); | |
67 final WindowAdapter onClose = new WindowAdapter() { | 68 final WindowAdapter onClose = new WindowAdapter() { |
68 @Override | 69 @Override |
69 public void windowClosing(WindowEvent e) { | 70 public void windowClosing(WindowEvent e) { |
70 setVisible(false); | 71 setVisible(false); |
71 } | 72 } |
81 addButtons(onClose); | 82 addButtons(onClose); |
82 | 83 |
83 pack(); | 84 pack(); |
84 } | 85 } |
85 | 86 |
86 public void initControlsFromSettings(ProtocolSettings settings, boolean isOnConnect) { | 87 public void initControlsFromSettings(ProtocolSettings settings, UiSettings uiSettings, boolean isOnConnect) { |
87 this.settings = settings; | 88 this.settings = settings; |
88 | 89 this.uiSettings = uiSettings; |
89 viewOnlyCheckBox.setSelected(settings.isViewOnly()); | 90 |
90 | 91 viewOnlyCheckBox.setSelected(settings.isViewOnly()); |
91 // String scaling = String.valueOf((int)(settings.scaling * 100)); | |
92 // int i = 0; boolean isNotSetScale = true; | |
93 // while ( scaleCombo.getItemAt(i) != null) { | |
94 // String item = (String)scaleCombo.getItemAt(i); | |
95 // if (item.equals(scaling)) { | |
96 // scaleCombo.setSelectedIndex(i); | |
97 // isNotSetScale = false; | |
98 // break; | |
99 // } | |
100 // ++i; | |
101 // } | |
102 // if (isNotSetScale) { | |
103 // scaleCombo.setSelectedItem(SCALE_100); | |
104 // } | |
105 | 92 |
106 int i = 0; boolean isNotSetEncoding = true; | 93 int i = 0; boolean isNotSetEncoding = true; |
107 while ( encodings.getItemAt(i) != null) { | 94 while ( encodings.getItemAt(i) != null) { |
108 EncodingType item = ((EncodingSelectItem)encodings.getItemAt(i)).type; | 95 EncodingType item = ((EncodingSelectItem)encodings.getItemAt(i)).type; |
109 if (item.equals(settings.getPreferredEncoding())) { | 96 if (item.equals(settings.getPreferredEncoding())) { |
120 sharedSession.setSelected(settings.isShared()); | 107 sharedSession.setSelected(settings.isShared()); |
121 sharedSession.setEnabled(isOnConnect); | 108 sharedSession.setEnabled(isOnConnect); |
122 | 109 |
123 mouseCursorTrackMap.get(settings.getMouseCursorTrack()).setSelected(true); | 110 mouseCursorTrackMap.get(settings.getMouseCursorTrack()).setSelected(true); |
124 mouseCursorTrackSelected.setSelected(settings.getMouseCursorTrack()); | 111 mouseCursorTrackSelected.setSelected(settings.getMouseCursorTrack()); |
125 | 112 mouseCursorShapeMap.get(uiSettings.getMouseCursorShape()).setSelected(true); |
126 // settings.setBitsPerPixel(settings.getBitsPerPixel()); // when 0 set default bpp value | 113 mouseCursorShapeSelected.setSelected(uiSettings.getMouseCursorShape()); |
127 // final JRadioButton colorDepthRadioButton = colorDepthMap.get(settings.getBitsPerPixel()); | 114 |
128 // if (colorDepthRadioButton != null) { | 115 int depth = settings.getColorDepth(); |
129 // colorDepthRadioButton.setSelected(true); | |
130 // } | |
131 // colorDepthSelected.setSelected(settings.getBitsPerPixel()); | |
132 | |
133 int bpp = settings.getBitsPerPixel(); | |
134 i = 0; boolean isNotSet = true; | 116 i = 0; boolean isNotSet = true; |
135 while ( colorDepth.getItemAt(i) != null) { | 117 while ( colorDepth.getItemAt(i) != null) { |
136 int itemBpp = ((ColorDepthSelectItem)colorDepth.getItemAt(i)).bpp; | 118 int itemDepth = ((ColorDepthSelectItem)colorDepth.getItemAt(i)).depth; |
137 if (itemBpp == bpp) { | 119 if (itemDepth == depth) { |
138 colorDepth.setSelectedIndex(i); | 120 colorDepth.setSelectedIndex(i); |
139 isNotSet = false; | 121 isNotSet = false; |
140 break; | 122 break; |
141 } | 123 } |
142 ++i; | 124 ++i; |
161 settings.setViewOnly(viewOnlyCheckBox.isSelected()); | 143 settings.setViewOnly(viewOnlyCheckBox.isSelected()); |
162 settings.setPreferredEncoding(((EncodingSelectItem)encodings.getSelectedItem()).type); | 144 settings.setPreferredEncoding(((EncodingSelectItem)encodings.getSelectedItem()).type); |
163 | 145 |
164 settings.setSharedFlag(sharedSession.isSelected()); | 146 settings.setSharedFlag(sharedSession.isSelected()); |
165 settings.setMouseCursorTrack(mouseCursorTrackSelected.getSelected()); | 147 settings.setMouseCursorTrack(mouseCursorTrackSelected.getSelected()); |
166 | 148 uiSettings.setMouseCursorShape(mouseCursorShapeSelected.getSelected()); |
167 settings.setBitsPerPixel(((ColorDepthSelectItem)colorDepth.getSelectedItem()).bpp); | 149 |
150 settings.setColorDepth(((ColorDepthSelectItem) colorDepth.getSelectedItem()).depth); | |
168 | 151 |
169 settings.setCompressionLevel(useCompressionLevel.isSelected() ? | 152 settings.setCompressionLevel(useCompressionLevel.isSelected() ? |
170 compressionLevel.getValue() : | 153 compressionLevel.getValue() : |
171 - Math.abs(settings.getCompressionLevel())); | 154 - Math.abs(settings.getCompressionLevel())); |
172 settings.setJpegQuality(useJpegQuality.isSelected() ? | 155 settings.setJpegQuality(useJpegQuality.isSelected() ? |
190 private Component createRightPane() { | 173 private Component createRightPane() { |
191 Box box = Box.createVerticalBox(); | 174 Box box = Box.createVerticalBox(); |
192 box.setAlignmentX(LEFT_ALIGNMENT); | 175 box.setAlignmentX(LEFT_ALIGNMENT); |
193 | 176 |
194 box.add(createRestrictionsPanel()); | 177 box.add(createRestrictionsPanel()); |
195 // box.add(createDisplayPanel()); | |
196 box.add(createMouseCursorPanel()); | 178 box.add(createMouseCursorPanel()); |
197 // box.add(createLocalShapePanel()); | 179 box.add(createLocalShapePanel()); |
198 | 180 |
199 sharedSession = new JCheckBox("Request shared session"); | 181 sharedSession = new JCheckBox("Request shared session"); |
200 box.add(new JPanel(new FlowLayout(FlowLayout.LEFT)).add(sharedSession)); | 182 box.add(new JPanel(new FlowLayout(FlowLayout.LEFT)).add(sharedSession)); |
201 | 183 |
202 box.add(Box.createVerticalGlue()); | 184 box.add(Box.createVerticalGlue()); |
203 return box; | 185 return box; |
204 } | 186 } |
205 | 187 |
206 private JPanel createRestrictionsPanel() { | 188 private JPanel createRestrictionsPanel() { |
207 JPanel restrictionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); | 189 JPanel restrictionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
208 // restrictionsPanel.setAlignmentX(LEFT_ALIGNMENT); | |
209 restrictionsPanel.setBorder( | 190 restrictionsPanel.setBorder( |
210 BorderFactory.createTitledBorder( | 191 BorderFactory.createTitledBorder( |
211 BorderFactory.createEtchedBorder(), "Restrictions")); | 192 BorderFactory.createEtchedBorder(), "Restrictions")); |
212 | 193 |
213 Box restrictionsBox = Box.createVerticalBox(); | 194 Box restrictionsBox = Box.createVerticalBox(); |
270 return type.getName(); | 251 return type.getName(); |
271 } | 252 } |
272 } | 253 } |
273 | 254 |
274 private static class ColorDepthSelectItem { | 255 private static class ColorDepthSelectItem { |
275 final int bpp; | 256 final int depth; |
276 final String title; | 257 final String title; |
277 public ColorDepthSelectItem(int bpp, String title) { | 258 public ColorDepthSelectItem(int depth, String title) { |
278 this.bpp = bpp; | 259 this.depth = depth; |
279 this.title = title; | 260 this.title = title; |
280 } | 261 } |
281 @Override | 262 @Override |
282 public String toString() { | 263 public String toString() { |
283 return title; | 264 return title; |
288 JPanel colorDepthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); | 269 JPanel colorDepthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
289 colorDepthPanel.setAlignmentX(LEFT_ALIGNMENT); | 270 colorDepthPanel.setAlignmentX(LEFT_ALIGNMENT); |
290 colorDepthPanel.add(new JLabel("Color format: ")); | 271 colorDepthPanel.add(new JLabel("Color format: ")); |
291 | 272 |
292 colorDepth = new JComboBox(); | 273 colorDepth = new JComboBox(); |
293 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_SERVER_SETTINGS, | 274 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_SERVER_SETTINGS, |
294 "Server's default")); | 275 "Server's default")); |
295 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_32, | 276 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_24, |
296 "16 777 216 colors")); | 277 "16 777 216 colors")); |
297 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_16, | 278 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_16, |
298 "65 536 colors")); | 279 "65 536 colors")); |
299 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_8, | 280 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_8, |
300 "256 colors")); | 281 "256 colors")); |
301 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_6, | 282 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_6, |
302 "64 colors")); | 283 "64 colors")); |
303 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.BPP_3, | 284 colorDepth.addItem(new ColorDepthSelectItem(ProtocolSettings.COLOR_DEPTH_3, |
304 "8 colors")); | 285 "8 colors")); |
305 | 286 |
306 colorDepthPanel.add(colorDepth); | 287 colorDepthPanel.add(colorDepth); |
307 colorDepth.addItemListener(new ItemListener() { | 288 colorDepth.addItemListener(new ItemListener() { |
308 @Override | 289 @Override |
309 public void itemStateChanged(ItemEvent e) { | 290 public void itemStateChanged(ItemEvent e) { |
310 final ColorDepthSelectItem selectedItem = | 291 setJpegQualityPaneEnable(); |
311 (ColorDepthSelectItem) colorDepth.getSelectedItem(); | |
312 setEnabled(selectedItem.bpp > ProtocolSettings.BPP_8 || | |
313 selectedItem.bpp == ProtocolSettings.BPP_SERVER_SETTINGS, | |
314 useJpegQuality); | |
315 setEnabled(useJpegQuality.isSelected() && | |
316 (selectedItem.bpp > ProtocolSettings.BPP_8 || | |
317 selectedItem.bpp == ProtocolSettings.BPP_SERVER_SETTINGS), | |
318 jpegQuality, jpegQualityPoorLabel, jpegQualityBestLabel); | |
319 } | 292 } |
320 }); | 293 }); |
321 return colorDepthPanel; | 294 return colorDepthPanel; |
322 } | 295 } |
323 | 296 |
354 }); | 327 }); |
355 } | 328 } |
356 | 329 |
357 protected void setJpegQualityPaneEnable() { | 330 protected void setJpegQualityPaneEnable() { |
358 if (useJpegQuality != null && colorDepth != null) { | 331 if (useJpegQuality != null && colorDepth != null) { |
359 int bpp = ((ColorDepthSelectItem)colorDepth.getSelectedItem()).bpp; | 332 int depth = ((ColorDepthSelectItem)colorDepth.getSelectedItem()).depth; |
360 setEnabled( | 333 setEnabled(whetherJpegQualityPaneBeEnabled(depth), useJpegQuality); |
361 bpp > ProtocolSettings.BPP_8 || bpp == ProtocolSettings.BPP_SERVER_SETTINGS, | 334 setEnabled(useJpegQuality.isSelected() && whetherJpegQualityPaneBeEnabled(depth), |
362 useJpegQuality); | |
363 setEnabled(useJpegQuality.isSelected() && | |
364 (bpp > ProtocolSettings.BPP_8 || bpp == ProtocolSettings.BPP_SERVER_SETTINGS), | |
365 jpegQuality, jpegQualityPoorLabel, jpegQualityBestLabel); | 335 jpegQuality, jpegQualityPoorLabel, jpegQualityBestLabel); |
366 } | 336 } |
367 } | 337 } |
368 | 338 |
369 private void addCompressionLevelPane(JPanel encodingsPanel) { | 339 private boolean whetherJpegQualityPaneBeEnabled(int depth) { |
340 return ProtocolSettings.COLOR_DEPTH_16 == depth || | |
341 ProtocolSettings.COLOR_DEPTH_24 == depth || | |
342 ProtocolSettings.COLOR_DEPTH_SERVER_SETTINGS == depth; | |
343 } | |
344 | |
345 private void addCompressionLevelPane(JPanel encodingsPanel) { | |
370 useCompressionLevel = new JCheckBox("Custom compression level:"); | 346 useCompressionLevel = new JCheckBox("Custom compression level:"); |
371 useCompressionLevel.setAlignmentX(LEFT_ALIGNMENT); | 347 useCompressionLevel.setAlignmentX(LEFT_ALIGNMENT); |
372 encodingsPanel.add(useCompressionLevel); | 348 encodingsPanel.add(useCompressionLevel); |
373 | 349 |
374 JPanel compressionLevelPane = new JPanel(); | 350 JPanel compressionLevelPane = new JPanel(); |
408 for (JComponent c : comp) { | 384 for (JComponent c : comp) { |
409 c.setEnabled(isEnabled); | 385 c.setEnabled(isEnabled); |
410 } | 386 } |
411 } | 387 } |
412 | 388 |
413 /* | |
414 private JPanel createLocalShapePanel() { | 389 private JPanel createLocalShapePanel() { |
415 JPanel localCursorShapePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); | 390 JPanel localCursorShapePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
416 // localCursorShapePanel.setLayout(new BoxLayout(localCursorShapePanel, BoxLayout.Y_AXIS)); | 391 // localCursorShapePanel.setLayout(new BoxLayout(localCursorShapePanel, BoxLayout.Y_AXIS)); |
417 localCursorShapePanel.setBorder( | 392 localCursorShapePanel.setBorder( |
418 BorderFactory.createTitledBorder( | 393 BorderFactory.createTitledBorder( |
419 BorderFactory.createEtchedBorder(), "Local cursor shape")); | 394 BorderFactory.createEtchedBorder(), "Local cursor shape")); |
420 Box localCursorShapeBox = Box.createVerticalBox(); | 395 Box localCursorShapeBox = Box.createVerticalBox(); |
421 localCursorShapePanel.add(localCursorShapeBox); | 396 localCursorShapePanel.add(localCursorShapeBox); |
422 | 397 |
423 JRadioButton dotCursorRadio = new JRadioButton("Dot cursor"); | 398 ButtonGroup mouseCursorShapeTrackGroup = new ButtonGroup(); |
424 JRadioButton smallDotCursorRadio = new JRadioButton("Small dot cursor"); | 399 mouseCursorShapeSelected = new RadioButtonSelectedState<LocalMouseCursorShape>(); |
425 JRadioButton arrowCursorRadio = new JRadioButton("Default cursor"); | 400 mouseCursorShapeMap = new HashMap<LocalMouseCursorShape, JRadioButton>(); |
426 JRadioButton noCursorRadio = new JRadioButton("No local cursor"); | 401 |
427 localCursorShapeBox.add(dotCursorRadio); | 402 addRadioButton("Dot cursor", LocalMouseCursorShape.DOT, |
428 localCursorShapeBox.add(smallDotCursorRadio); | 403 mouseCursorShapeSelected, mouseCursorShapeMap, localCursorShapeBox, |
429 localCursorShapeBox.add(arrowCursorRadio); | 404 mouseCursorShapeTrackGroup); |
430 localCursorShapeBox.add(noCursorRadio); | 405 |
431 ButtonGroup localCursorButtonGroup = new ButtonGroup(); | 406 addRadioButton("Small dot cursor", LocalMouseCursorShape.SMALL_DOT, |
432 localCursorButtonGroup.add(dotCursorRadio); | 407 mouseCursorShapeSelected, mouseCursorShapeMap, localCursorShapeBox, |
433 localCursorButtonGroup.add(smallDotCursorRadio); | 408 mouseCursorShapeTrackGroup); |
434 localCursorButtonGroup.add(arrowCursorRadio); | 409 |
435 localCursorButtonGroup.add(noCursorRadio); | 410 addRadioButton("System default cursor", LocalMouseCursorShape.SYSTEM_DEFAULT, |
411 mouseCursorShapeSelected, mouseCursorShapeMap, localCursorShapeBox, | |
412 mouseCursorShapeTrackGroup); | |
413 | |
414 addRadioButton("No local cursor", LocalMouseCursorShape.NO_CURSOR, | |
415 mouseCursorShapeSelected, mouseCursorShapeMap, localCursorShapeBox, | |
416 mouseCursorShapeTrackGroup); | |
417 | |
436 return localCursorShapePanel; | 418 return localCursorShapePanel; |
437 } | 419 } |
438 */ | 420 |
439 | |
440 private JPanel createMouseCursorPanel() { | 421 private JPanel createMouseCursorPanel() { |
441 JPanel mouseCursorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); | 422 JPanel mouseCursorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
442 mouseCursorPanel.setBorder( | 423 mouseCursorPanel.setBorder( |
443 BorderFactory.createTitledBorder( | 424 BorderFactory.createTitledBorder( |
444 BorderFactory.createEtchedBorder(), "Mouse Cursor")); | 425 BorderFactory.createEtchedBorder(), "Mouse Cursor")); |