annotate src/AuthPanel.java @ 10:9c7eab50c708

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