svn-gvsig-desktop / branches / v10 / frameworks / _fwAndami / src / com / iver / andami / authentication / LoginUI.java @ 10369
History | View | Annotate | Download (3.85 KB)
1 |
package com.iver.andami.authentication; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Container; |
6 |
|
7 |
import javax.swing.BorderFactory; |
8 |
import javax.swing.ImageIcon; |
9 |
import javax.swing.JDialog; |
10 |
import javax.swing.JLabel; |
11 |
import javax.swing.JPanel; |
12 |
import javax.swing.JPasswordField; |
13 |
import javax.swing.JTextField; |
14 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
15 |
import org.gvsig.gui.beans.swing.JButton; |
16 |
|
17 |
import com.iver.andami.PluginServices; |
18 |
|
19 |
/**
|
20 |
* Form to let the user log in the system.
|
21 |
* @author laura
|
22 |
*
|
23 |
*/
|
24 |
public class LoginUI extends JDialog |
25 |
{ |
26 |
private JTextField usernameField; |
27 |
private JPasswordField passwordField; |
28 |
private JTextField serverURLField; |
29 |
private JLabel invalidLoginLabel; |
30 |
private JButton okButton; |
31 |
private JButton exitButton; |
32 |
private GridBagLayoutPanel mainPanel;
|
33 |
private JPanel buttonPanel; |
34 |
private boolean isFirstLogin = true; |
35 |
|
36 |
static private ImageIcon gvsigIcon = new javax.swing.ImageIcon( |
37 |
LoginUI.class.getClassLoader().getResource("images/login_gvsig.png"));
|
38 |
|
39 |
IAuthentication authentication; |
40 |
|
41 |
public LoginUI(IAuthentication authentication )
|
42 |
{ |
43 |
Container container = getContentPane();
|
44 |
mainPanel = new GridBagLayoutPanel();
|
45 |
usernameField = new JTextField(25); |
46 |
passwordField = new JPasswordField(25); |
47 |
serverURLField = new JTextField(25); |
48 |
|
49 |
String server_text = (String)authentication.get("server_url"); |
50 |
if(server_text != null){ |
51 |
serverURLField.setText( server_text ); |
52 |
} |
53 |
|
54 |
buttonPanel = new JPanel(); |
55 |
okButton = new JButton( PluginServices.getText(this, "login_ok") ); |
56 |
okButton.addActionListener(new java.awt.event.ActionListener() {
|
57 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
58 |
OK(); |
59 |
} |
60 |
}); |
61 |
exitButton = new JButton( PluginServices.getText(this, "login_exit") ); |
62 |
exitButton.addActionListener(new java.awt.event.ActionListener() {
|
63 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
64 |
Cancel(); |
65 |
} |
66 |
}); |
67 |
|
68 |
buttonPanel.add( okButton ); |
69 |
buttonPanel.add( exitButton ); |
70 |
|
71 |
JPanel logoPanel = new JPanel(); |
72 |
logoPanel.add(new JLabel(gvsigIcon)); |
73 |
logoPanel.setBorder(BorderFactory.createEmptyBorder(1,1,1,10)); |
74 |
container.add(logoPanel, BorderLayout.WEST);
|
75 |
container.add( mainPanel, BorderLayout.CENTER );
|
76 |
mainPanel.addComponent(PluginServices.getText(this, "login_name"), usernameField); |
77 |
mainPanel.addComponent(PluginServices.getText(this, "login_password"), passwordField); |
78 |
mainPanel.addComponent(PluginServices.getText(this, "login_name"), serverURLField); |
79 |
invalidLoginLabel = new JLabel(PluginServices.getText(this, "login_invalid_user")); |
80 |
invalidLoginLabel.setForeground(Color.RED);
|
81 |
invalidLoginLabel.setVisible( false );
|
82 |
mainPanel.addComponent(invalidLoginLabel, buttonPanel); |
83 |
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
84 |
|
85 |
this.authentication = authentication;
|
86 |
this.setBounds(400,400,this.getWidth(),this.getHeight()); |
87 |
this.setTitle( "Login" ); |
88 |
this.setModal(true); |
89 |
this.setSize( 400, 200); |
90 |
this.setResizable( false ); |
91 |
pack(); |
92 |
setVisible( true );
|
93 |
} |
94 |
|
95 |
public void OK() |
96 |
{ |
97 |
if (((String)serverURLField.getText() == null) || (((String)serverURLField.getText()).length() == 0)){ |
98 |
return;
|
99 |
} |
100 |
|
101 |
authentication.put("user", (String)usernameField.getText()); |
102 |
authentication.put("pwd", new String(passwordField.getPassword())); |
103 |
authentication.put("server", (String)serverURLField.getText()); |
104 |
|
105 |
if (authentication.isValidUser()){
|
106 |
authentication.setLogged(true);
|
107 |
dispose(); |
108 |
} |
109 |
else{
|
110 |
usernameField.setText("");
|
111 |
passwordField.setText("");
|
112 |
if (isFirstLogin)
|
113 |
{ |
114 |
invalidLoginLabel.setVisible(true);
|
115 |
isFirstLogin = false;
|
116 |
} |
117 |
//JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Invalid user/password");
|
118 |
} |
119 |
} |
120 |
|
121 |
public void Cancel() |
122 |
{ |
123 |
authentication.put("user", ""); |
124 |
authentication.put("pwd", ""); |
125 |
authentication.setLogged(false);
|
126 |
dispose(); |
127 |
} |
128 |
|
129 |
} |