package jrummikub.view; import java.awt.Color; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.text.DecimalFormat; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.border.LineBorder; @SuppressWarnings("serial") public class PlayerPanel extends JPanel implements IPlayerPanel { private final static DecimalFormat secondFormat = new DecimalFormat("00"); private Board board; private JLabel currentPlayerNameLabel; private JButton sortByNumberButton; private JButton sortByColorButton; private JProgressBar timeBar; private JButton endTurnButton; @Override public IBoard getBoard() { return board; } @Override public void setCurrentPlayerName(String playerName) { currentPlayerNameLabel.setText(playerName); } @Override public void setTimeLeft(int time) { timeBar.setValue(time); timeBar.setString(Integer.toString(time/60) + ":" + secondFormat.format(time%60)); } JPanel createLeftPanel() { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(0, 0)); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(layout); panel.setOpaque(false); currentPlayerNameLabel = new JLabel(); currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER); currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER); currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER); currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER); currentPlayerNameLabel.setPreferredSize(new Dimension(200, 30)); c.weightx = 0; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(25, 0, 0, 0); layout.setConstraints(currentPlayerNameLabel, c); panel.add(currentPlayerNameLabel); sortByNumberButton = new JButton("Sort by
number"); sortByNumberButton.setPreferredSize(new Dimension(95, 50)); c.gridwidth = GridBagConstraints.RELATIVE; c.gridheight = GridBagConstraints.REMAINDER; c.insets = new Insets(15, 0, 20, 5); layout.setConstraints(sortByNumberButton, c); panel.add(sortByNumberButton); sortByColorButton = new JButton("Sort by
color"); sortByColorButton.setPreferredSize(new Dimension(95, 50)); c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(15, 5, 20, 0); layout.setConstraints(sortByColorButton, c); panel.add(sortByColorButton); return panel; } JPanel createRightPanel() { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(0, 0)); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(layout); panel.setOpaque(false); timeBar = new JProgressBar(0, 60); timeBar.setStringPainted(true); timeBar.setPreferredSize(new Dimension(200, 30)); c.weightx = 0; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(25, 0, 0, 0); layout.setConstraints(timeBar, c); panel.add(timeBar); endTurnButton = new JButton("End turn"); endTurnButton.setPreferredSize(new Dimension(200, 50)); c.gridheight = GridBagConstraints.REMAINDER; c.insets = new Insets(15, 0, 20, 0); layout.setConstraints(endTurnButton, c); panel.add(endTurnButton); return panel; } PlayerPanel() { GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(layout); setBorder(new LineBorder(Color.BLACK, 1)); setBackground(Color.LIGHT_GRAY); JPanel leftPanel = createLeftPanel(); c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridheight = GridBagConstraints.REMAINDER; layout.setConstraints(leftPanel, c); add(leftPanel); board = new Board(); c.weightx = 3; layout.setConstraints(board, c); add(board); JPanel rightPanel = createRightPanel(); c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(rightPanel, c); add(rightPanel); } }