blob: 04d3bdec510a8b4a026a2253acf9d97321c34a30 [file] [log] [blame]
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00001//
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
Adam Tkacf53e62a2009-03-13 13:20:26 +000021package com.tigervnc.vncviewer;
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000022
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000023import java.awt.*;
24import java.awt.event.*;
25
26//
27// The panel which implements the user authentication scheme
28//
29
30class AuthPanel extends Panel implements ActionListener {
31
32 TextField passwordField;
33 Button okButton;
34
35 //
36 // Constructor.
37 //
38
39 public AuthPanel(VncViewer viewer)
40 {
41 Label titleLabel = new Label("VNC Authentication", Label.CENTER);
42 titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18));
43
44 Label promptLabel = new Label("Password:", Label.CENTER);
45
46 passwordField = new TextField(10);
47 passwordField.setForeground(Color.black);
48 passwordField.setBackground(Color.white);
49 passwordField.setEchoChar('*');
50
51 okButton = new Button("OK");
52
53 GridBagLayout gridbag = new GridBagLayout();
54 GridBagConstraints gbc = new GridBagConstraints();
55
56 setLayout(gridbag);
57
58 gbc.gridwidth = GridBagConstraints.REMAINDER;
59 gbc.insets = new Insets(0,0,20,0);
60 gridbag.setConstraints(titleLabel,gbc);
61 add(titleLabel);
62
63 gbc.fill = GridBagConstraints.NONE;
64 gbc.gridwidth = 1;
65 gbc.insets = new Insets(0,0,0,0);
66 gridbag.setConstraints(promptLabel,gbc);
67 add(promptLabel);
68
69 gridbag.setConstraints(passwordField,gbc);
70 add(passwordField);
71 passwordField.addActionListener(this);
72
73 // gbc.ipady = 10;
74 gbc.gridwidth = GridBagConstraints.REMAINDER;
75 gbc.fill = GridBagConstraints.BOTH;
76 gbc.insets = new Insets(0,20,0,0);
77 gbc.ipadx = 30;
78 gridbag.setConstraints(okButton,gbc);
79 add(okButton);
80 okButton.addActionListener(this);
81 }
82
83 //
84 // Move keyboard focus to the default object, that is, the password
85 // text field.
86 //
87
88 public void moveFocusToDefaultField()
89 {
90 passwordField.requestFocus();
91 }
92
93 //
94 // This method is called when a button is pressed or return is
95 // pressed in the password text field.
96 //
97
98 public synchronized void actionPerformed(ActionEvent evt)
99 {
100 if (evt.getSource() == passwordField || evt.getSource() == okButton) {
101 passwordField.setEnabled(false);
102 notify();
103 }
104 }
105
106 //
107 // Wait for user entering a password, and return it as String.
108 //
109
110 public synchronized String getPassword() throws Exception
111 {
112 try {
113 wait();
114 } catch (InterruptedException e) { }
115 return passwordField.getText();
116 }
117
118}