package visualization.components;

import java.awt.Graphics2D;
import java.awt.geom.Area;

import background.systemVariables.TableVariable;
import visualization.VisualComponent;

public class TableComponent extends VisualComponent {
	
	public TableComponent(TableVariable var) {
		super(var);		
		
	}
	
	@Override
	public Area getBorder(Graphics2D g, Boolean draw) {
		Area result = new Area();
		
		Area border = dizajn.getMultipleValueDesignBorder(g, draw, x, y, (dizajn.vizWidth)*table.sizeY, dizajn.vizHeight*table.sizeX, table.sizeY, table.sizeX);
		result.add(border);
		
		for (int i=0; i<table.sizeY; i++) {		
			for (int j=0; j<table.sizeX; j++) {			
				Area part = dizajn.getDesignBorder(g, draw, table.getNth(i+table.posunY, j+table.posunX).isActive(), x+(i*dizajn.vizWidth), y+(j*dizajn.vizHeight), dizajn.vizWidth, dizajn.vizHeight, i, j);				
				result.add(part);		
			}
		}				
		return result;
	}
		
	@Override
	public Area getValueShape(Graphics2D g, Boolean draw) {
        
        Area result = new Area();
		
		for (int i=0; i<table.sizeY; i++) {		
			for (int j=0; j<table.sizeX; j++) {			
				if (table.getNth(i+table.posunY, j+table.posunX).initialized) {
					Area vA = dizajn.getDesignValueShape(g, draw, table.getNth(i+table.posunY,j+table.posunX), x + i*dizajn.vizWidth, y + j*dizajn.vizHeight, i, j);
					result.add(vA);
				}
			}
		}

		return result;
	}
	
	@Override
	public Area getNameShape(Graphics2D g, Boolean draw) {		
		return dizajn.getDesignNameShape(g, draw, table.name, x, y, table.sizeY*dizajn.vizWidth, table.sizeX*dizajn.vizHeight, table.sizeY, table.sizeX);
	}

}
