import java.awt.Color;

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

/**
 * Reprezentacja stołu gry
 * zawiera planszę, zasobnik i podgląd następnych elementów
 * @see Tablepane
 */
public final class Table extends JPanel {
		Tablepane tablepane, tray, next;
		/**Liczba zdobytych punktów, inkrementowane przez {@link Water}*/
		int points;
		JLabel label;
	
	/**
	 * Domyślny konstruktor
	 * tworzy wszystkie elementy składowe
	 */
	public Table(){
		points = 0;
						
		setLayout(null);
		setBackground(new Color((float)0.5, (float)0.5, (float)0.5));
		
		tablepane = new Tablepane(12, 12);
		tablepane.setBounds(0, 0, 650, 600);
		tablepane.addHex(6, 11, new Hex("source"));
		tablepane.addHex(7, 10, new Hex(0));
		
		tray = new Tablepane(1, 5);
		tray.setBounds(670, 90, 100, 500);
		for (int i=0; i<5; i++){
			tray.addHex(0, i, new Hex());
		}
		tray.setred(0, 1);
		
		next = new Tablepane(2, 1);
		for (int i=0; i<2; i++){
			next.addHex(i, 0, new Hex());
		}
		next.setBounds(670, 405, 100, 100);
		
		ImageIcon icon = createImageIcon("polishplumber.png", "wallpaper");
		label = new JLabel(icon);
		add(label);
		label.setBounds(200, 70, 400, 400);
		label.setVisible(false);
		
		add(tablepane);
		add(tray);
		add(next);
}
	
	/**
	 * Tworzenie ikony z pliku
	 * @param path Ścieżka dostępu
	 * @param description Opis ikony
	 * @return {@link javax.swing.ImageIcon} lub null jeśli ścieżka nieprawidłowa
	 */
	protected ImageIcon createImageIcon(String path,
	                                           String description) {
	    java.net.URL imgURL = getClass().getResource(path);
	    if (imgURL != null) {
	        return new ImageIcon(imgURL, description);
	    } else {
	        System.err.println("Couldn't find file: " + path);
	        return null;
	    }
	}
}
