/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.wiieditor.gui;
import com.wiieditor.other.Grid;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
/**
*
* @author zohaibrauf
*/
public class GridPanel extends JPanel{
/**
* The image data.
*/
Grid data;
/**
* The constructor.
*
* @param width The width of the downsampled image
* @param height The height of the downsampled image
*/
GridPanel(int width,int height)
{
data = new Grid(width,height);
}
/**
* The image data object.
*
* @return The image data object.
*/
Grid getData()
{
return data;
}
/**
* Assign a new image data object.
*
* @param data The image data object.
*/
void setData(Grid data)
{
this.data = data;
}
/**
* @param g Display the downsampled image.
*/
public void paint(Graphics g)
{
if ( data==null )
return;
int x,y;
int vcell = getHeight()/data.getHeight();
int hcell = getWidth()/data.getWidth();
g.setColor(Color.white);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.black);
for ( y=0;y<data.getHeight();y++ )
g.drawLine(0,y*vcell,getWidth(),y*vcell);
for ( x=0;x<data.getWidth();x++ )
g.drawLine(x*hcell,0,x*hcell,getHeight());
for ( y=0;y<data.getHeight();y++ ) {
for ( x=0;x<data.getWidth();x++ ) {
if ( data.getBlock(x,y) )
g.fillRect(x*hcell,y*vcell,hcell,vcell);
}
}
g.setColor(Color.black);
g.drawRect(0,0,getWidth()-1,getHeight()-1);
}
}