Mercurial > hg > Applications > TightVNC_orginal
comparison src/viewer_swing/java/com/glavsoft/viewer/swing/gui/PasswordDialog.java @ 52:472a9bcacb21 draft default tip
TightVNC 2.7.1.0
author | you@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 07 Aug 2013 19:01:17 +0900 |
parents | 4689cc86d6cb |
children |
comparison
equal
deleted
inserted
replaced
0:4689cc86d6cb | 52:472a9bcacb21 |
---|---|
1 // Copyright (C) 2010, 2011 GlavSoft LLC. | 1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 //------------------------------------------------------------------------- | 4 //------------------------------------------------------------------------- |
5 // This file is part of the TightVNC software. Please visit our Web site: | 5 // This file is part of the TightVNC software. Please visit our Web site: |
6 // | 6 // |
22 //------------------------------------------------------------------------- | 22 //------------------------------------------------------------------------- |
23 // | 23 // |
24 | 24 |
25 package com.glavsoft.viewer.swing.gui; | 25 package com.glavsoft.viewer.swing.gui; |
26 | 26 |
27 import com.glavsoft.viewer.ConnectionWorker; | |
27 import com.glavsoft.viewer.swing.Utils; | 28 import com.glavsoft.viewer.swing.Utils; |
28 | 29 |
29 import javax.swing.*; | 30 import javax.swing.*; |
30 import javax.swing.border.EmptyBorder; | 31 import javax.swing.border.EmptyBorder; |
31 import java.awt.*; | 32 import java.awt.*; |
32 import java.awt.event.ActionEvent; | 33 import java.awt.event.ActionEvent; |
33 import java.awt.event.ActionListener; | 34 import java.awt.event.ActionListener; |
34 import java.awt.event.WindowListener; | 35 import java.awt.event.WindowAdapter; |
35 import java.util.List; | 36 import java.awt.event.WindowEvent; |
36 | 37 |
37 /** | 38 /** |
38 * Dialog to ask password | 39 * Dialog to ask password |
39 */ | 40 */ |
40 @SuppressWarnings("serial") | 41 @SuppressWarnings("serial") |
42 | 43 |
43 private String password = ""; | 44 private String password = ""; |
44 | 45 |
45 private static final int PADDING = 4; | 46 private static final int PADDING = 4; |
46 private final JLabel messageLabel; | 47 private final JLabel messageLabel; |
47 public PasswordDialog(Frame owner, final WindowListener onClose, boolean isApplet) { | 48 public PasswordDialog(Frame owner, final ConnectionWorker onCancel) { |
48 super(owner, "Login", isApplet ? ModalityType.APPLICATION_MODAL : ModalityType.TOOLKIT_MODAL); | 49 super(owner, "VNC Authentication", true); |
49 try { | 50 addWindowListener(new WindowAdapter() { |
50 setAlwaysOnTop(true); | 51 @Override |
51 } catch (SecurityException e) { /*nop*/ } | 52 public void windowClosed(WindowEvent windowEvent) { |
52 addWindowListener(onClose); | 53 onCancel.cancel(); |
54 } | |
55 }); | |
53 JPanel pane = new JPanel(new GridLayout(0, 1, PADDING, PADDING)); | 56 JPanel pane = new JPanel(new GridLayout(0, 1, PADDING, PADDING)); |
54 add(pane); | 57 add(pane); |
55 pane.setBorder(new EmptyBorder(PADDING, PADDING, PADDING, PADDING)); | 58 pane.setBorder(new EmptyBorder(PADDING, PADDING, PADDING, PADDING)); |
56 | 59 |
57 messageLabel = new JLabel("Server requires password authentication"); | 60 messageLabel = new JLabel("Server requires VNC authentication"); |
58 pane.add(messageLabel); | 61 pane.add(messageLabel); |
59 | 62 |
60 JPanel passwordPanel = new JPanel(); | 63 JPanel passwordPanel = new JPanel(); |
61 passwordPanel.add(new JLabel("Password:")); | 64 passwordPanel.add(new JLabel("Password:")); |
62 final JPasswordField passwordField = new JPasswordField("", 20); | 65 final JPasswordField passwordField = new JPasswordField("", 20); |
72 password = new String(passwordField.getPassword()); | 75 password = new String(passwordField.getPassword()); |
73 setVisible(false); | 76 setVisible(false); |
74 } | 77 } |
75 }); | 78 }); |
76 | 79 |
77 JButton closeButton = new JButton("Close"); | 80 JButton closeButton = new JButton("Cancel"); |
78 buttonPanel.add(closeButton); | 81 buttonPanel.add(closeButton); |
79 closeButton.addActionListener(new ActionListener() { | 82 closeButton.addActionListener(new ActionListener() { |
80 @Override | 83 @Override |
81 public void actionPerformed(ActionEvent e) { | 84 public void actionPerformed(ActionEvent e) { |
85 password = null; | |
82 setVisible(false); | 86 setVisible(false); |
83 onClose.windowClosing(null); | 87 onCancel.cancel(); |
84 } | 88 } |
85 }); | 89 }); |
86 | 90 |
87 pane.add(buttonPanel); | 91 pane.add(buttonPanel); |
88 | 92 |
89 getRootPane().setDefaultButton(loginButton); | 93 getRootPane().setDefaultButton(loginButton); |
90 | 94 Utils.decorateDialog(this); |
91 List<Image> icons = Utils.getIcons(); | 95 Utils.centerWindow(this); |
92 if (icons.size() != 0) { | 96 addWindowFocusListener(new WindowAdapter() { |
93 setIconImages(icons); | 97 @Override |
94 } | 98 public void windowGainedFocus(WindowEvent e) { |
95 | 99 passwordField.requestFocusInWindow(); |
96 // center dialog | 100 } |
97 Point locationPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); | 101 }); |
98 pack(); | |
99 Rectangle bounds = getBounds(); | |
100 locationPoint.setLocation( | |
101 locationPoint.x - bounds.width/2, locationPoint.y - bounds.height/2); | |
102 setLocation(locationPoint); | |
103 } | 102 } |
104 | 103 |
105 public void setServerHostName(String serverHostName) { | 104 public void setServerHostName(String serverHostName) { |
106 messageLabel.setText("Server '" + serverHostName + "' requires password authentication"); | 105 messageLabel.setText("Server '" + serverHostName + "' requires VNC authentication"); |
107 pack(); | 106 pack(); |
108 } | 107 } |
109 | 108 |
110 public String getPassword() { | 109 public String getPassword() { |
111 return password; | 110 return password; |
112 } | 111 } |
113 | 112 |
113 | |
114 | |
114 } | 115 } |