summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/ISettingsPanel.java2
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java162
-rw-r--r--src/jrummikub/view/impl/StonePainter.java14
3 files changed, 118 insertions, 60 deletions
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 1d030fe..fbe1932 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -158,6 +158,8 @@ public interface ISettingsPanel {
NO_PLAYER_NAME_ERROR,
/** More Stones than present would be dealed */
NOT_ENOUGH_STONES_ERROR,
+ /** Less than 3 colors are selected */
+ NOT_ENOUGH_COLORS_ERROR,
// warnings
/** threshold higher 100 */
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 95089a3..3f577cc 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -16,7 +16,10 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.swing.Box;
@@ -32,6 +35,7 @@ import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
+import javax.swing.JToggleButton;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
@@ -72,6 +76,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JSpinner numberOfStonesDealtSpinner;
private JSpinner jokerNumberSpinner;
+ private JPanel colorSelectionPanel;
+ private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
+
private Event startGameEvent = new Event();
private Event addPlayerEvent = new Event();
private Event1<Integer> removePlayerEvent = new Event1<Integer>();
@@ -138,32 +145,37 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public void setError(SettingsError error) {
switch (error) {
- case NO_ERROR:
- errorMessageLabel.setText(" ");
- break;
- case DUPLICATE_PLAYER_NAME_ERROR:
- errorMessageLabel
- .setText("Jeder Spielername darf nur einmal verwendet werden.");
- errorMessageLabel.setForeground(Color.RED);
- break;
- case NO_PLAYER_NAME_ERROR:
- errorMessageLabel.setText("Jeder Spieler muss einen Namen haben.");
- errorMessageLabel.setForeground(Color.RED);
- break;
- case NOT_ENOUGH_STONES_ERROR:
- errorMessageLabel
- .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl.");
- errorMessageLabel.setForeground(Color.RED);
- break;
- case COMPUTER_PLAYERS_ONLY_WARNING:
- errorMessageLabel.setText("Es gibt keinen menschlichen Spieler.");
- errorMessageLabel.setForeground(Color.ORANGE.darker());
- break;
- case TOO_HIGH_THRESHOLD_WARNING:
- errorMessageLabel
- .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch");
- errorMessageLabel.setForeground(Color.ORANGE.darker());
- break;
+ case NO_ERROR:
+ errorMessageLabel.setText(" ");
+ break;
+ case DUPLICATE_PLAYER_NAME_ERROR:
+ errorMessageLabel
+ .setText("Jeder Spielername darf nur einmal verwendet werden.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case NO_PLAYER_NAME_ERROR:
+ errorMessageLabel.setText("Jeder Spieler muss einen Namen haben.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case NOT_ENOUGH_STONES_ERROR:
+ errorMessageLabel
+ .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case NOT_ENOUGH_COLORS_ERROR:
+ errorMessageLabel
+ .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case COMPUTER_PLAYERS_ONLY_WARNING:
+ errorMessageLabel.setText("Es gibt keinen menschlichen Spieler.");
+ errorMessageLabel.setForeground(Color.ORANGE.darker());
+ break;
+ case TOO_HIGH_THRESHOLD_WARNING:
+ errorMessageLabel
+ .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch");
+ errorMessageLabel.setForeground(Color.ORANGE.darker());
+ break;
}
}
@@ -188,8 +200,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public void setGameSettings(GameSettings gameSettings) {
- while (playerSettingsPanels.size() > gameSettings.getPlayerList()
- .size()) {
+ while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) {
removePlayerSettingsPanel();
}
@@ -197,13 +208,18 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i));
}
- initialMeldThresholdSpinner.setValue(gameSettings
- .getInitialMeldThreshold());
+ initialMeldThresholdSpinner
+ .setValue(gameSettings.getInitialMeldThreshold());
stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber());
highestValueSpinner.setValue(gameSettings.getHighestValue());
numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
+ for (StoneColor color : StoneColor.values()) {
+ colorButtons.get(color).getModel()
+ .setSelected(gameSettings.getStoneColors().contains(color));
+ }
+
playerSettingsViewport.revalidate();
}
@@ -223,8 +239,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void removePlayerSettingsPanel() {
- PlayerSettingsPanel p = playerSettingsPanels
- .remove(playerSettingsPanels.size() - 1);
+ PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels
+ .size() - 1);
playerSettingsViewport.remove(p);
}
@@ -246,8 +262,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
playerSettingsViewport.add(addPlayerPanel);
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) {
@@ -284,18 +299,62 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeNumberOfStonesDealtEvent);
makeOptionLabel(4, "Jokeranzahl:");
- jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1,
- changeJokerNumberEvent);
+ jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent);
+
+ makeOptionLabel(5, "Steinfarben:");
+ createColorSelectionPanel(5);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 1;
- c.gridy = 5;
+ c.gridy = 6;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
optionsPanel.add(makeFiller(), c);
}
+ private void createColorSelectionPanel(int row) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.anchor = GridBagConstraints.WEST;
+ c.gridx = 1;
+ c.gridy = row;
+
+ colorSelectionPanel = new JPanel();
+ optionsPanel.add(colorSelectionPanel, c);
+
+ for (StoneColor color : StoneColor.values()) {
+ createColorButton(color);
+ }
+ }
+
+ private void createColorButton(final StoneColor color) {
+ JToggleButton button = new JToggleButton(ImageUtil.createColorIcon(
+ StonePainter.getColor(color), 12, 1));
+ button.addChangeListener(new ChangeListener() {
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ emitColorChangeEvent();
+ }
+ });
+
+ colorSelectionPanel.add(button);
+
+ colorButtons.put(color, button);
+ }
+
+ private void emitColorChangeEvent() {
+ Set<StoneColor> colors = new HashSet<StoneColor>();
+
+ for (StoneColor color : StoneColor.values()) {
+ if (colorButtons.get(color).getModel().isSelected()) {
+ colors.add(color);
+ }
+ }
+
+ changeStoneColorsEvent.emit(colors);
+ }
+
private JSpinner makeOptionSpinner(int row, int min, int max, int step,
final Event1<Integer> targetEvent) {
GridBagConstraints c = new GridBagConstraints();
@@ -305,8 +364,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.insets = new Insets(2, 2, 2, 2);
final JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(min, min, max, step));
- spinner.setPreferredSize(new Dimension(60,
- spinner.getMinimumSize().height));
+ spinner
+ .setPreferredSize(new Dimension(60, spinner.getMinimumSize().height));
spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
@@ -359,8 +418,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 {
@@ -380,8 +439,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
if (index != playerType.getSelectedIndex()) {
playerType.setSelectedIndex(index);
}
- colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(),
- 16, 2));
+ colorButton
+ .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
}
public void enableRemoveButton(boolean enable) {
@@ -429,8 +488,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.gridy = 0;
add(colorButton, c);
- nameField.getDocument().addDocumentListener(
- new NameChangeListener());
+ nameField.getDocument().addDocumentListener(new NameChangeListener());
c2.gridy = 0;
c2.weightx = 1;
c2.fill = GridBagConstraints.HORIZONTAL;
@@ -463,9 +521,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) {
- preferredSize.setSize(
- preferredSize.width,
- Math.max(preferredSize.height,
+ preferredSize
+ .setSize(preferredSize.width, Math.max(preferredSize.height,
component.getPreferredSize().height));
}
return preferredSize;
@@ -475,9 +532,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getMaximumSize() {
Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) {
- preferredSize.setSize(
- Integer.MAX_VALUE,
- Math.max(preferredSize.height,
+ preferredSize
+ .setSize(Integer.MAX_VALUE, Math.max(preferredSize.height,
component.getPreferredSize().height));
}
return preferredSize;
@@ -492,8 +548,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void changeType() {
- changePlayerTypeEvent.emit(playerNumber, TurnControlFactory.Type
- .values()[playerType.getSelectedIndex()]);
+ changePlayerTypeEvent.emit(playerNumber,
+ TurnControlFactory.Type.values()[playerType.getSelectedIndex()]);
}
private void remove() {
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index 572ba76..e2dae24 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -71,24 +71,24 @@ class StonePainter {
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
}
- private static Color getColor(StoneColor color) {
+ public static Color getColor(StoneColor color) {
switch (color) {
case BLACK:
- return new Color(0.15f, 0.15f, 0.15f);
+ return new Color(0.0f, 0.0f, 0.0f);
case BLUE:
return new Color(0.0f, 0.0f, 1.0f);
case ORANGE:
return new Color(1.0f, 0.4f, 0.0f);
case RED:
return new Color(0.9f, 0.0f, 0.25f);
- case BROWN:
- return new Color(0.5f, 0.25f, 0.0f);
+ case AQUA:
+ return new Color(0.0f, 0.85f, 0.75f);
case GREEN:
- return new Color(0.0f, 0.75f, 0.0f);
+ return new Color(0.0f, 0.65f, 0.0f);
case VIOLET:
return new Color(0.75f, 0.325f, 0.75f);
- case WHITE:
- return new Color(1.0f, 1.0f, 1.0f);
+ case GRAY:
+ return new Color(0.5f, 0.5f, 0.5f);
}
return null;