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.

AuthPanel.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
  3. // Copyright (C) 2002-2006 Constantin Kaplinsky. 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. import java.awt.*;
  21. import java.awt.event.*;
  22. //
  23. // The panel which implements the user authentication scheme
  24. //
  25. class AuthPanel extends Panel implements ActionListener {
  26. TextField passwordField;
  27. Button okButton;
  28. //
  29. // Constructor.
  30. //
  31. public AuthPanel(VncViewer viewer)
  32. {
  33. Label titleLabel = new Label("VNC Authentication", Label.CENTER);
  34. titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18));
  35. Label promptLabel = new Label("Password:", Label.CENTER);
  36. passwordField = new TextField(10);
  37. passwordField.setForeground(Color.black);
  38. passwordField.setBackground(Color.white);
  39. passwordField.setEchoChar('*');
  40. okButton = new Button("OK");
  41. GridBagLayout gridbag = new GridBagLayout();
  42. GridBagConstraints gbc = new GridBagConstraints();
  43. setLayout(gridbag);
  44. gbc.gridwidth = GridBagConstraints.REMAINDER;
  45. gbc.insets = new Insets(0,0,20,0);
  46. gridbag.setConstraints(titleLabel,gbc);
  47. add(titleLabel);
  48. gbc.fill = GridBagConstraints.NONE;
  49. gbc.gridwidth = 1;
  50. gbc.insets = new Insets(0,0,0,0);
  51. gridbag.setConstraints(promptLabel,gbc);
  52. add(promptLabel);
  53. gridbag.setConstraints(passwordField,gbc);
  54. add(passwordField);
  55. passwordField.addActionListener(this);
  56. // gbc.ipady = 10;
  57. gbc.gridwidth = GridBagConstraints.REMAINDER;
  58. gbc.fill = GridBagConstraints.BOTH;
  59. gbc.insets = new Insets(0,20,0,0);
  60. gbc.ipadx = 30;
  61. gridbag.setConstraints(okButton,gbc);
  62. add(okButton);
  63. okButton.addActionListener(this);
  64. }
  65. //
  66. // Move keyboard focus to the default object, that is, the password
  67. // text field.
  68. //
  69. public void moveFocusToDefaultField()
  70. {
  71. passwordField.requestFocus();
  72. }
  73. //
  74. // This method is called when a button is pressed or return is
  75. // pressed in the password text field.
  76. //
  77. public synchronized void actionPerformed(ActionEvent evt)
  78. {
  79. if (evt.getSource() == passwordField || evt.getSource() == okButton) {
  80. passwordField.setEnabled(false);
  81. notify();
  82. }
  83. }
  84. //
  85. // Wait for user entering a password, and return it as String.
  86. //
  87. public synchronized String getPassword() throws Exception
  88. {
  89. try {
  90. wait();
  91. } catch (InterruptedException e) { }
  92. return passwordField.getText();
  93. }
  94. }