import java.awt.*;
import javax.swing.*;

public class InformPanel extends JPanel
{
    RobboFrame RF;
    private Dimension Dim;
    private Graphics Gr;
    private Image image;
    String[] DATA_STRINGS;
    int DATA_COUNT;
    int SIZE = 24;
    int MAX_LENGTH = 600;

    public InformPanel (RobboFrame ROBBO_FRAME)
    {
	super ();
	RF = ROBBO_FRAME;
	DATA_COUNT = 0;
	DATA_STRINGS = new String[3000];
	this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
    }

    public final synchronized void update (Graphics G)
    {
	Dimension dim = getSize();
	if (
	    (image == null) ||
	    (dim.height != Dim.height) ||
	    (dim.width != Dim.width)
	    )
	    {
		image = createImage (dim.width, dim.height);
		Gr = image.getGraphics ();
		Dim = dim;
	    }
	paint (Gr);
	G.drawImage (image, 0, 0, null);
    }

    public Dimension getMinimumSize ()
    {
	return new Dimension (600, 600);
    }

    public Dimension getPreferredSize ()
    {
	return new Dimension (MAX_LENGTH, SIZE * DATA_COUNT + SIZE);
    }

    public void paint (Graphics G)
    {
	char B[] = new char[1];
	G.setColor (new Color (245, 235, 225));
	G.fillRect (0, 0, 10000, SIZE * 1500);
	G.setColor (Color.black);
	Font F = RF.chess_font.deriveFont ((float) SIZE);
	Font F2 = RF.chess_font.deriveFont ((float) (1 + SIZE / 2));
	int VSIZE = SIZE, HSIZE = SIZE;
	MAX_LENGTH = 600;
	for (int i = 0; i < DATA_COUNT; i++)
	    {
		StringBuffer SB = new StringBuffer (DATA_STRINGS[i]);
		for (int j = 0; j < 4; j++)
		    {
			int u = ((int) SB.charAt (j)) - ((int) 'a');
			switch (u)
			    {
			    case 0: B[0] = 0; break;
			    case 1: B[0] = 80 + 32; break;
			    case 2: B[0] = 78 + 32; break;
			    case 3: B[0] = 75 + 32; break;
			    case 4: B[0] = 66 + 32; break;
			    case 5: B[0] = 66 + 32; break;
			    case 6: B[0] = 82 + 32; break;
			    case 7: B[0] = 81 + 32; break;
			    case 8: B[0] = 'Z'; break;
			    case 9: B[0] = 79 + 32; break;
			    case 10: B[0] = 77 + 32; break;
			    case 11: B[0] = 76 + 32; break;
			    case 12: B[0] = 86 + 32; break;
			    case 13: B[0] = 86 + 32; break;
			    case 14: B[0] = 84 + 32; break;
			    case 15: B[0] = 87 + 32; break;
			    }
			if (u == 8)
			    {
				G.setFont (F2);
				B[0] = 80 + 32;
				G.drawChars (B, 0, 1, 4 + SIZE / 4 + HSIZE * j, VSIZE * (i + 1) + 4);
				B[0] = 79 + 32;
				G.drawChars (B, 0, 1, 4 + SIZE / 4 + HSIZE * j, VSIZE * (i + 1) + 4 - SIZE / 2);
				G.setColor (Color.black);
				G.drawLine (HSIZE * j + 6, VSIZE * (i + 1) + 3, HSIZE * (j + 1) + 2, VSIZE * (i + 1) + 3);
				G.drawLine (HSIZE * j + 6, VSIZE * (i + 1) + 3, HSIZE * j + 6, VSIZE * i + 3);
				G.drawLine (HSIZE * (j + 1) + 2, VSIZE * i + 3, HSIZE * j + 6, VSIZE * i + 3);
				G.drawLine (HSIZE * (j + 1) + 2, VSIZE * i + 3, HSIZE * (j + 1) + 2, VSIZE * (i + 1) + 3);
			    }
			else
			    {
				G.setFont (F);
				G.drawChars (B, 0, 1, 4 + HSIZE * j, VSIZE * (i + 1) + 4);
			    }
		    }
		G.setFont (new Font ("Monospaced", 0, 14));
		G.drawString (DATA_STRINGS[i].substring (5), 16 + 4 * HSIZE, (i + 1) * VSIZE);
		int hsize = 4 * HSIZE + 14 * DATA_STRINGS[i].length () + 10;
		if (hsize > MAX_LENGTH)
		    MAX_LENGTH = hsize;
	    }
    }
}
