summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/ApplicationControl.java42
-rw-r--r--src/jrummikub/control/SettingsControl.java54
-rw-r--r--src/jrummikub/view/ISettingsPanel.java36
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java98
4 files changed, 175 insertions, 55 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index b3d432c..8e09853 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -15,7 +15,7 @@ public class ApplicationControl {
* Creates a new application control
*
* @param view
- * the view to use
+ * the view to use
*/
public ApplicationControl(IView view) {
this.view = view;
@@ -25,39 +25,17 @@ public class ApplicationControl {
* Starts the application by showing the game settings dialog panel
*/
public void startApplication() {
- view.getSettingsPanel().getSettingsChangeEvent()
- .add(new IListener1<GameSettings>() {
- @Override
- public void handle(GameSettings settings) {
- checkSettings(settings);
- }
- });
- view.getSettingsPanel().getStartGameEvent()
- .add(new IListener1<GameSettings>() {
- @Override
- public void handle(GameSettings settings) {
- startGame(settings);
- }
- });
+ SettingsControl settingsControl = new SettingsControl(view);
+ settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
- view.showSettingsPanel(true);
- }
-
- private boolean checkSettings(GameSettings settings) {
- // TODO Check
- // TODO Show error
+ @Override
+ public void handle(GameSettings settings) {
+ GameControl gameControl = new GameControl(settings, view);
+ gameControl.startGame();
- return true;
+ }
+ });
+ settingsControl.startSettings();
}
- private void startGame(GameSettings settings) {
- if (!checkSettings(settings)) {
- return;
- }
-
- view.showSettingsPanel(false);
-
- GameControl gameControl = new GameControl(settings, view);
- gameControl.startGame();
- }
}
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
new file mode 100644
index 0000000..7b96e77
--- /dev/null
+++ b/src/jrummikub/control/SettingsControl.java
@@ -0,0 +1,54 @@
+package jrummikub.control;
+
+import jrummikub.model.GameSettings;
+import jrummikub.util.Event1;
+import jrummikub.util.IEvent1;
+import jrummikub.util.IListener1;
+import jrummikub.view.IView;
+
+public class SettingsControl {
+ private IView view;
+ private Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
+
+ public SettingsControl(IView view) {
+ this.view = view;
+ }
+
+ public IEvent1<GameSettings> getStartGameEvent() {
+ return startGameEvent;
+ }
+
+ public void startSettings() {
+ /*
+ * view.getSettingsPanel().getSettingsChangeEvent() .add(new
+ * IListener1<GameSettings>() {
+ *
+ * @Override public void handle(GameSettings settings) {
+ * checkSettings(settings); } });
+ * view.getSettingsPanel().getStartGameEvent() .add(new
+ * IListener1<GameSettings>() {
+ *
+ * @Override public void handle(GameSettings settings) {
+ * startGame(settings); } });
+ */
+
+ view.showSettingsPanel(true);
+ }
+
+ private boolean checkSettings(GameSettings settings) {
+ // TODO Check
+ // TODO Show error
+
+ return true;
+ }
+
+ private void startGame(GameSettings settings) {
+ if (!checkSettings(settings)) {
+ return;
+ }
+
+ view.showSettingsPanel(false);
+
+ startGameEvent.emit(settings);
+ }
+}
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 4437f58..17830e5 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -1,24 +1,44 @@
package jrummikub.view;
+import java.awt.Color;
+
import jrummikub.model.GameSettings;
+import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
+import jrummikub.util.IEvent2;
/**
* The panel for the game setup
*/
public interface ISettingsPanel {
- /**
- * The settings change event is emitted whenever the user has changed a game
- * settings without starting the game
- *
- * @return the event
- */
- public IEvent1<GameSettings> getSettingsChangeEvent();
+ public IEvent getAddPlayerEvent();
+
+ public IEvent1<Integer> getRemovePlayerEvent();
+
+ public IEvent2<Integer, Color> getChangePlayerColorEvent();
+
+ public IEvent2<Integer, String> getChangePlayerNameEvent();
+
+ public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
/**
* the start game event is emitted when the user wants to start the game
*
* @return the event
*/
- public IEvent1<GameSettings> getStartGameEvent();
+ public IEvent getStartGameEvent();
+
+ public void setError(SettingsError error);
+
+ public void enableStartGameButton(boolean enable);
+
+ public void enableAddPlayerButton(boolean enable);
+
+ public void enableRemovePlayerButtons(boolean enable);
+
+ public void setGameSettings(GameSettings gameSettings);
+
+ public enum SettingsError {
+ NO_ERROR, DUPLICATE_PLAYER_NAME, NO_PLAYER_NAME
+ }
} \ No newline at end of file
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 7a9347c..03cfd4c 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -32,7 +32,9 @@ import javax.swing.event.DocumentListener;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.util.Event1;
+import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
+import jrummikub.util.IEvent2;
import jrummikub.view.ISettingsPanel;
@SuppressWarnings("serial")
@@ -66,15 +68,13 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event1<GameSettings> settingsChangeEvent = new Event1<GameSettings>();
private Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
- @Override
- public IEvent1<GameSettings> getSettingsChangeEvent() {
- return settingsChangeEvent;
- }
-
- @Override
- public IEvent1<GameSettings> getStartGameEvent() {
- return startGameEvent;
- }
+ /*
+ * @Override public IEvent1<GameSettings> getSettingsChangeEvent() { return
+ * settingsChangeEvent; }
+ *
+ * @Override public IEvent1<GameSettings> getStartGameEvent() { return
+ * startGameEvent; }
+ */
private void addPlayerSettings() {
// Find unused player name
@@ -104,7 +104,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
break;
}
- PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num, color);
+ PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num,
+ color);
playerSettingsPanels.add(panel);
playerSettingsViewport.add(panel,
playerSettingsViewport.getComponentCount() - 1);
@@ -130,7 +131,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
playerSettingsViewport.add(addPlayerPanel);
JButton addPlayerButton = new JButton("+");
- addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
+ addPlayerButton
+ .setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
addPlayerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -180,8 +182,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
});
add(startButton, c);
- setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
- 10, 10, 10, 10)));
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
+ new EmptyBorder(10, 10, 10, 10)));
}
private class PlayerSettingsPanel extends JPanel {
@@ -200,8 +202,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void updateColor() {
- colorButton
- .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
+ colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(),
+ 16, 2));
}
private void setName() {
@@ -333,4 +335,70 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
}
}
+
+ @Override
+ public IEvent getAddPlayerEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEvent1<Integer> getRemovePlayerEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEvent2<Integer, Color> getChangePlayerColorEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEvent2<Integer, String> getChangePlayerNameEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEvent1<Integer> getChangeInitialMeldThresholdEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setError(SettingsError error) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void enableStartGameButton(boolean enable) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void enableAddPlayerButton(boolean enable) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void enableRemovePlayerButtons(boolean enable) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IEvent getStartGameEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setGameSettings(GameSettings gameSettings) {
+ // TODO Auto-generated method stub
+
+ }
}