import java.awt.*;

public class Ndraw extends Panel{
	private String[] data; //the strings
	private Color[]	datac; //the color of the strings
	private int[][] pos; //pos[x] contains row and col info for string
	int[] lpos;
	private int nindex;
	public static final int TOP=1;
	public static final int BOTTOM=2;
	public static final int NONE=0;


	//constructors
	public Ndraw(String[] data, Color[] datac, int[][] pos,int[] lpos,int NIndex){ //rowcol true: pos is row and col
		this.nindex=NIndex;
		this.data = data;
		this.datac = datac;
		this.pos = pos;
		this.lpos = lpos;
	}

	//changers
	public void setString(String[] data){
		this.data = data;
		repaint();
	}
	public void setColor(Color[] datac){
		this.datac = datac;
		repaint();
	}
	public void setRowCol(int[][] pos){
		this.pos = pos;
		repaint();
	}

	//display
	public void paint(Graphics g){
		FontMetrics fm;
		int i;
		fm = g.getFontMetrics();
		g.setColor(Color.black);
		g.drawRect(0,0,size().width-1,size().height-1);
		g.drawRect(2,2,size().width-5,size().height-5);
		for(i=0;i<data.length;i++){
				g.setColor(datac[i]);
				TD(data[i],g,pos[i][0],pos[i][1],i==nindex,lpos[i]);

		}
	}
	public void TD(String T, Graphics g, int ry, int cx,boolean poly,int line){
		FontMetrics fm;
		int x;
		int y;
		int n;
		fm = g.getFontMetrics();
		x = maxCharWidth(fm)+(cx*maxWidth(fm));
		y = 5 + fm.getHeight() + ry*fm.getHeight();
		char[] dca = new char[T.length()];
		T.getChars(0, T.length(),dca,0);
		if(poly){
			for(n=0;n<dca.length;n+=4){
				g.drawChars(dca,n,3,x,y);
				int mid = 3*maxCharWidth(fm)/2;
				g.drawLine(x+mid,y-fm.getAscent()-1,x+mid,y-fm.getAscent()+fm.getLeading()+fm.getDescent());
				g.drawLine(x+2,y-fm.getAscent()-1,x+(2*mid)-2,y-fm.getAscent()-1);
				x+=maxCharWidth(fm)*3;
			}
		}else{
			if(line==TOP){
				g.drawLine(x,y-fm.getAscent(),x+maxWidth(fm)-maxCharWidth(fm),y-fm.getAscent());
			}else if(line==BOTTOM){
				g.drawLine(x,y+fm.getDescent(),x+maxWidth(fm)-maxCharWidth(fm),y+fm.getDescent());
			}
			for(n=0;n<dca.length;n++){
				g.drawChars(dca,n,1,x,y);
				x+=maxCharWidth(fm);
			}
		}
	}

	//display calc
	public int maxWidth(FontMetrics fm){
		int i;
		int width = 0;
		for(i=0;i<data.length;i++){
			if(!(i==nindex)){
				if ((data[i].length()+1)*maxCharWidth(fm)>width){
					width = (data[i].length()+1)*maxCharWidth(fm);
				}
			}
		}
		return width;
	}
	public int maxCharWidth(FontMetrics fm){
		int i;
		int width = 0;
		if (fm.charWidth('A')>width){
				width = fm.charWidth('A');
		}
		if (fm.charWidth('T')>width){
						width = fm.charWidth('T');
		}
		if (fm.charWidth('C')>width){
						width = fm.charWidth('C');
		}
		if (fm.charWidth('G')>width){
						width = fm.charWidth('G');
		}
		if (fm.charWidth('U')>width){
						width = fm.charWidth('U');
		}
		return width+1;
	}

}
