Statistics
| Revision:

root / branches / piloto3d / frameworks / _fwAndami / src / com / iver / andami / ui / LoginUI.java @ 9543

History | View | Annotate | Download (3.16 KB)

1 4261 ldiaz
package com.iver.andami.ui;
2
3 5275 jaume
import java.awt.BorderLayout;
4
import java.awt.Container;
5
import java.awt.GridLayout;
6
7
import javax.swing.JButton;
8
import javax.swing.JDialog;
9
import javax.swing.JLabel;
10
import javax.swing.JPanel;
11
import javax.swing.JPasswordField;
12
import javax.swing.JTextField;
13
14 4261 ldiaz
import com.iver.andami.authentication.IAuthentication;
15
16
/**
17
 * Form to let the user log in the system.
18
 * @author laura
19
 *
20
 */
21 4570 ldiaz
public class LoginUI extends JDialog
22 4261 ldiaz
{
23
        private JLabel usernameLabel;
24
        private JLabel passwordLabel;
25 5323 ldiaz
        private JLabel serverURLLabel;
26 4261 ldiaz
27
        private JTextField usernameField;
28
        private JPasswordField passwordField;
29 5323 ldiaz
        private JTextField serverURLField;
30 4261 ldiaz
31
        private JButton okButton;
32
        private JButton exitButton;
33
34 5448 ldiaz
        private JPanel mainPanel;
35
        private JPanel labelsPanel;
36
        private JPanel textFieldsPanel;
37
38
        //private JPanel upperPanel;
39 4261 ldiaz
        private JPanel buttonPanel;
40 4300 ldiaz
41 4261 ldiaz
        IAuthentication authentication;
42
43
        public LoginUI(IAuthentication authentication )
44
        {
45
                Container container = getContentPane();
46 5448 ldiaz
                mainPanel = new JPanel();
47
                mainPanel.setLayout(new BorderLayout());
48
49 4570 ldiaz
                usernameLabel = new JLabel( "Nombre: " );
50
                passwordLabel = new JLabel( "Clave : " );
51 5323 ldiaz
                serverURLLabel = new JLabel( "Servidor: ");
52 4261 ldiaz
                usernameField = new JTextField();
53
                passwordField = new JPasswordField();
54 5323 ldiaz
                serverURLField = new JTextField();
55
56
                String server_text = (String)authentication.get("server_url");
57
                if(server_text != null){
58
                        serverURLField.setText( server_text );
59
                }
60 5448 ldiaz
61
                labelsPanel = new JPanel();
62
                labelsPanel.setLayout(new GridLayout( 3, 1));
63
                textFieldsPanel = new JPanel();
64
                textFieldsPanel.setLayout( new GridLayout( 3, 1 ) );
65
                labelsPanel.add( usernameLabel );
66
                textFieldsPanel.add( usernameField );
67
                labelsPanel.add( passwordLabel );
68
                textFieldsPanel.add( passwordField );
69
                labelsPanel.add( serverURLLabel);
70
                textFieldsPanel.add( serverURLField);
71
72 4261 ldiaz
                buttonPanel = new JPanel();
73 5448 ldiaz
                //buttonPanel.setLayout( new GridLayout( 1, 2 ) );
74 4261 ldiaz
                okButton = new JButton( "OK" );
75 4570 ldiaz
                okButton.addActionListener(new java.awt.event.ActionListener() {
76
                        public void actionPerformed(java.awt.event.ActionEvent e) {
77
                                OK();
78
                        }
79
                });
80 4261 ldiaz
                exitButton = new JButton( "Exit" );
81 4570 ldiaz
                exitButton.addActionListener(new java.awt.event.ActionListener() {
82
                        public void actionPerformed(java.awt.event.ActionEvent e) {
83
                                Cancel();
84
                        }
85
                });
86 4261 ldiaz
87
                buttonPanel.add( okButton );
88
                buttonPanel.add( exitButton );
89 4300 ldiaz
90 5448 ldiaz
                container.add( mainPanel, BorderLayout.CENTER );
91
                mainPanel.add(labelsPanel, BorderLayout.WEST );
92
                mainPanel.add(textFieldsPanel, BorderLayout.EAST);
93
                mainPanel.add( buttonPanel, BorderLayout.SOUTH );
94
95 4300 ldiaz
                this.authentication = authentication;
96
                this.setBounds(400,400,this.getWidth(),this.getHeight());
97
                this.setTitle( "Login" );
98
                this.setModal(true);
99 4570 ldiaz
                this.setSize( 400, 200);
100 4300 ldiaz
                this.setResizable( false );
101 4261 ldiaz
                pack();
102
                setVisible( true );
103
        }
104
105 4570 ldiaz
        public void OK()
106 4261 ldiaz
        {
107 4570 ldiaz
                authentication.put("user", (String)usernameField.getText());
108
                authentication.put("pwd", new String(passwordField.getPassword()));
109 5323 ldiaz
                authentication.put("server", (String)serverURLField.getText());
110 4570 ldiaz
                this.dispose();
111 4261 ldiaz
        }
112 4570 ldiaz
        public void Cancel()
113
        {
114
                authentication.put("user", "");
115
                authentication.put("pwd", "");
116
                dispose();
117
                System.exit( 0 );
118
        }
119 4300 ldiaz
120 4261 ldiaz
}