summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-19 18:31:05 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-19 18:31:05 +0200
commit705698670a7a5f57a2ad1e44c8e1240ede49aa06 (patch)
treec3b737a132ca8e9d845c0b5874db774fee2c52e2 /src/jrummikub
parent2db77addd9082e33dda6c4ba5e957a6d7c6fa877 (diff)
downloadJRummikub-705698670a7a5f57a2ad1e44c8e1240ede49aa06.tar
JRummikub-705698670a7a5f57a2ad1e44c8e1240ede49aa06.zip
Show current game settings
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@486 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/GameControl.java1
-rw-r--r--src/jrummikub/view/ISidePanel.java9
-rw-r--r--src/jrummikub/view/IView.java7
-rw-r--r--src/jrummikub/view/impl/SidePanel.java110
-rw-r--r--src/jrummikub/view/impl/View.java8
5 files changed, 111 insertions, 24 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index d52b4ef..7149464 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -97,6 +97,7 @@ public class GameControl {
* Game gets started by initializing the first Round
*/
public void startGame() {
+ view.getSidePanel().setGameSettings(gameSettings);
startRound();
}
diff --git a/src/jrummikub/view/ISidePanel.java b/src/jrummikub/view/ISidePanel.java
new file mode 100644
index 0000000..6b55a1a
--- /dev/null
+++ b/src/jrummikub/view/ISidePanel.java
@@ -0,0 +1,9 @@
+package jrummikub.view;
+
+import jrummikub.model.GameSettings;
+
+public interface ISidePanel {
+
+ public void setGameSettings(GameSettings settings);
+
+} \ No newline at end of file
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 0074b8d..00e286d 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -35,6 +35,13 @@ public interface IView {
public ITablePanel getTablePanel();
/**
+ * Returns the side panel
+ *
+ * @return the side panel
+ */
+ public ISidePanel getSidePanel();
+
+ /**
* @return the board where the players hand stones are displayed
*/
public IHandPanel getHandPanel();
diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java
index 3b7c2c9..fd0d376 100644
--- a/src/jrummikub/view/impl/SidePanel.java
+++ b/src/jrummikub/view/impl/SidePanel.java
@@ -24,27 +24,38 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JViewport;
+import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
+import jrummikub.model.GameSettings;
+import jrummikub.view.ISidePanel;
+
@SuppressWarnings("serial")
-class SidePanel extends JPanel {
- RuleInfoPanel ruleInfoPanel;
+class SidePanel extends JPanel implements ISidePanel {
+ InfoPanel infoPanel;
PlayerListPanel playerListPanel;
BottomScrollPane playerListScrollPane;
+ private JLabel initialMeldLabel;
+ private JLabel setNumberLabel;
+ private JLabel highestValueLabel;
+ private JLabel handStonesLabel;
+ private JLabel jokerLabel;
+ private JLabel noLimitsLabel;
+ private JLabel colorLabel;
public SidePanel() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
- ruleInfoPanel = new RuleInfoPanel();
+ infoPanel = new InfoPanel(createRuleInfoPanel());
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.fill = GridBagConstraints.BOTH;
- ruleInfoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
- add(ruleInfoPanel, c);
+ infoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
+ add(infoPanel, c);
playerListPanel = new PlayerListPanel();
c.gridx = 0;
@@ -61,12 +72,65 @@ class SidePanel extends JPanel {
}
+ @Override
+ public void setGameSettings(GameSettings settings) {
+ initialMeldLabel.setText("" + settings.getInitialMeldThreshold());
+ setNumberLabel.setText("" + settings.getStoneSetNumber());
+ highestValueLabel.setText("1 - " + settings.getHighestValue());
+ handStonesLabel.setText("" + settings.getNumberOfStonesDealt());
+ jokerLabel.setText("" + settings.getJokerNumber());
+ colorLabel.setText("" + settings.getStoneColors().size());
+ noLimitsLabel.setVisible(settings.isNoLimits());
+ }
+
+ private JPanel createRuleInfoPanel() {
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridBagLayout());
+ initialMeldLabel = createRuleLine(panel, "Auslegeschranke", 0);
+ setNumberLabel = createRuleLine(panel, "Steinsätze", 1);
+ highestValueLabel = createRuleLine(panel,"Steinwert", 2);
+ handStonesLabel = createRuleLine(panel, "Startsteine", 3);
+ jokerLabel = createRuleLine(panel, "Joker", 4);
+ colorLabel = createRuleLine(panel, "Farben", 5);
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 6;
+ c.gridwidth = 2;
+ c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.CENTER;
+ noLimitsLabel = new JLabel("No Limits");
+ noLimitsLabel.setHorizontalAlignment(SwingConstants.CENTER);
+ panel.add(noLimitsLabel, c);
+
+ return panel;
+ }
+
+ private JLabel createRuleLine(JPanel panel, String name, int line) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = line;
+ c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+ panel.add(new JLabel(name + ": "), c);
+ JLabel label = new JLabel("");
+ label.setHorizontalAlignment(SwingConstants.RIGHT);
+ c.weightx = 0;
+ c.gridx = 1;
+ c.anchor = GridBagConstraints.EAST;
+ panel.add(label, c);
+ return label;
+ }
+
@SuppressWarnings("serial")
class BottomScrollPane extends JPanel {
JComponent content;
JViewport viewport;
JScrollBar scrollBar;
boolean scrollToBottom;
+
public BottomScrollPane(JComponent content) {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -81,18 +145,18 @@ class SidePanel extends JPanel {
scrollBar.setBorder(new LineBorder(Color.BLACK, 0));
c.weightx = 0;
add(scrollBar, c);
-
+
ComponentAdapter resizeListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
onResize();
}
};
-
+
addComponentListener(resizeListener);
-
+
content.addComponentListener(resizeListener);
-
+
scrollBar.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent arg0) {
@@ -101,18 +165,19 @@ class SidePanel extends JPanel {
});
scrollToBottom();
}
-
+
public void scrollToBottom() {
scrollToBottom = true;
}
-
+
private void onResize() {
int oldValue = 0;
if (!scrollToBottom) {
- oldValue = scrollBar.getMaximum() - scrollBar.getVisibleAmount() - scrollBar.getValue();
+ oldValue = scrollBar.getMaximum()
+ - scrollBar.getVisibleAmount() - scrollBar.getValue();
}
scrollToBottom = false;
-
+
int max = content.getHeight();
int extent = viewport.getHeight();
int value = Math.max(0, max - extent - oldValue);
@@ -120,17 +185,18 @@ class SidePanel extends JPanel {
scrollBar.setValues(value, extent, 0, max);
scrollViewport();
}
-
+
private void scrollViewport() {
viewport.setViewPosition(new Point(0, scrollBar.getValue()));
}
}
- class RuleInfoPanel extends JPanel {
- JLabel ruleInfo;
+ static class InfoPanel extends JPanel {
+ JPanel ruleInfoPanel;
JCheckBox showRules;
- public RuleInfoPanel() {
+ public InfoPanel(JPanel ruleInfo) {
+ ruleInfoPanel = ruleInfo;
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
showRules = new JCheckBox("Regeln");
@@ -147,16 +213,14 @@ class SidePanel extends JPanel {
@Override
public void actionPerformed(ActionEvent arg) {
boolean selected = showRules.isSelected();
- ruleInfo.setVisible(selected);
+ ruleInfoPanel.setVisible(selected);
showRules.setPressedIcon(selected ? showRules.getIcon()
: showRules.getSelectedIcon());
}
});
- ruleInfo = new JLabel(
- "<html><center>All work and no play<br>makes Jack a dull boy");
- ruleInfo.setHorizontalAlignment(JLabel.CENTER);
- add(ruleInfo, c);
+ c.insets = new Insets(4, 8, 4, 8);
+ add(ruleInfoPanel, c);
}
private void setupTriangleIcons(JCheckBox test) {
@@ -240,7 +304,7 @@ class SidePanel extends JPanel {
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
- for (int i = 1; i <= 15; i++) {
+ for (int i = 1; i <= 4; i++) {
c.gridx = 0;
c.gridy = i;
c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0);
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 2bfee8e..5755c73 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -39,6 +39,7 @@ import jrummikub.view.ILoginPanel;
import jrummikub.view.IPlayerPanel;
import jrummikub.view.IScorePanel;
import jrummikub.view.ISettingsPanel;
+import jrummikub.view.ISidePanel;
import jrummikub.view.ITablePanel;
import jrummikub.view.IView;
@@ -101,7 +102,12 @@ public class View extends JFrame implements IView {
public ITablePanel getTablePanel() {
return table;
}
-
+
+ @Override
+ public ISidePanel getSidePanel() {
+ return sidePanel;
+ }
+
@Override
public IHandPanel getHandPanel() {
return playerPanel.getHandPanel();