Show current game settings

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@486 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-06-19 18:31:05 +02:00
parent 2db77addd9
commit 705698670a
5 changed files with 111 additions and 24 deletions

View file

@ -97,6 +97,7 @@ public class GameControl {
* Game gets started by initializing the first Round * Game gets started by initializing the first Round
*/ */
public void startGame() { public void startGame() {
view.getSidePanel().setGameSettings(gameSettings);
startRound(); startRound();
} }

View file

@ -0,0 +1,9 @@
package jrummikub.view;
import jrummikub.model.GameSettings;
public interface ISidePanel {
public void setGameSettings(GameSettings settings);
}

View file

@ -34,6 +34,13 @@ public interface IView {
*/ */
public ITablePanel getTablePanel(); public ITablePanel getTablePanel();
/**
* Returns the side panel
*
* @return the side panel
*/
public ISidePanel getSidePanel();
/** /**
* @return the board where the players hand stones are displayed * @return the board where the players hand stones are displayed
*/ */

View file

@ -24,27 +24,38 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollBar; import javax.swing.JScrollBar;
import javax.swing.JViewport; import javax.swing.JViewport;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder; import javax.swing.border.MatteBorder;
import jrummikub.model.GameSettings;
import jrummikub.view.ISidePanel;
@SuppressWarnings("serial") @SuppressWarnings("serial")
class SidePanel extends JPanel { class SidePanel extends JPanel implements ISidePanel {
RuleInfoPanel ruleInfoPanel; InfoPanel infoPanel;
PlayerListPanel playerListPanel; PlayerListPanel playerListPanel;
BottomScrollPane playerListScrollPane; 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() { public SidePanel() {
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
ruleInfoPanel = new RuleInfoPanel(); infoPanel = new InfoPanel(createRuleInfoPanel());
c.gridx = 0; c.gridx = 0;
c.gridy = 0; c.gridy = 0;
c.weightx = 1; c.weightx = 1;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
ruleInfoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK)); infoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
add(ruleInfoPanel, c); add(infoPanel, c);
playerListPanel = new PlayerListPanel(); playerListPanel = new PlayerListPanel();
c.gridx = 0; 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") @SuppressWarnings("serial")
class BottomScrollPane extends JPanel { class BottomScrollPane extends JPanel {
JComponent content; JComponent content;
JViewport viewport; JViewport viewport;
JScrollBar scrollBar; JScrollBar scrollBar;
boolean scrollToBottom; boolean scrollToBottom;
public BottomScrollPane(JComponent content) { public BottomScrollPane(JComponent content) {
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
@ -81,18 +145,18 @@ class SidePanel extends JPanel {
scrollBar.setBorder(new LineBorder(Color.BLACK, 0)); scrollBar.setBorder(new LineBorder(Color.BLACK, 0));
c.weightx = 0; c.weightx = 0;
add(scrollBar, c); add(scrollBar, c);
ComponentAdapter resizeListener = new ComponentAdapter() { ComponentAdapter resizeListener = new ComponentAdapter() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
onResize(); onResize();
} }
}; };
addComponentListener(resizeListener); addComponentListener(resizeListener);
content.addComponentListener(resizeListener); content.addComponentListener(resizeListener);
scrollBar.addAdjustmentListener(new AdjustmentListener() { scrollBar.addAdjustmentListener(new AdjustmentListener() {
@Override @Override
public void adjustmentValueChanged(AdjustmentEvent arg0) { public void adjustmentValueChanged(AdjustmentEvent arg0) {
@ -101,18 +165,19 @@ class SidePanel extends JPanel {
}); });
scrollToBottom(); scrollToBottom();
} }
public void scrollToBottom() { public void scrollToBottom() {
scrollToBottom = true; scrollToBottom = true;
} }
private void onResize() { private void onResize() {
int oldValue = 0; int oldValue = 0;
if (!scrollToBottom) { if (!scrollToBottom) {
oldValue = scrollBar.getMaximum() - scrollBar.getVisibleAmount() - scrollBar.getValue(); oldValue = scrollBar.getMaximum()
- scrollBar.getVisibleAmount() - scrollBar.getValue();
} }
scrollToBottom = false; scrollToBottom = false;
int max = content.getHeight(); int max = content.getHeight();
int extent = viewport.getHeight(); int extent = viewport.getHeight();
int value = Math.max(0, max - extent - oldValue); int value = Math.max(0, max - extent - oldValue);
@ -120,17 +185,18 @@ class SidePanel extends JPanel {
scrollBar.setValues(value, extent, 0, max); scrollBar.setValues(value, extent, 0, max);
scrollViewport(); scrollViewport();
} }
private void scrollViewport() { private void scrollViewport() {
viewport.setViewPosition(new Point(0, scrollBar.getValue())); viewport.setViewPosition(new Point(0, scrollBar.getValue()));
} }
} }
class RuleInfoPanel extends JPanel { static class InfoPanel extends JPanel {
JLabel ruleInfo; JPanel ruleInfoPanel;
JCheckBox showRules; JCheckBox showRules;
public RuleInfoPanel() { public InfoPanel(JPanel ruleInfo) {
ruleInfoPanel = ruleInfo;
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
showRules = new JCheckBox("Regeln"); showRules = new JCheckBox("Regeln");
@ -147,16 +213,14 @@ class SidePanel extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent arg) { public void actionPerformed(ActionEvent arg) {
boolean selected = showRules.isSelected(); boolean selected = showRules.isSelected();
ruleInfo.setVisible(selected); ruleInfoPanel.setVisible(selected);
showRules.setPressedIcon(selected ? showRules.getIcon() showRules.setPressedIcon(selected ? showRules.getIcon()
: showRules.getSelectedIcon()); : showRules.getSelectedIcon());
} }
}); });
ruleInfo = new JLabel( c.insets = new Insets(4, 8, 4, 8);
"<html><center>All work and no play<br>makes Jack a dull boy"); add(ruleInfoPanel, c);
ruleInfo.setHorizontalAlignment(JLabel.CENTER);
add(ruleInfo, c);
} }
private void setupTriangleIcons(JCheckBox test) { private void setupTriangleIcons(JCheckBox test) {
@ -240,7 +304,7 @@ class SidePanel extends JPanel {
c.weighty = 0; c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
for (int i = 1; i <= 15; i++) { for (int i = 1; i <= 4; i++) {
c.gridx = 0; c.gridx = 0;
c.gridy = i; c.gridy = i;
c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0); c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0);

View file

@ -39,6 +39,7 @@ import jrummikub.view.ILoginPanel;
import jrummikub.view.IPlayerPanel; import jrummikub.view.IPlayerPanel;
import jrummikub.view.IScorePanel; import jrummikub.view.IScorePanel;
import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel;
import jrummikub.view.ISidePanel;
import jrummikub.view.ITablePanel; import jrummikub.view.ITablePanel;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -101,7 +102,12 @@ public class View extends JFrame implements IView {
public ITablePanel getTablePanel() { public ITablePanel getTablePanel() {
return table; return table;
} }
@Override
public ISidePanel getSidePanel() {
return sidePanel;
}
@Override @Override
public IHandPanel getHandPanel() { public IHandPanel getHandPanel() {
return playerPanel.getHandPanel(); return playerPanel.getHandPanel();