diff options
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r-- | src/jrummikub/view/impl/SidePanel.java | 110 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 8 |
2 files changed, 94 insertions, 24 deletions
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(); |