Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. package com.tigervnc.vncviewer;
  19. import java.awt.*;
  20. import java.awt.image.*;
  21. import java.awt.event.*;
  22. import javax.swing.*;
  23. import javax.swing.border.*;
  24. import java.net.URL;
  25. import java.io.File;
  26. import java.util.*;
  27. import com.tigervnc.rfb.*;
  28. import com.tigervnc.rfb.Exception;
  29. class ServerDialog extends Dialog implements
  30. ActionListener,
  31. ItemListener
  32. {
  33. public ServerDialog(OptionsDialog options_,
  34. String defaultServerName, CConn cc_) {
  35. super(true);
  36. cc = cc_;
  37. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  38. setResizable(false);
  39. setSize(new Dimension(340, 135));
  40. setTitle("VNC Viewer : Connection Details");
  41. options = options_;
  42. getContentPane().setLayout(new GridBagLayout());
  43. JLabel serverLabel = new JLabel("Server:", JLabel.RIGHT);
  44. if (options.defaults.getString("server") != null) {
  45. server = new JComboBox(options.defaults.getString("server").split(","));
  46. } else {
  47. server = new JComboBox();
  48. }
  49. // Hack to set the left inset on editable JComboBox
  50. if (UIManager.getLookAndFeel().getID() == "Windows") {
  51. server.setBorder(BorderFactory.createCompoundBorder(server.getBorder(),
  52. BorderFactory.createEmptyBorder(0,2,0,0)));
  53. } else {
  54. ComboBoxEditor editor = server.getEditor();
  55. JTextField jtf = (JTextField)editor.getEditorComponent();
  56. jtf.setBorder(new CompoundBorder(jtf.getBorder(), new EmptyBorder(0,2,0,0)));
  57. }
  58. server.setEditable(true);
  59. editor = server.getEditor();
  60. JLabel encryptionLabel = new JLabel("Encryption:");
  61. encryption = new JComboBox();
  62. serverLabel.setPreferredSize(encryptionLabel.getPreferredSize());
  63. JPanel topPanel = new JPanel(new GridBagLayout());
  64. addGBComponent(new JLabel(cc.logo),topPanel, 0, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(5,5,5,15));
  65. addGBComponent(serverLabel,topPanel, 1, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_END, new Insets(10,0,5,5));
  66. addGBComponent(server,topPanel, 2, 0, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(10,0,5,40));
  67. optionsButton = new JButton("Options...");
  68. aboutButton = new JButton("About...");
  69. okButton = new JButton("OK");
  70. cancelButton = new JButton("Cancel");
  71. JPanel buttonPanel = new JPanel(new GridBagLayout());
  72. buttonPanel.setPreferredSize(new Dimension(340, 40));
  73. addGBComponent(aboutButton,buttonPanel, 0, 3, 1, 1, 0, 0, 0.2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0,5,0,5));
  74. addGBComponent(optionsButton,buttonPanel, 1, 3, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0,5,0,5));
  75. addGBComponent(okButton,buttonPanel, 2, 3, 1, 1, 0, 0, 0.8, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0,5,0,5));
  76. addGBComponent(cancelButton,buttonPanel, 3, 3, 1, 1, 0, 0, 0.5, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0,5,0,5));
  77. GridBagConstraints gbc = new GridBagConstraints();
  78. gbc.anchor = GridBagConstraints.LINE_START;
  79. gbc.fill = GridBagConstraints.BOTH;
  80. gbc.gridwidth = GridBagConstraints.REMAINDER;
  81. gbc.gridheight = 1;
  82. gbc.insets = new Insets(0,0,0,0);
  83. gbc.ipadx = 0;
  84. gbc.ipady = 0;
  85. gbc.weightx = 1;
  86. gbc.weighty = 1;
  87. getContentPane().add(topPanel,gbc);
  88. getContentPane().add(buttonPanel);
  89. server.addActionListener(this);
  90. optionsButton.addActionListener(this);
  91. aboutButton.addActionListener(this);
  92. okButton.addActionListener(this);
  93. cancelButton.addActionListener(this);
  94. pack();
  95. }
  96. public void itemStateChanged(ItemEvent e) {
  97. Object s = e.getSource();
  98. }
  99. public void actionPerformed(ActionEvent e) {
  100. Object s = e.getSource();
  101. if (s instanceof JButton && (JButton)s == okButton) {
  102. ok = true;
  103. endDialog();
  104. } else if (s instanceof JButton && (JButton)s == cancelButton) {
  105. ok = false;
  106. endDialog();
  107. } else if (s instanceof JButton && (JButton)s == optionsButton) {
  108. options.showDialog();
  109. } else if (s instanceof JButton && (JButton)s == aboutButton) {
  110. cc.showAbout();
  111. } else if (s instanceof JComboBox && (JComboBox)s == server) {
  112. if (e.getActionCommand().equals("comboBoxEdited")) {
  113. server.insertItemAt(editor.getItem(), 0);
  114. server.setSelectedIndex(0);
  115. ok = true;
  116. endDialog();
  117. }
  118. }
  119. }
  120. public void endDialog() {
  121. if (ok) {
  122. try {
  123. options.defaults.setPref("encryption",(encryption.getSelectedIndex()==1) ? "off" : "on");
  124. if (!server.getSelectedItem().toString().equals("")) {
  125. String t = (options.defaults.getString("server")==null) ? "" : options.defaults.getString("server");
  126. StringTokenizer st = new StringTokenizer(t, ",");
  127. StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem());
  128. while (st.hasMoreTokens()) {
  129. String s = st.nextToken();
  130. if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) {
  131. sb.append(',');
  132. sb.append(s);
  133. }
  134. }
  135. options.defaults.setPref("server", sb.toString());
  136. }
  137. options.defaults.Save();
  138. } catch (java.io.IOException e) {
  139. System.out.println(e.toString());
  140. } catch(java.security.AccessControlException e) {
  141. System.out.println(e.toString());
  142. }
  143. }
  144. done = true;
  145. if (modal) {
  146. synchronized (this) {
  147. notify();
  148. }
  149. }
  150. this.dispose();
  151. }
  152. CConn cc;
  153. JComboBox encryption, server;
  154. ComboBoxEditor editor;
  155. JButton aboutButton, optionsButton, okButton, cancelButton;
  156. OptionsDialog options;
  157. static LogWriter vlog = new LogWriter("ServerDialog");
  158. }