17
|
1 package myVncClient;
|
0
|
2 //
|
|
3 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
|
4 // Copyright (C) 2002-2006 Constantin Kaplinsky. All Rights Reserved.
|
|
5 //
|
|
6 // This is free software; you can redistribute it and/or modify
|
|
7 // it under the terms of the GNU General Public License as published by
|
|
8 // the Free Software Foundation; either version 2 of the License, or
|
|
9 // (at your option) any later version.
|
|
10 //
|
|
11 // This software is distributed in the hope that it will be useful,
|
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 // GNU General Public License for more details.
|
|
15 //
|
|
16 // You should have received a copy of the GNU General Public License
|
|
17 // along with this software; if not, write to the Free Software
|
|
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
19 // USA.
|
|
20 //
|
|
21
|
|
22 import java.awt.*;
|
|
23 import java.awt.event.*;
|
|
24
|
|
25 //
|
|
26 // The panel which implements the user authentication scheme
|
|
27 //
|
|
28
|
|
29 class AuthPanel extends Panel implements ActionListener {
|
|
30
|
|
31 TextField passwordField;
|
|
32 Button okButton;
|
|
33
|
|
34 //
|
|
35 // Constructor.
|
|
36 //
|
|
37
|
|
38 public AuthPanel(VncViewer viewer)
|
|
39 {
|
|
40 Label titleLabel = new Label("VNC Authentication", Label.CENTER);
|
|
41 titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18));
|
|
42
|
|
43 Label promptLabel = new Label("Password:", Label.CENTER);
|
|
44
|
|
45 passwordField = new TextField(10);
|
|
46 passwordField.setForeground(Color.black);
|
|
47 passwordField.setBackground(Color.white);
|
|
48 passwordField.setEchoChar('*');
|
|
49
|
|
50 okButton = new Button("OK");
|
|
51
|
|
52 GridBagLayout gridbag = new GridBagLayout();
|
|
53 GridBagConstraints gbc = new GridBagConstraints();
|
|
54
|
|
55 setLayout(gridbag);
|
|
56
|
|
57 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
58 gbc.insets = new Insets(0,0,20,0);
|
|
59 gridbag.setConstraints(titleLabel,gbc);
|
|
60 add(titleLabel);
|
|
61
|
|
62 gbc.fill = GridBagConstraints.NONE;
|
|
63 gbc.gridwidth = 1;
|
|
64 gbc.insets = new Insets(0,0,0,0);
|
|
65 gridbag.setConstraints(promptLabel,gbc);
|
|
66 add(promptLabel);
|
|
67
|
|
68 gridbag.setConstraints(passwordField,gbc);
|
|
69 add(passwordField);
|
|
70 passwordField.addActionListener(this);
|
|
71
|
|
72 // gbc.ipady = 10;
|
|
73 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
74 gbc.fill = GridBagConstraints.BOTH;
|
|
75 gbc.insets = new Insets(0,20,0,0);
|
|
76 gbc.ipadx = 30;
|
|
77 gridbag.setConstraints(okButton,gbc);
|
|
78 add(okButton);
|
|
79 okButton.addActionListener(this);
|
|
80 }
|
|
81
|
|
82 //
|
|
83 // Move keyboard focus to the default object, that is, the password
|
|
84 // text field.
|
|
85 //
|
|
86
|
|
87 public void moveFocusToDefaultField()
|
|
88 {
|
|
89 passwordField.requestFocus();
|
|
90 }
|
|
91
|
|
92 //
|
|
93 // This method is called when a button is pressed or return is
|
|
94 // pressed in the password text field.
|
|
95 //
|
|
96
|
|
97 public synchronized void actionPerformed(ActionEvent evt)
|
|
98 {
|
|
99 if (evt.getSource() == passwordField || evt.getSource() == okButton) {
|
|
100 passwordField.setEnabled(false);
|
|
101 notify();
|
|
102 }
|
|
103 }
|
|
104
|
|
105 //
|
|
106 // Wait for user entering a password, and return it as String.
|
|
107 //
|
|
108
|
|
109 public synchronized String getPassword() throws Exception
|
|
110 {
|
|
111 try {
|
|
112 wait();
|
|
113 } catch (InterruptedException e) { }
|
|
114 return passwordField.getText();
|
|
115 }
|
|
116
|
|
117 }
|