Statistics
| Revision:

root / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / authentication / LoginUI.java @ 29593

History | View | Annotate | Download (3.85 KB)

1
package org.gvsig.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

    
15
import org.gvsig.andami.PluginServices;
16
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
17
import org.gvsig.gui.beans.swing.JButton;
18

    
19

    
20
/**
21
 * Form to let the user log in the system.
22
 * @author laura
23
 *
24
 */
25
public class LoginUI extends JDialog
26
{
27
        private JTextField usernameField;
28
        private JPasswordField passwordField;
29
        private JTextField serverURLField;
30
        private JLabel invalidLoginLabel;
31
        private JButton okButton;
32
        private JButton exitButton;
33
        private GridBagLayoutPanel mainPanel;
34
        private JPanel buttonPanel;
35
        private boolean isFirstLogin = true;
36

    
37
        //TODO:
38
        //Cambiar esto para que coja un icono de una ruta que se lee de un xml
39

    
40
        static private ImageIcon gvsigIcon = PluginServices
41
                .getIconTheme().get("login-gvsig");
42

    
43
        IAuthentication authentication;
44

    
45
        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

    
53
                String server_text = (String)authentication.get("server_url");
54
                if(server_text != null){
55
                        serverURLField.setText( server_text );
56
                }
57

    
58
                buttonPanel = new JPanel();
59
                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

    
72
                buttonPanel.add( okButton );
73
                buttonPanel.add( exitButton );
74

    
75
                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
                mainPanel.addComponent(invalidLoginLabel, buttonPanel);
87
                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

    
99
        public void OK()
100
        {
101
                  if (((String)serverURLField.getText() == null) || (((String)serverURLField.getText()).length() == 0)){
102
                          return;
103
                  }
104

    
105
                authentication.put("user", (String)usernameField.getText());
106
                authentication.put("pwd", new String(passwordField.getPassword()));
107
                authentication.put("server", (String)serverURLField.getText());
108

    
109
                if (authentication.isValidUser()){
110
                        authentication.setLogged(true);
111
                        dispose();
112
                }
113
                else{
114
                        usernameField.setText("");
115
                        passwordField.setText("");
116
                        if (isFirstLogin)
117
                        {
118
                                invalidLoginLabel.setVisible(true);
119
                                isFirstLogin = false;
120
                        }
121
                        //JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Invalid user/password");
122
                }
123
        }
124

    
125
        public void Cancel()
126
        {
127
                authentication.put("user", "");
128
                authentication.put("pwd", "");
129
                authentication.setLogged(false);
130
                dispose();
131
        }
132

    
133
}