summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/LoginControl.java
blob: 2e6b8532c7938f0c1677b43fb8334f82e918aff2 (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
package jrummikub.control;

import java.util.ArrayList;
import java.util.List;

import jrummikub.util.Connection;
import jrummikub.util.Event;
import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.LoginData;
import jrummikub.view.IView;

public class LoginControl {
	private IView view;
	private Event1<LoginData> loginEvent = new Event1<LoginData>();
	private Event cancelEvent = new Event();
	private List<Connection> connections = new ArrayList<Connection>();

	public LoginControl(final IView view) {
		this.view = view;
		connections.add(view.getLoginPanel().getLoginEvent()
				.add(new IListener1<LoginData>() {
					@Override
					public void handle(LoginData loginData) {
						abort();
						loginEvent.emit(loginData);
					}
				}));

		connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() {
			@Override
			public void handle() {
				abort();
				cancelEvent.emit();
			}
		}));
	}

	public void startLogin() {
		view.showLoginPanel(true);
	}

	public IEvent1<LoginData> getLoginEvent() {
		return loginEvent;
	}

	public IEvent getCancelEvent() {
		return cancelEvent;
	}

	public void abort() {
		view.showLoginPanel(false);
		for (Connection c : connections) {
			c.remove();
		}
	}
}