import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.math.*;

public class Documentation {
    String[] S=new String[10];
    SelectInteger PAGE;
    int X,Y;

    public Documentation(int x,int y) {
	this.X=x;
	this.Y=y;
	setPage1();
	PAGE=new SelectInteger(x+5,y+144,40,20,1,1,8,1);
    }

    public void setPage1() {
	for(int i=0;i<10;++i) S[i]="";
	   S[0]="This applet is my attempt";
	   S[1]="to understand the math in";
 	  S[2]="a paper by Conway and";
 	  S[3]="Coxeter on integral Frieze";
 	  S[4]="patterns and triangulations.";
 	  S[5]="Click the blue arrow to";
 	  S[6]="see more explanatory text.";
    }

    public void setPage2() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="Row 1 of an integer";
	S[1]="Frieze pattern is an infinite";
	S[2]="list of 1s.  Row 2 is";
	S[3]="an infinite periodic list of";
	S[4]="numbers generated from";
	S[5]="a triangulated polygon,";
	S[6]="in the following way.";
    }

    public void setPage3() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="Let N(k) be the number";
	S[1]="of triangles that share the";
	S[2]="(k)th vertex.  Row 2 is";
	S[3]="...N(1),N(2),N(3),... ";
	S[4]="To see this, click the green";
	S[5]="and orange arrows and";
	S[6]="watch the circled numbers.";
    }

    public void setPage4() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="Row 3  is derived";
	S[1]="From Row 1 and Row 2";
	S[2]="Using the rule shown";
	S[3]="just below this explanation";
	S[4]="Row 4 is derived from";
	S[5]="Row 2 and Row 3 in";
	S[6]="the same way.  And so on.";
    }

    public void setPage5() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="Amazingly, the pattern ends";
	S[1]="in another infinite list of 1s";
	S[2]="and has a glide reflection";
	S[3]="symmetry.  Each number";
	S[4]="in the pattern corresponds";
	S[5]="to a diagonal of the polygon.";
	S[6]="Find the white numbers.";
    }

    public void setPage6() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="The value of the current";
	S[1]="white number has an";
	S[2]="interpretation in terms";
	S[3]="of hyperbolic geometry.";
	S[4]="This is what the applet";
	S[5]="demonstrates.  In brief";
	S[6]="it works as follows.";
    }

    public void setPage7() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="Map the triangulated";
	S[1]="polygon to the Farey";
	S[2]="tesselation so that one";
	S[3]="endpoint of the diagonal";
	S[4]="goes to infinity and the";
	S[5]="other is some rational";
	S[6]="number p/q in [0,1].";
    }

    public void setPage8() {
	for(int i=0;i<10;++i) S[i]="";
	S[0]="The white numbers";
	S[1]="corresponding to";
	S[2]="the diagonal are all q, the";
	S[3]="denominator of the image";
	S[4]="of the endpoint of the";
	S[5]="diagonal.  The right side";
	S[6]="of the applet shows this.";
    }



    public void setPage(int j) {
	if(j==1) setPage1();
	if(j==2) setPage2();
	if(j==3) setPage3();
	if(j==4) setPage4();
	if(j==5) setPage5();
	if(j==6) setPage6();
	if(j==7) setPage7();
	if(j==8) setPage8();
    }



    public void render(Graphics2D g) {
	g.setColor(new Color(0,0,120));  
	g.fillRect(X,Y-10,168,178);

	g.setColor(new Color(70,130,255));  
	g.drawRect(X,Y-10,168,178);

	g.drawRect(X,Y-10,168,150);
                 g.setFont(new Font("Helvetica",Font.PLAIN,12));
	for(int i=0;i<7;++i) {
	    g.drawString(S[i],X+5,Y+20*i+8);
	}

	PAGE.render(g,new Color(70,130,255),new Color(70,130,255),new Color(80,180,255));     
                  g.setFont(new Font("Helvetica",Font.PLAIN,12));
	g.drawString("out of 8 pages",X+64,Y+158);
    }

    public void process(Point X) {
	PAGE.modify(X);
	if(PAGE.isModified(X)==1) setPage(PAGE.val);
    }


}

