summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r--src/jrummikub/view/impl/View.java109
1 files changed, 58 insertions, 51 deletions
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index ab6b4c2..8ef8e50 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -68,6 +68,7 @@ public class View extends JFrame implements IView {
private Event menuNewGameEvent = new Event();
private Event menuQuitEvent = new Event();
+ private Event networkGameEvent = new Event();
private Event1<File> loadEvent = new Event1<File>();
private Event1<File> saveEvent = new Event1<File>();
@@ -137,7 +138,7 @@ public class View extends JFrame implements IView {
@Override
public IEvent getNetworkGameEvent() {
- return settingsPanel.getNetworkGameEvent();
+ return networkGameEvent;
}
@Override
@@ -145,8 +146,7 @@ public class View extends JFrame implements IView {
showScorePanel(false);
showSettingsPanel(false);
showLoginPanel(false);
- getHandPanel().setStones(
- Collections.<Pair<Stone, Position>> emptyList());
+ getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
@@ -165,14 +165,8 @@ public class View extends JFrame implements IView {
JMenu gameMenu = new JMenu("Spiel");
menuBar.add(gameMenu);
- JMenuItem newItem = new JMenuItem("Neu");
- newItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- menuNewGameEvent.emit();
- }
- });
- gameMenu.add(newItem);
+ gameMenu.add(createMenuItem("Neu", menuNewGameEvent));
+ gameMenu.add(createMenuItem("Netzwerkspiel...", networkGameEvent));
gameMenu.addSeparator();
@@ -195,16 +189,20 @@ public class View extends JFrame implements IView {
gameMenu.addSeparator();
- JMenuItem quitItem = new JMenuItem("Beenden");
- quitItem.addActionListener(new ActionListener() {
+ gameMenu.add(createMenuItem("Beenden", menuQuitEvent));
+
+ setJMenuBar(menuBar);
+ }
+
+ private JMenuItem createMenuItem(String text, final Event event) {
+ JMenuItem item = new JMenuItem(text);
+ item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- menuQuitEvent.emit();
+ event.emit();
}
});
- gameMenu.add(quitItem);
-
- setJMenuBar(menuBar);
+ return item;
}
private void load() {
@@ -240,15 +238,7 @@ public class View extends JFrame implements IView {
createMainLayer();
- settingsPanel = new SettingsPanel();
- settingsPanel.setVisible(false);
-
- settingsPanel.getLoadGameEvent().add(new IListener() {
- @Override
- public void handle() {
- load();
- }
- });
+ createSettingsPanel();
layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(settingsPanel);
@@ -274,6 +264,24 @@ public class View extends JFrame implements IView {
setVisible(true);
}
+ private void createSettingsPanel() {
+ settingsPanel = new SettingsPanel();
+ settingsPanel.setVisible(false);
+
+ settingsPanel.getNetworkGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ networkGameEvent.emit();
+ }
+ });
+ settingsPanel.getLoadGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ load();
+ }
+ });
+ }
+
private void createMainLayer() {
mainLayer = new JPanel();
mainLayer.setLayout(null);
@@ -283,8 +291,8 @@ public class View extends JFrame implements IView {
mainLayer.add(table);
playerPanel = new PlayerPanel();
- playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
- 0, Color.BLACK));
+ playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
+ Color.BLACK));
mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel();
@@ -394,24 +402,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
- Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
- -'J', StoneColor.BLACK), new Position(2.5f, 0));
- Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
- -'R', StoneColor.ORANGE), new Position(3.5f, 0));
- Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.BLUE), new Position(4.5f, 0));
- Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.RED), new Position(5.5f, 0));
- Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.GREEN), new Position(6.5f, 0));
- Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
- -'i', StoneColor.VIOLET), new Position(7.5f, 0));
- Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
- -'k', StoneColor.AQUA), new Position(8.5f, 0));
- Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.GRAY), new Position(9.5f, 0));
- Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
- -'b', StoneColor.BLACK), new Position(10.5f, 0));
+ Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
+ StoneColor.BLACK), new Position(2.5f, 0));
+ Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
+ StoneColor.ORANGE), new Position(3.5f, 0));
+ Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.BLUE), new Position(4.5f, 0));
+ Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.RED), new Position(5.5f, 0));
+ Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.GREEN), new Position(6.5f, 0));
+ Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
+ StoneColor.VIOLET), new Position(7.5f, 0));
+ Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
+ StoneColor.AQUA), new Position(8.5f, 0));
+ Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.GRAY), new Position(9.5f, 0));
+ Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
+ StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1));
@@ -426,9 +434,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1));
- return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
- stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
- stone5, stone6);
+ return Arrays
+ .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
+ stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
}
@Override
@@ -445,8 +453,7 @@ public class View extends JFrame implements IView {
&& type != BottomPanelType.WIN_PANEL && type != null);
if (type == BottomPanelType.START_GAME_PANEL) {
- table.setStoneSets(Collections
- .<Pair<StoneSet, Position>> emptyList());
+ table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}