From ace7175f1a57f3dc88a861842969e84efacf65ad Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 20 Jun 2011 02:19:47 +0200 Subject: Continued side panel git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@499 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/ISidePanel.java | 5 ++ src/jrummikub/view/impl/SidePanel.java | 96 +++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 25 deletions(-) (limited to 'src/jrummikub/view') diff --git a/src/jrummikub/view/ISidePanel.java b/src/jrummikub/view/ISidePanel.java index 9b3bf43..9efea85 100644 --- a/src/jrummikub/view/ISidePanel.java +++ b/src/jrummikub/view/ISidePanel.java @@ -1,6 +1,9 @@ package jrummikub.view; +import java.util.List; + import jrummikub.model.GameSettings; +import jrummikub.model.IPlayer; public interface ISidePanel { @@ -10,4 +13,6 @@ public interface ISidePanel { void setHeapSize(int size); + void setPlayers(List players); + } \ No newline at end of file diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java index b895701..a4e0e43 100644 --- a/src/jrummikub/view/impl/SidePanel.java +++ b/src/jrummikub/view/impl/SidePanel.java @@ -16,6 +16,9 @@ import java.awt.event.AdjustmentListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import javax.swing.ImageIcon; import javax.swing.JCheckBox; @@ -26,16 +29,19 @@ 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.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.border.MatteBorder; import jrummikub.model.GameSettings; +import jrummikub.model.IPlayer; +import jrummikub.model.Player; +import jrummikub.model.PlayerSettings; import jrummikub.view.ISidePanel; @SuppressWarnings("serial") class SidePanel extends JPanel implements ISidePanel { - //private InfoPanel infoPanel; + // private InfoPanel infoPanel; private PlayerListPanel playerListPanel; private BottomScrollPane playerListScrollPane; private JLabel initialMeldLabel; @@ -52,7 +58,8 @@ class SidePanel extends JPanel implements ISidePanel { GridBagConstraints c = new GridBagConstraints(); - InfoPanel infoPanel = new InfoPanel(createGameInfoPanel(), createRuleInfoPanel()); + InfoPanel infoPanel = new InfoPanel(createGameInfoPanel(), + createRuleInfoPanel()); c.gridx = 0; c.gridy = 0; c.weightx = 1; @@ -83,12 +90,12 @@ 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); @@ -99,11 +106,11 @@ class SidePanel extends JPanel implements ISidePanel { heapBar.setString("leer"); } } - + private JPanel createGameInfoPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); - + GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; @@ -113,24 +120,24 @@ class SidePanel extends JPanel implements ISidePanel { c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; heapBar = new JProgressBar(); - heapBar.setPreferredSize(new Dimension(16,16)); + heapBar.setPreferredSize(new Dimension(16, 16)); panel.add(heapBar, c); - + heapBar.setStringPainted(true); - + return panel; } private JPanel createRuleInfoPanel() { JPanel panel = new JPanel(); - panel.setLayout(new GridBagLayout()); + panel.setLayout(new GridBagLayout()); initialMeldLabel = createRuleLine(panel, "Auslegeschranke", 0); setNumberLabel = createRuleLine(panel, "Steins\u00e4tze", 1); - highestValueLabel = createRuleLine(panel,"Steinwert", 2); + 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; @@ -144,7 +151,7 @@ class SidePanel extends JPanel implements ISidePanel { return panel; } - + private JLabel createRuleLine(JPanel panel, String name, int line) { GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; @@ -247,7 +254,7 @@ class SidePanel extends JPanel implements ISidePanel { c.insets = new Insets(4, 8, 4, 8); add(gameInfoPanel, c); - + showRules = new JCheckBox("Regeln"); showRules.setSelected(true); setupTriangleIcons(showRules); @@ -312,25 +319,47 @@ class SidePanel extends JPanel implements ISidePanel { class PlayerListItem extends JPanel { JLabel playerName; + JLabel playerStatus; + JLabel playerColor; + - public PlayerListItem() { + public PlayerListItem(IPlayer player) { setLayout(new GridBagLayout()); + setBorder(new EmptyBorder(0, 4, 0, 4)); + PlayerSettings settings = player.getPlayerSettings(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; + c.gridheight = 2; + c.weighty = 1; + c.insets = new Insets(4, 4, 4, 4); + playerColor = new JLabel(ImageUtil.createColorIcon( + settings.getColor(), 12, 1)); + add(playerColor, c); + + c.gridx = 1; + c.gridy = 0; + c.gridheight = 1; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; - c.insets = new Insets(5, 5, 5, 5); + c.insets = new Insets(2,2,2,2); - playerName = new JLabel("Horst
> 9000 Steine"); + playerName = new JLabel(settings.getName()); + playerName.putClientProperty("html.disable", Boolean.TRUE); add(playerName, c); + + c.gridx = 1; + c.gridy = 1; + playerStatus = new JLabel(player.getLaidOut() ? "rausgekommen" : "nicht rausgekommen"); + add(playerStatus, c); } } class PlayerListPanel extends JPanel { JPanel startSpacer; + List listItems = new ArrayList(); public PlayerListPanel() { setBackground(Color.GRAY); @@ -346,14 +375,25 @@ class SidePanel extends JPanel implements ISidePanel { c.weighty = 1; c.fill = GridBagConstraints.BOTH; add(startSpacer, c); - c.weighty = 0; - c.fill = GridBagConstraints.HORIZONTAL; - for (int i = 1; i <= 4; i++) { - c.gridx = 0; - c.gridy = i; - c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0); - add(new PlayerListItem(), c); + } + + public void setPlayers(List players) { + for (PlayerListItem item : listItems) { + remove(item); + } + listItems.clear(); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.weightx = 1; + c.fill = GridBagConstraints.HORIZONTAL; + for (IPlayer player : players) { + c.gridy++; + c.insets = new Insets(c.gridy == 1 ? 0 : 1, 0, 0, 0); + PlayerListItem item = new PlayerListItem(player); + listItems.add(item); + add(item, c); } } @@ -364,4 +404,10 @@ class SidePanel extends JPanel implements ISidePanel { } } + @Override + public void setPlayers(List players) { + playerListPanel.setPlayers(players); + + } + } -- cgit v1.2.3