summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/LoginPanel.java
blob: ca9f37f875f98cfcb66facdbed35f3d77e683bbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package jrummikub.view.impl;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import jrummikub.util.Event;
import jrummikub.util.Event3;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent3;
import jrummikub.view.ILoginPanel;

@SuppressWarnings("serial")
class LoginPanel extends JPanel implements ILoginPanel {
	private Event3<String, String, String> loginEvent = new Event3<String, String, String>();
	private Event cancelEvent = new Event();
	private JTextField userNameField;
	private JTextField passwordField;
	private JTextField channelNameField;

	LoginPanel() {
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.weightx = 1;
		c.weighty = 1;

		userNameField = addInputRow("Benutzername:");
		passwordField = addInputRow("Passwort:");
		channelNameField = addInputRow("Channel:");
		add(Box.createVerticalGlue(), c);

		c.gridwidth = 1;
		c.weighty = 0;

		JButton loginButton = new JButton("Login");
		loginButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				loginEvent.emit(userNameField.getText(),
						passwordField.getText(), channelNameField.getText());
			}
		});
		add(loginButton, c);

		c.gridwidth = GridBagConstraints.REMAINDER;
		JButton cancelButton = new JButton("Abbrechen");
		cancelButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				cancelEvent.emit();
			}
		});
		add(cancelButton, c);

		setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
				new EmptyBorder(10, 10, 10, 10)));
	}

	@Override
	public IEvent3<String, String, String> getLoginEvent() {
		return loginEvent;
	}

	@Override
	public IEvent getCancelEvent() {
		return cancelEvent;
	}

	private JTextField addInputRow(String label) {
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = 1;
		c.weightx = 1;
		c.weighty = 0;

		add(new JLabel(label), c);

		JTextField textField = new JTextField();

		c.gridwidth = GridBagConstraints.REMAINDER;
		add(textField, c);
		return textField;
	}
}