From d9b651828aedbd9eb80f534842356d5200c644ee Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 29 May 2011 22:12:58 +0200 Subject: Make score panel look nice git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@316 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/ScorePanel.java | 82 +++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/jrummikub/view/impl/ScorePanel.java b/src/jrummikub/view/impl/ScorePanel.java index e926294..5610368 100644 --- a/src/jrummikub/view/impl/ScorePanel.java +++ b/src/jrummikub/view/impl/ScorePanel.java @@ -1,12 +1,16 @@ package jrummikub.view.impl; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.Insets; import java.util.Iterator; +import javax.swing.Box; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.border.LineBorder; @@ -20,9 +24,26 @@ class ScorePanel extends JPanel implements IScorePanel { private Iterable scores; private Score accumulatedScore; + private JScrollPane scrollPane; + private JPanel innerPanel; + public ScorePanel() { - setLayout(new GridBagLayout()); setBorder(new LineBorder(Color.BLACK)); + setLayout(new BorderLayout(0, 5)); + + JLabel titleLabel = new JLabel("Auswertung"); + titleLabel.setHorizontalAlignment(JLabel.CENTER); + titleLabel.setFont(titleLabel.getFont().deriveFont(20.0f)); + add(titleLabel, BorderLayout.NORTH); + + innerPanel = new JPanel(); + innerPanel.setLayout(new GridBagLayout()); + + scrollPane = new JScrollPane(innerPanel, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + add(scrollPane); } @Override @@ -42,35 +63,41 @@ class ScorePanel extends JPanel implements IScorePanel { @Override public void update() { - this.removeAll(); - + innerPanel.removeAll(); + GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; + c.weighty = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; - + addPlayerNames(); - add(new JSeparator(), c); - + innerPanel.add(new JSeparator(), c); + int n = 0; for (Iterator it = scores.iterator(); it.hasNext();) { addScoreRow(it.next(), ++n); } - - add(new JSeparator(), c); - + + innerPanel.add(new JSeparator(), c); + addAccumulatedScore(); + + c.weighty = 1; + innerPanel.add(Box.createVerticalGlue(), c); } private void addPlayerNames() { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; - + c.weighty = 0.0; + c.insets = new Insets(0, 7, 0, 7); + JLabel roundHead = new JLabel("Runde"); roundHead.setHorizontalAlignment(JLabel.CENTER); - add(roundHead, c); + innerPanel.add(roundHead, c); for (Iterator it = players.iterator(); it.hasNext();) { PlayerSettings player = it.next(); @@ -83,8 +110,8 @@ class ScorePanel extends JPanel implements IScorePanel { playerNameLabel.setIcon(ImageUtil.createColorIcon(player.getColor(), 12, 1)); playerNameLabel.setHorizontalAlignment(JLabel.CENTER); - - add(playerNameLabel, c); + + innerPanel.add(playerNameLabel, c); } } @@ -92,20 +119,22 @@ class ScorePanel extends JPanel implements IScorePanel { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; + c.weighty = 0.0; c.gridwidth = 1; - + c.insets = new Insets(0, 7, 0, 7); + JLabel roundLabel = new JLabel(Integer.toString(n)); roundLabel.setHorizontalAlignment(JLabel.CENTER); - add(roundLabel, c); + innerPanel.add(roundLabel, c); for (int i = 0; i < score.getPoints().size(); ++i) { - if (i == score.getPoints().size()-1) { + if (i == score.getPoints().size() - 1) { c.gridwidth = GridBagConstraints.REMAINDER; } - + JLabel scoreLabel = new JLabel(Integer.toString(score.getPoints().get(i))); scoreLabel.setHorizontalAlignment(JLabel.CENTER); - add(scoreLabel, c); + innerPanel.add(scoreLabel, c); } } @@ -113,19 +142,22 @@ class ScorePanel extends JPanel implements IScorePanel { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; - + c.weighty = 0.0; + c.insets = new Insets(0, 7, 0, 7); + JLabel accumLabel = new JLabel("Gesamt"); accumLabel.setHorizontalAlignment(JLabel.CENTER); - add(accumLabel, c); - + innerPanel.add(accumLabel, c); + for (int i = 0; i < accumulatedScore.getPoints().size(); ++i) { - if (i == accumulatedScore.getPoints().size()-1) { + if (i == accumulatedScore.getPoints().size() - 1) { c.gridwidth = GridBagConstraints.REMAINDER; } - - JLabel scoreLabel = new JLabel(Integer.toString(accumulatedScore.getPoints().get(i))); + + JLabel scoreLabel = new JLabel(Integer.toString(accumulatedScore + .getPoints().get(i))); scoreLabel.setHorizontalAlignment(JLabel.CENTER); - add(scoreLabel, c); + innerPanel.add(scoreLabel, c); } } } -- cgit v1.2.3