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