From 3fb3b387c8aa8e43d746341ee6039998c05cd6a9 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 25 May 2011 23:49:39 +0200 Subject: Cleaned up player panel code git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@279 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/PlayerPanel.java | 54 ++++++++++---------------------- 1 file changed, 17 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 171e46b..db2721a 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -113,27 +113,19 @@ class PlayerPanel extends JPanel implements IPlayerPanel { currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER); leftPanel.add(currentPlayerNameLabel); - sortByGroupsButton = new JButton("
Nach Sammlungen sortieren"); - sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0)); - sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0)); - sortByGroupsButton.addActionListener(new ActionListener() { + sortByGroupsButton = createButton(leftPanel, "
Nach Sammlungen sortieren", new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { sortByGroupsEvent.emit(); } }); - leftPanel.add(sortByGroupsButton); - sortByRunsButton = new JButton("
Nach Reihen sortieren"); - sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0)); - sortByRunsButton.setMargin(new Insets(0, 0, 0, 0)); - sortByRunsButton.addActionListener(new ActionListener() { + sortByRunsButton = createButton(leftPanel, "
Nach Reihen sortieren", new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { sortByRunsEvent.emit(); } }); - leftPanel.add(sortByRunsButton); leftPanel.addComponentListener(new LeftPanelResizeListener()); } @@ -144,68 +136,56 @@ class PlayerPanel extends JPanel implements IPlayerPanel { rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET)); - handRowUpButton = new JButton("
\u25B2"); - handRowUpButton.setMargin(new Insets(0, 0, 0, 0)); - handRowUpButton.addActionListener(new ActionListener() { + handRowUpButton = createButton(rightPanel, "
\u25B2", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { hand.rowUp(); } }); - rightPanel.add(handRowUpButton); - handRowDownButton = new JButton("
\u25BC"); - handRowDownButton.setMargin(new Insets(0, 0, 0, 0)); - handRowDownButton.addActionListener(new ActionListener() { + handRowDownButton = createButton(rightPanel, "
\u25BC", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { hand.rowDown(); } }); - rightPanel.add(handRowDownButton); timeBar = new JProgressBar(0, 60); timeBar.setStringPainted(true); rightPanel.add(timeBar); - endTurnButton = new JButton("---"); - endTurnButton.setFont(endTurnButton.getFont().deriveFont(0)); - endTurnButton.setMargin(new Insets(0, 0, 0, 0)); - endTurnButton.addActionListener(new ActionListener() { + endTurnButton = createButton(rightPanel, "---", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { endTurnEvent.emit(); } }); - - rightPanel.add(endTurnButton); - keepStonesButton = new JButton("
Steine
behalten"); - keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(0)); - keepStonesButton.setMargin(new Insets(0, 0, 0, 0)); - keepStonesButton.addActionListener(new ActionListener() { + keepStonesButton = createButton(rightPanel, "
Steine
behalten", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { endTurnEvent.emit(); } }); - - rightPanel.add(keepStonesButton); - - redealButton= new JButton("
Neu
geben"); - redealButton.setFont(redealButton.getFont().deriveFont(0)); - redealButton.setMargin(new Insets(0, 0, 0, 0)); - redealButton.addActionListener(new ActionListener() { + + redealButton = createButton(rightPanel, "
Neu
geben", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { redealEvent.emit(); } }); - rightPanel.add(redealButton); - rightPanel.addComponentListener(new RightPanelResizeListener()); } + + private JButton createButton(JPanel panel, String caption, ActionListener listener) { + JButton button = new JButton(caption); + button.setFont(button.getFont().deriveFont(0)); + button.setMargin(new Insets(0, 0, 0, 0)); + button.addActionListener(listener); + panel.add(button); + return button; + } private void rescale() { Insets insets = getInsets(); -- cgit v1.2.3