summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/GameListPanel.java
blob: d509a6e55e3b33d75c3ac7be1269300a9e390495 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import jrummikub.util.Event;
import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.view.IGameListPanel;

class GameListPanel extends JPanel implements IGameListPanel {
	private JLabel title;
	private JList gameList;
	private JButton joinButton;
	private JButton openNewGameButton;
	private JButton cancelButton;
	private Event1<GameData> joinEvent = new Event1<GameData>();
	private Event openNewGameEvent = new Event();
	private Event cancelEvent = new Event();

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

		title = new JLabel();
		add(title, c);

		gameList = new JList();
		c.weighty = 1;
		add(new JScrollPane(gameList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c);

		joinButton = new JButton("Beitreten");
		c.weighty = 0;
		c.gridwidth = 1;
		add(joinButton, c);
		joinButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				// joinEvent.emit();
			}
		});

		c.weightx = 0;
		add(Box.createHorizontalStrut(10), c);

		openNewGameButton = new JButton("Neues Spiel");
		c.weightx = 1;
		add(openNewGameButton, c);
		openNewGameButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				openNewGameEvent.emit();
			}
		});

		c.weightx = 0;
		add(Box.createHorizontalStrut(10), c);

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

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

	@Override
	public IEvent getOpenNewGameEvent() {
		return openNewGameEvent;
	}

	@Override
	public IEvent1<GameData> getJoinEvent() {
		return joinEvent;
	}

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

}