package com.rv.gwtsample.client;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.WidgetCanvas;

import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tile.TileLayout;

//public class SecondsGrid extends TileLayout {
//
//	public SecondsGrid() {
//		this.setLayoutMargin(1);
//		for (int i=0; i<60; ++i) {
//			Label label =new Label(Integer.toString(i));
////			label.setShowEdges(true);
//			label.setAlign(Alignment.CENTER);
////			label.setAutoFit(true);
////			label.setPadding(1);
//			label.setAutoWidth();
//			label.setAutoHeight();
//			label.setStyleName("gridLabel");
//			this.addTile(label);
//		}
//	}
//}

public class MinutesGrid extends VLayout {

	private int numCols = 10;

	public MinutesGrid() {
		final int CELL_WIDTH = 22;
		final int CELL_HEIGHT = 22;
		int numRows = 60 / numCols;

		for (int row = 0; row < numRows; ++row) {
			HLayout layout = new HLayout();
			for (int col = 0; col < numCols; ++col) {
				final Label lbl = new Label(Integer.toString((row * numCols) + col));
				lbl.setOverflow(Overflow.HIDDEN);
				lbl.setWidth(CELL_WIDTH);
				lbl.setHeight(CELL_HEIGHT);
				lbl.setAlign(Alignment.CENTER);

//				lbl.setStyleName("gridLabel");
				lbl.addClickHandler(new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {
						String bgColor =null;
						if ((bgColor=lbl.getBackgroundColor())== null || bgColor.equals("white")) {
							lbl.setBackgroundColor("gray");
						}
						else {
							lbl.setBackgroundColor("white");
						}
						GWT.log(lbl.getBackgroundColor());
						SC.say("You clicked on [" + lbl.getContents() + "]");
					}
				});
				layout.addMember(lbl);
			}
			this.addMember(layout);
		}
		this.setWidth(CELL_WIDTH * numCols);
		this.setHeight(CELL_HEIGHT * numRows);
	}
}
