summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/Table.java
blob: c3c6a717cd7727293498cdbf939c527e0fa71316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package jrummikub.view.impl;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import jrummikub.view.ITable;

@SuppressWarnings("serial")
public class Table extends JPanel implements ITable {
  private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/felt.png"));
  
  private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
  private JPanel innerPanel;
  

  @Override
  public void setLeftPlayerName(String playerName) {
    leftPlayerLabel.setText(playerName);
  }

  @Override
  public void setTopPlayerName(String playerName) {
    topPlayerLabel.setText(playerName);
  }

  @Override
  public void setRightPlayerName(String playerName) {
    rightPlayerLabel.setText(playerName);
  }
  
  Table() {
    super(true); // set double buffered
    setLayout(new BorderLayout());
    
    leftPlayerLabel = new JLabel();
    leftPlayerLabel.setForeground(Color.WHITE);
    add(leftPlayerLabel, BorderLayout.WEST);
    
    topPlayerLabel = new JLabel();
    topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
    topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
    topPlayerLabel.setForeground(Color.WHITE);
    add(topPlayerLabel, BorderLayout.NORTH);
    
    rightPlayerLabel = new JLabel();
    rightPlayerLabel.setForeground(Color.WHITE);
    add(rightPlayerLabel, BorderLayout.EAST);
    
    innerPanel = new JPanel();
    innerPanel.setOpaque(false);
    add(innerPanel, BorderLayout.CENTER);
  }
  
  @Override
  protected void paintComponent(Graphics g) {
    for(int x = 0; x < getWidth(); x += background.getIconWidth()) {
      for(int y = 0; y < getHeight(); y += background.getIconHeight()) {
        background.paintIcon(this, g, x, y);
      }
    }
    
    // TODO Rest of painting code
  }
}