AuthPanel.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. // USA.
  18. //
  19. import java.awt.Button;
  20. import java.awt.Color;
  21. import java.awt.Font;
  22. import java.awt.GridBagConstraints;
  23. import java.awt.GridBagLayout;
  24. import java.awt.Insets;
  25. import java.awt.Label;
  26. import java.awt.Panel;
  27. import java.awt.TextField;
  28. import java.awt.event.ActionEvent;
  29. import java.awt.event.ActionListener;
  30. //
  31. // The panel which implements the user authentication scheme
  32. //
  33. class AuthPanel extends Panel implements ActionListener {
  34. Label title, retry, prompt;
  35. TextField password;
  36. Button ok;
  37. // mslgon support
  38. Label promptuser;
  39. TextField username;
  40. boolean mslogon = false;
  41. // mslogon support end
  42. //
  43. // Constructor.
  44. //
  45. // mslgon support 2
  46. public AuthPanel(boolean logon) {
  47. mslogon = logon;
  48. // mslgon support 2 end
  49. title = new Label("VNC Authentication",Label.CENTER);
  50. title.setFont(new Font("Helvetica", Font.BOLD, 18));
  51. prompt = new Label("Password:",Label.CENTER);
  52. password = new TextField(10);
  53. password.setForeground(Color.black);
  54. password.setBackground(Color.white);
  55. password.setEchoChar('*');
  56. // mslogon support 3
  57. if (mslogon) {
  58. promptuser = new Label("Username:",Label.CENTER);
  59. username = new TextField(10);
  60. username.setForeground(Color.black);
  61. username.setBackground(Color.white);
  62. }
  63. // mslogon support 3 end
  64. ok = new Button("OK");
  65. retry = new Label("",Label.CENTER);
  66. retry.setFont(new Font("Courier", Font.BOLD, 16));
  67. GridBagLayout gridbag = new GridBagLayout();
  68. GridBagConstraints gbc = new GridBagConstraints();
  69. setLayout(gridbag);
  70. gbc.gridwidth = GridBagConstraints.REMAINDER;
  71. gridbag.setConstraints(title,gbc);
  72. add(title);
  73. gbc.fill = GridBagConstraints.HORIZONTAL;
  74. gridbag.setConstraints(retry,gbc);
  75. add(retry);
  76. gbc.fill = GridBagConstraints.NONE;
  77. gbc.gridwidth = 1;
  78. //mslogon support 4
  79. if (mslogon) {
  80. gridbag.setConstraints(promptuser,gbc);
  81. add(promptuser);
  82. gridbag.setConstraints(username,gbc);
  83. add(username);
  84. username.addActionListener(this);
  85. }
  86. //mslogon support 4 end
  87. gridbag.setConstraints(prompt,gbc);
  88. add(prompt);
  89. gridbag.setConstraints(password,gbc);
  90. add(password);
  91. password.addActionListener(this);
  92. gbc.ipady = 10;
  93. gbc.gridwidth = GridBagConstraints.REMAINDER;
  94. gbc.fill = GridBagConstraints.BOTH;
  95. gbc.insets = new Insets(0,20,0,0);
  96. gbc.ipadx = 40;
  97. gridbag.setConstraints(ok,gbc);
  98. add(ok);
  99. ok.addActionListener(this);
  100. }
  101. // mslogon support 5
  102. public void setmslogon(boolean InfoMsLogon) {
  103. mslogon = InfoMsLogon;
  104. }
  105. public void moveFocusToUsernameField() {
  106. if (mslogon) { username.requestFocus(); }
  107. else { moveFocusToPasswordField();}
  108. }
  109. // mslogon support 5 end
  110. //
  111. // Move keyboard focus to the password text field object.
  112. //
  113. public void moveFocusToPasswordField() {
  114. password.requestFocus();
  115. }
  116. //
  117. // This method is called when a button is pressed or return is
  118. // pressed in the password text field.
  119. //
  120. public synchronized void actionPerformed(ActionEvent evt) {
  121. if (evt.getSource() == password || evt.getSource() == ok) {
  122. password.setEnabled(false);
  123. notify();
  124. }
  125. }
  126. //
  127. // retry().
  128. //
  129. public void retry() {
  130. retry.setText("Sorry. Try again.");
  131. password.setEnabled(true);
  132. password.setText("");
  133. moveFocusToPasswordField();
  134. }
  135. }