From ec54bde90aad27a5ec4bc7bfec6cef732c7c3348 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sun, 19 Jun 2011 23:42:19 +0200 Subject: Show heap size in side panel git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@497 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/view/MockSidePanel.java | 12 ++++++ src/jrummikub/control/RoundControl.java | 5 +++ src/jrummikub/view/ISidePanel.java | 4 ++ src/jrummikub/view/impl/SidePanel.java | 65 ++++++++++++++++++++++++++++----- src/jrummikub/view/impl/View.java | 57 ++++++++++++++++------------- 5 files changed, 107 insertions(+), 36 deletions(-) diff --git a/mock/jrummikub/view/MockSidePanel.java b/mock/jrummikub/view/MockSidePanel.java index af103a6..1755e65 100644 --- a/mock/jrummikub/view/MockSidePanel.java +++ b/mock/jrummikub/view/MockSidePanel.java @@ -13,4 +13,16 @@ public class MockSidePanel implements ISidePanel { } + @Override + public void setHeapCapacity(int capacity) { + // TODO Auto-generated method stub + + } + + @Override + public void setHeapSize(int size) { + // TODO Auto-generated method stub + + } + } diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index f209f3e..285980a 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -203,12 +203,15 @@ public class RoundControl { } void deal() { + view.getSidePanel().setHeapCapacity(roundState.getGameHeap().getSize()); for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); } } + view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); + } private boolean laidOutValidPoints() { @@ -392,6 +395,8 @@ public class RoundControl { hand.drop(roundState.getGameHeap().drawStone(), new Position( Hand.WIDTH - 1, rowCount - 1)); } + + view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); } private void dealStone() { diff --git a/src/jrummikub/view/ISidePanel.java b/src/jrummikub/view/ISidePanel.java index 6b55a1a..9b3bf43 100644 --- a/src/jrummikub/view/ISidePanel.java +++ b/src/jrummikub/view/ISidePanel.java @@ -6,4 +6,8 @@ public interface ISidePanel { public void setGameSettings(GameSettings settings); + void setHeapCapacity(int capacity); + + void setHeapSize(int size); + } \ No newline at end of file diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java index 9e83c91..b895701 100644 --- a/src/jrummikub/view/impl/SidePanel.java +++ b/src/jrummikub/view/impl/SidePanel.java @@ -22,9 +22,11 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JProgressBar; import javax.swing.JScrollBar; import javax.swing.JViewport; import javax.swing.SwingConstants; +import javax.swing.border.CompoundBorder; import javax.swing.border.LineBorder; import javax.swing.border.MatteBorder; @@ -33,9 +35,9 @@ import jrummikub.view.ISidePanel; @SuppressWarnings("serial") class SidePanel extends JPanel implements ISidePanel { - InfoPanel infoPanel; - PlayerListPanel playerListPanel; - BottomScrollPane playerListScrollPane; + //private InfoPanel infoPanel; + private PlayerListPanel playerListPanel; + private BottomScrollPane playerListScrollPane; private JLabel initialMeldLabel; private JLabel setNumberLabel; private JLabel highestValueLabel; @@ -43,18 +45,19 @@ class SidePanel extends JPanel implements ISidePanel { private JLabel jokerLabel; private JLabel noLimitsLabel; private JLabel colorLabel; + private JProgressBar heapBar; public SidePanel() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); - infoPanel = new InfoPanel(createRuleInfoPanel()); + InfoPanel infoPanel = new InfoPanel(createGameInfoPanel(), createRuleInfoPanel()); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; - infoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK)); + infoPanel.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY)); add(infoPanel, c); playerListPanel = new PlayerListPanel(); @@ -65,8 +68,6 @@ class SidePanel extends JPanel implements ISidePanel { c.fill = GridBagConstraints.BOTH; playerListScrollPane = new BottomScrollPane(playerListPanel); - playerListScrollPane - .setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK)); add(playerListScrollPane, c); @@ -82,6 +83,43 @@ class SidePanel extends JPanel implements ISidePanel { colorLabel.setText("" + settings.getStoneColors().size()); noLimitsLabel.setVisible(settings.isNoLimits()); } + + @Override + public void setHeapCapacity(int capacity) { + heapBar.setMaximum(capacity); + } + + @Override + public void setHeapSize(int size) { + heapBar.setValue(size); + if (size > 0) { + heapBar.setString("" + size); + } else { + heapBar.setIndeterminate(true); + heapBar.setString("leer"); + } + } + + private JPanel createGameInfoPanel() { + JPanel panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.WEST; + panel.add(new JLabel("Stapel: "), c); + c.gridx = 1; + c.weightx = 1; + c.fill = GridBagConstraints.HORIZONTAL; + heapBar = new JProgressBar(); + heapBar.setPreferredSize(new Dimension(16,16)); + panel.add(heapBar, c); + + heapBar.setStringPainted(true); + + return panel; + } private JPanel createRuleInfoPanel() { JPanel panel = new JPanel(); @@ -193,18 +231,25 @@ class SidePanel extends JPanel implements ISidePanel { static class InfoPanel extends JPanel { JPanel ruleInfoPanel; + JPanel gameInfoPanel; JCheckBox showRules; + JProgressBar heapBar; - public InfoPanel(JPanel ruleInfo) { + public InfoPanel(JPanel gameInfo, JPanel ruleInfo) { ruleInfoPanel = ruleInfo; + gameInfoPanel = gameInfo; setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); - showRules = new JCheckBox("Regeln"); - showRules.setSelected(true); c.gridx = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; + + c.insets = new Insets(4, 8, 4, 8); + add(gameInfoPanel, c); + + showRules = new JCheckBox("Regeln"); + showRules.setSelected(true); setupTriangleIcons(showRules); c.insets = new Insets(0, 4, 0, 4); add(showRules, c); diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 042421f..b367b65 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -22,6 +22,7 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.border.CompoundBorder; import javax.swing.border.MatteBorder; import javax.swing.filechooser.FileNameExtensionFilter; @@ -186,7 +187,8 @@ public class View extends JFrame implements IView { showSettingsPanel(false); showLoginPanel(false); showGameListPanel(false); - getHandPanel().setStones(Collections.> emptyList()); + getHandPanel().setStones( + Collections.> emptyList()); getTablePanel().setStoneSets( Collections.> emptyList()); setSelectedStones(Collections. emptyList()); @@ -366,7 +368,8 @@ public class View extends JFrame implements IView { table = new TablePanel(); mainLayer.add(table); - table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.BLACK)); + table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, + Color.BLACK)); playerPanel = new PlayerPanel(); mainLayer.add(playerPanel); @@ -390,8 +393,9 @@ public class View extends JFrame implements IView { sidePanel = new SidePanel(); sidePanel.setVisible(false); mainLayer.add(sidePanel); - sidePanel.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, - Color.BLACK)); + sidePanel.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, + Color.BLACK), new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, + Color.GRAY))); } @Override @@ -556,24 +560,24 @@ public class View extends JFrame implements IView { @SuppressWarnings("unchecked") private List> createDecorationStones() { - Pair stoneJ = new Pair(new Stone(-'J', - StoneColor.BLACK), new Position(2.5f, 0)); - Pair stoneR = new Pair(new Stone(-'R', - StoneColor.ORANGE), new Position(3.5f, 0)); - Pair stoneu1 = new Pair(new Stone(-'u', - StoneColor.BLUE), new Position(4.5f, 0)); - Pair stonem1 = new Pair(new Stone(-'m', - StoneColor.RED), new Position(5.5f, 0)); - Pair stonem2 = new Pair(new Stone(-'m', - StoneColor.GREEN), new Position(6.5f, 0)); - Pair stonei = new Pair(new Stone(-'i', - StoneColor.VIOLET), new Position(7.5f, 0)); - Pair stonek = new Pair(new Stone(-'k', - StoneColor.AQUA), new Position(8.5f, 0)); - Pair stoneu2 = new Pair(new Stone(-'u', - StoneColor.GRAY), new Position(9.5f, 0)); - Pair stoneb = new Pair(new Stone(-'b', - StoneColor.BLACK), new Position(10.5f, 0)); + Pair stoneJ = new Pair(new Stone( + -'J', StoneColor.BLACK), new Position(2.5f, 0)); + Pair stoneR = new Pair(new Stone( + -'R', StoneColor.ORANGE), new Position(3.5f, 0)); + Pair stoneu1 = new Pair(new Stone( + -'u', StoneColor.BLUE), new Position(4.5f, 0)); + Pair stonem1 = new Pair(new Stone( + -'m', StoneColor.RED), new Position(5.5f, 0)); + Pair stonem2 = new Pair(new Stone( + -'m', StoneColor.GREEN), new Position(6.5f, 0)); + Pair stonei = new Pair(new Stone( + -'i', StoneColor.VIOLET), new Position(7.5f, 0)); + Pair stonek = new Pair(new Stone( + -'k', StoneColor.AQUA), new Position(8.5f, 0)); + Pair stoneu2 = new Pair(new Stone( + -'u', StoneColor.GRAY), new Position(9.5f, 0)); + Pair stoneb = new Pair(new Stone( + -'b', StoneColor.BLACK), new Position(10.5f, 0)); Pair stone1 = new Pair(new Stone( StoneColor.RED), new Position(2, 1)); @@ -588,9 +592,9 @@ public class View extends JFrame implements IView { Pair stone6 = new Pair(new Stone( StoneColor.BLACK), new Position(11, 1)); - return Arrays - .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek, - stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6); + return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, + stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4, + stone5, stone6); } @Override @@ -610,7 +614,8 @@ public class View extends JFrame implements IView { && type != BottomPanelType.WIN_PANEL && type != null); if (type == BottomPanelType.START_GAME_PANEL) { - table.setStoneSets(Collections.> emptyList()); + table.setStoneSets(Collections + .> emptyList()); playerPanel.getHandPanel().setStones(createDecorationStones()); } -- cgit v1.2.3