/* File : BraidDrawing.java * Program : Handle Reduction Aimation - Applet * By Jean Fromentin * Copyright 2008 Jean Fromentin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.GeneralPath; public class BraidDrawing extends Braid{ private float strandStep; //The distance between two strand private float strandWidth; //The width of a strand private float strandLeft; //The x position of the leftmost strand private float[][] xPos; private float yUp; private float yPos; public boolean handleNormalDraw; //This variable is true if we draw the handle with the classic metod public boolean onHandle; //This variable is true if we are in between the handleBegin Node and the handleEnd node public float trivialHeight; private Color[] strandColor; //The color of different strand private Color handleColor=Color.black; //The color of the handle private Color originalHandleStrandColor; //The original color of the handle strand static public boolean isDraw; //For not repeat drawing public boolean firstDraw; public BraidDrawing(String braidWord){ super(braidWord); trivialNumber=0; trivialHeight=0; handleNormalDraw=true; isDraw=false; } public void initStrandColor(){ strandColor=new Color[strandNumber]; for(int strand=1;strand=handleBeginIndice && indice<=handleEndIndice && strand==handleStrand); } public void drawLine(Graphics g, float xA, float yA, float xB,float yB,Color color){ Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(strandWidth*2,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL)); GeneralPath path=new GeneralPath(); float yBezier=(yB-yA)/3; path.moveTo(xA,yA); path.curveTo(xA,yA+yBezier,xB,yA+2*yBezier,xB,yB); g2.setColor(Color.white); g2.draw(path); g2.setStroke(new BasicStroke(strandWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL)); path=new GeneralPath(); path.moveTo(xA,yA); path.curveTo(xA,yA+yBezier,xB,yA+2*yBezier,xB,yB); g2.setColor(color); g2.draw(path); } public void drawCrossing(Graphics g,int indice, int strandNumber,int generator, int exp){ int begin; int step; GeneralPath gpl,gpm,gpr; if(exp==1){ begin=1; } else{ begin=strandNumber; } for(int strand=begin;00){ if(animationStep>=2 && animationStep<=4){ for(int indice=handleBeginIndice+1;indice<=handleEndIndice;indice++){ xPos[indice][handleStrand]+=(parameterAnimationStep2-1)*(float)strandStep; } } if(animationStep==4){ current=handleBegin; for(int indice=handleBeginIndice+1;indice<=handleEndIndice;indice++){ xPos[indice][handleStrand-1]+=parameterAnimationStep4*(float)strandStep; } setCurrent(current); shift(); for(int indice=handleBeginIndice+2;indice1 && generator==handleStrand-1){ xPos[indice-1][handleStrand-2]+=parameterAnimationStep4*(float)strandStep; xPos[indice][handleStrand-2]+=parameterAnimationStep4*(float)strandStep; } shift(); } } if(animationStep==5){ current=handleBegin; setCurrent(current); int currentStrand=handleStrand; for(int indice=handleBeginIndice;indice<=handleEndIndice;indice++){ generator=value(); if(generator<0){ generator=-generator; } if(generator==currentStrand){ currentStrand++; } else if(generator==currentStrand-1){ currentStrand--; } if(handleStrand>1 && currentStrand==handleStrand-1){ xPos[indice+1][handleStrand-2]+=parameterAnimationStep5*(float)strandStep; } shift(); } } } } public String word(){ boolean stop; int value; String res=""; initCurrent(); stop=false; while(!stop){ value=value(); if(value>0){ res+=(char)((value-1)+'a'); } else if(value<0){ res+=(char)((-value-1)+'A'); } if(isEnd()){ stop=true; } if(!stop){ shift(); } } if(res==""){ res="empty"; } return res; } }