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.

ButtonPanel.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // Copyright (C) 2001,2002 HorizonLive.com, Inc. All Rights Reserved.
  3. // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
  4. //
  5. // This is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This software is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this software; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. // USA.
  19. //
  20. //
  21. // ButtonPanel class implements panel with four buttons in the
  22. // VNCViewer desktop window.
  23. //
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.io.*;
  27. class ButtonPanel extends Panel implements ActionListener {
  28. VncViewer viewer;
  29. Button disconnectButton;
  30. Button optionsButton;
  31. Button recordButton;
  32. Button clipboardButton;
  33. Button ctrlAltDelButton;
  34. Button refreshButton;
  35. ButtonPanel(VncViewer v) {
  36. viewer = v;
  37. setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
  38. disconnectButton = new Button("Disconnect");
  39. disconnectButton.setEnabled(false);
  40. add(disconnectButton);
  41. disconnectButton.addActionListener(this);
  42. optionsButton = new Button("Options");
  43. add(optionsButton);
  44. optionsButton.addActionListener(this);
  45. clipboardButton = new Button("Clipboard");
  46. clipboardButton.setEnabled(false);
  47. add(clipboardButton);
  48. clipboardButton.addActionListener(this);
  49. if (viewer.rec != null) {
  50. recordButton = new Button("Record");
  51. add(recordButton);
  52. recordButton.addActionListener(this);
  53. }
  54. ctrlAltDelButton = new Button("Send Ctrl-Alt-Del");
  55. ctrlAltDelButton.setEnabled(false);
  56. add(ctrlAltDelButton);
  57. ctrlAltDelButton.addActionListener(this);
  58. refreshButton = new Button("Refresh");
  59. refreshButton.setEnabled(false);
  60. add(refreshButton);
  61. refreshButton.addActionListener(this);
  62. }
  63. //
  64. // Enable buttons on successful connection.
  65. //
  66. public void enableButtons() {
  67. disconnectButton.setEnabled(true);
  68. clipboardButton.setEnabled(true);
  69. refreshButton.setEnabled(true);
  70. }
  71. //
  72. // Disable all buttons on disconnect.
  73. //
  74. public void disableButtonsOnDisconnect() {
  75. remove(disconnectButton);
  76. disconnectButton = new Button("Hide desktop");
  77. disconnectButton.setEnabled(true);
  78. add(disconnectButton, 0);
  79. disconnectButton.addActionListener(this);
  80. optionsButton.setEnabled(false);
  81. clipboardButton.setEnabled(false);
  82. ctrlAltDelButton.setEnabled(false);
  83. refreshButton.setEnabled(false);
  84. validate();
  85. }
  86. //
  87. // Enable/disable controls that should not be available in view-only
  88. // mode.
  89. //
  90. public void enableRemoteAccessControls(boolean enable) {
  91. ctrlAltDelButton.setEnabled(enable);
  92. }
  93. //
  94. // Event processing.
  95. //
  96. public void actionPerformed(ActionEvent evt) {
  97. viewer.moveFocusToDesktop();
  98. if (evt.getSource() == disconnectButton) {
  99. viewer.disconnect();
  100. } else if (evt.getSource() == optionsButton) {
  101. viewer.options.setVisible(!viewer.options.isVisible());
  102. } else if (evt.getSource() == recordButton) {
  103. viewer.rec.setVisible(!viewer.rec.isVisible());
  104. } else if (evt.getSource() == clipboardButton) {
  105. viewer.clipboard.setVisible(!viewer.clipboard.isVisible());
  106. } else if (evt.getSource() == ctrlAltDelButton) {
  107. try {
  108. final int modifiers = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
  109. KeyEvent ctrlAltDelEvent =
  110. new KeyEvent(this, KeyEvent.KEY_PRESSED, 0, modifiers, 127);
  111. viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
  112. ctrlAltDelEvent =
  113. new KeyEvent(this, KeyEvent.KEY_RELEASED, 0, modifiers, 127);
  114. viewer.rfb.writeKeyEvent(ctrlAltDelEvent);
  115. } catch (IOException e) {
  116. e.printStackTrace();
  117. }
  118. } else if (evt.getSource() == refreshButton) {
  119. try {
  120. RfbProto rfb = viewer.rfb;
  121. rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
  122. rfb.framebufferHeight, false);
  123. } catch (IOException e) {
  124. e.printStackTrace();
  125. }
  126. }
  127. }
  128. }