From 71def36c8950bd9c2b54e2e4a885d365ae0d49bb Mon Sep 17 00:00:00 2001 From: Adam Tkac Date: Thu, 11 Nov 2010 13:25:14 +0000 Subject: [PATCH] [Development] java: Support asking for a user name. (Martin Koegler) git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4192 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- .../src/com/tigervnc/vncviewer/AuthPanel.java | 13 ++++++-- .../src/com/tigervnc/vncviewer/VncViewer.java | 31 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/java/src/com/tigervnc/vncviewer/AuthPanel.java b/java/src/com/tigervnc/vncviewer/AuthPanel.java index 04d3bdec..a23758e4 100644 --- a/java/src/com/tigervnc/vncviewer/AuthPanel.java +++ b/java/src/com/tigervnc/vncviewer/AuthPanel.java @@ -31,22 +31,29 @@ class AuthPanel extends Panel implements ActionListener { TextField passwordField; Button okButton; + boolean AskPassword; // // Constructor. // - public AuthPanel(VncViewer viewer) + public AuthPanel(VncViewer viewer, boolean askpassword) { + AskPassword = askpassword; Label titleLabel = new Label("VNC Authentication", Label.CENTER); titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18)); - Label promptLabel = new Label("Password:", Label.CENTER); + Label promptLabel; + if (AskPassword) + promptLabel = new Label("Password:", Label.CENTER); + else + promptLabel = new Label("User:", Label.CENTER); passwordField = new TextField(10); passwordField.setForeground(Color.black); passwordField.setBackground(Color.white); - passwordField.setEchoChar('*'); + if (AskPassword) + passwordField.setEchoChar('*'); okButton = new Button("OK"); diff --git a/java/src/com/tigervnc/vncviewer/VncViewer.java b/java/src/com/tigervnc/vncviewer/VncViewer.java index 711b1c95..19541afe 100644 --- a/java/src/com/tigervnc/vncviewer/VncViewer.java +++ b/java/src/com/tigervnc/vncviewer/VncViewer.java @@ -437,11 +437,40 @@ public class VncViewer extends java.applet.Applet // Show an authentication panel. // + String askUser() throws Exception + { + showConnectionStatus(null); + + AuthPanel authPanel = new AuthPanel(this, false); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.ipadx = 100; + gbc.ipady = 50; + gridbag.setConstraints(authPanel, gbc); + vncContainer.add(authPanel); + + if (inSeparateFrame) { + vncFrame.pack(); + } else { + validate(); + } + + authPanel.moveFocusToDefaultField(); + String pw = authPanel.getPassword(); + vncContainer.remove(authPanel); + + return pw; + } + String askPassword() throws Exception { showConnectionStatus(null); - AuthPanel authPanel = new AuthPanel(this); + AuthPanel authPanel = new AuthPanel(this, true); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; -- 2.39.5