root / trunk / frameworks / _fwAndami / src / com / iver / andami / authentication / LoginUI.java @ 9512
History | View | Annotate | Download (3.93 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 |
//TODO:
|
37 |
//Cambiar esto para que coja un icono de una ruta que se lee de un xml
|
38 |
static private ImageIcon gvsigIcon = new javax.swing.ImageIcon( |
39 |
LoginUI.class.getClassLoader().getResource("images/login_gvsig.png"));
|
40 |
|
41 |
IAuthentication authentication; |
42 |
|
43 |
public LoginUI(IAuthentication authentication )
|
44 |
{ |
45 |
Container container = getContentPane();
|
46 |
mainPanel = new GridBagLayoutPanel();
|
47 |
usernameField = new JTextField(25); |
48 |
passwordField = new JPasswordField(25); |
49 |
serverURLField = new JTextField(25); |
50 |
|
51 |
String server_text = (String)authentication.get("server_url"); |
52 |
if(server_text != null){ |
53 |
serverURLField.setText( server_text ); |
54 |
} |
55 |
|
56 |
buttonPanel = new JPanel(); |
57 |
okButton = new JButton( PluginServices.getText(this, "login_ok") ); |
58 |
okButton.addActionListener(new java.awt.event.ActionListener() {
|
59 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
60 |
OK(); |
61 |
} |
62 |
}); |
63 |
exitButton = new JButton( PluginServices.getText(this, "login_exit") ); |
64 |
exitButton.addActionListener(new java.awt.event.ActionListener() {
|
65 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
66 |
Cancel(); |
67 |
} |
68 |
}); |
69 |
|
70 |
buttonPanel.add( okButton ); |
71 |
buttonPanel.add( exitButton ); |
72 |
|
73 |
JPanel logoPanel = new JPanel(); |
74 |
logoPanel.add(new JLabel(gvsigIcon)); |
75 |
logoPanel.setBorder(BorderFactory.createEmptyBorder(1,1,1,10)); |
76 |
container.add(logoPanel, BorderLayout.WEST);
|
77 |
container.add( mainPanel, BorderLayout.CENTER );
|
78 |
mainPanel.addComponent(PluginServices.getText(this, "login_name"), usernameField); |
79 |
mainPanel.addComponent(PluginServices.getText(this, "login_password"), passwordField); |
80 |
mainPanel.addComponent(PluginServices.getText(this, "login_name"), serverURLField); |
81 |
invalidLoginLabel = new JLabel(PluginServices.getText(this, "login_invalid_user")); |
82 |
invalidLoginLabel.setForeground(Color.RED);
|
83 |
invalidLoginLabel.setVisible( false );
|
84 |
mainPanel.addComponent(invalidLoginLabel, buttonPanel); |
85 |
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
86 |
|
87 |
this.authentication = authentication;
|
88 |
this.setBounds(400,400,this.getWidth(),this.getHeight()); |
89 |
this.setTitle( "Login" ); |
90 |
this.setModal(true); |
91 |
this.setSize( 400, 200); |
92 |
this.setResizable( false ); |
93 |
pack(); |
94 |
setVisible( true );
|
95 |
} |
96 |
|
97 |
public void OK() |
98 |
{ |
99 |
if (((String)serverURLField.getText() == null) || (((String)serverURLField.getText()).length() == 0)){ |
100 |
return;
|
101 |
} |
102 |
|
103 |
authentication.put("user", (String)usernameField.getText()); |
104 |
authentication.put("pwd", new String(passwordField.getPassword())); |
105 |
authentication.put("server", (String)serverURLField.getText()); |
106 |
|
107 |
if (authentication.isValidUser()){
|
108 |
authentication.setLogged(true);
|
109 |
dispose(); |
110 |
} |
111 |
else{
|
112 |
usernameField.setText("");
|
113 |
passwordField.setText("");
|
114 |
if (isFirstLogin)
|
115 |
{ |
116 |
invalidLoginLabel.setVisible(true);
|
117 |
isFirstLogin = false;
|
118 |
} |
119 |
//JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Invalid user/password");
|
120 |
} |
121 |
} |
122 |
|
123 |
public void Cancel() |
124 |
{ |
125 |
authentication.put("user", ""); |
126 |
authentication.put("pwd", ""); |
127 |
authentication.setLogged(false);
|
128 |
dispose(); |
129 |
} |
130 |
|
131 |
} |