1
2
3
4
5 package org.directdemocracyportal.democracy.web.views.dialogs;
6
7 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
8 import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
9
10 import thinwire.ui.Button;
11 import thinwire.ui.Label;
12 import thinwire.ui.TextField;
13 import thinwire.ui.AlignTextComponent.AlignX;
14 import thinwire.ui.event.ActionEvent;
15 import thinwire.ui.event.ActionListener;
16 import thinwire.ui.layout.TableLayout;
17
18 /***
19 * The Class LoginDialog.
20 */
21 public class LoginDialog extends AbstractActionDialog
22 {
23
24 /*** The name field. */
25 private TextField nameField = new TextField();
26
27 /*** The password field. */
28 private TextField passwordField = new TextField();
29
30 /*** The error message label. */
31 private Label errorMessageLabel = new Label();
32
33 /*** The login action listener. */
34 ActionListener loginActionListener = new ActionListener() {
35 public void actionPerformed(ActionEvent ev) {
36 dialogResult = DialogResult.Do_Action;
37 setVisible(false);
38 }
39 };
40
41 /*** The cancel action listener. */
42 ActionListener cancelActionListener = new ActionListener() {
43 public void actionPerformed(ActionEvent ev) {
44 dialogResult = DialogResult.Action_Cancelled;
45 setVisible(false);
46 }
47 };
48
49 /***
50 * Instantiates a new login dialog.
51 */
52 public LoginDialog() {
53 super(ApplicationMessageHolder
54 .getMessage(MessageConstans.BUTTON_LOGIN));
55 setPosition(200, 200);
56 setSize(350, 160);
57 setLayout(new TableLayout(new double[][] { { 120, 200 },
58
59 { 30, 30, 30, 30 } },
60 10,
61 5));
62 Label nameLabel = new Label(ApplicationMessageHolder
63 .getMessage(MessageConstans.NAME));
64 nameLabel.setLimit("0,0");
65 getChildren().add(nameLabel);
66
67 nameField.setLimit("1,0");
68 getChildren().add(nameField);
69
70 Label passwordLabel = new Label(ApplicationMessageHolder
71 .getMessage(MessageConstans.PASSWORD));
72 passwordLabel.setLimit("0,1");
73 passwordLabel.setAlignX(AlignX.LEFT);
74 getChildren().add(passwordLabel);
75
76 passwordField.setLimit("1,1");
77 passwordField.setInputHidden(true);
78 getChildren().add(passwordField);
79
80 errorMessageLabel.setVisible(false);
81 errorMessageLabel.setLimit("0,2,2,1");
82 getChildren().add(errorMessageLabel);
83
84 Button okButton = new Button(ApplicationMessageHolder
85 .getMessage(MessageConstans.BUTTON_OK));
86 okButton.setLimit("0,3");
87 okButton.addActionListener(ACTION_CLICK, loginActionListener);
88 getChildren().add(okButton);
89
90 Button cancelButton = new Button(ApplicationMessageHolder
91 .getMessage(MessageConstans.BUTTON_CANCEL));
92 cancelButton.setLimit("1,3");
93 cancelButton.addActionListener(ACTION_CLICK, cancelActionListener);
94 getChildren().add(cancelButton);
95 }
96
97 /***
98 * Gets the name.
99 *
100 * @return the name
101 */
102 public String getName() {
103 return nameField.getText();
104 }
105
106 /***
107 * Gets the password.
108 *
109 * @return the password
110 */
111 public String getPassword() {
112 return passwordField.getText();
113 }
114 }