/* * BLikeTile.java * * Created on December 8, 2005, 7:43 AM */ package Current.plot.BilliardLike; import Current.basic.*; import Current.manage.*; import Current.plot.Plotters.*; import Current.plot.BilliardLike.*; import java.awt.*; import java.awt.geom.*; import java.util.TreeSet; import Current.basic.HolonomyPosition; /** * This class stores and manipulates data for the Billiard-Like tiles. * * Eventually, I want this to store some addition data. Namely, the * rational lines that form the boundary components. * * @author pat */ public class BLikeTile implements Tile { public String W; public GeneralPath GP=null; public Color C; /** initialize everything yourself! */ private BLikeTile(){} /** "Plots the BLike Tile" * That is, it creates something that is plotable from a word * Returns null in case the tile is the null set. */ public static BLikeTile plot(String word, Color C, Interrupter I){ BLikeTile t=new BLikeTile(); t.W=word; t.C=C; t.reconstitute(I); return t; } public String getStringWord() { return W; } public boolean isPaintable() { return (GP!=null); } public boolean isSaveable() { return true; } public void paint(Graphics2D g, AffineTransform T) { g.setColor(C); g.fill(T.createTransformedShape(GP)); g.setColor(Color.black); g.draw(T.createTransformedShape(GP)); } public void paintSelected(Graphics2D g, AffineTransform T) { g.setColor(C); g.fill(T.createTransformedShape(GP)); g.setColor(Color.white); g.setStroke(new BasicStroke((float)2.0)); g.setColor(Color.white); g.draw(T.createTransformedShape(GP)); g.setStroke(new BasicStroke((float)1.0)); } public String saveString() { return "START BLike\n"+ "WORD "+W+"\n"+ "END"; } public Rectangle2D getBounds() { return GP.getBounds2D(); } public boolean contains(double x, double y) { return GP.contains(x,y); } public void setColor(Color C) { this.C=C; } // /** should be followed by a call to reconstitute */ // public void readExternal(ObjectInput obj_in) throws IOException, ClassNotFoundException { // C=(Color)(obj_in.readObject()); //read color // W=(String)(obj_in.readObject()); //read word // } // // public void writeExternal(java.io.ObjectOutput obj_out) throws IOException { // obj_out.writeObject(C); //write color // obj_out.writeObject(W); //write word // } // public void reconstitute(Interrupter I) { LoopWord w=new LoopWord(W); HolonomyPosition[] hol=w.createHolonomy(); TreeSet[][] leftOf=w.createLeftOf(); PatConvexHull ch=w.computeTile(hol,leftOf); if (ch==null) { System.err.println("Error: failed to reconstitute BLikeTile!"); } GP=ch.toGeneralPath(); } public Color getColor() { return C; } public XPlotter getPlotter() { return new XBilliardLikePlotter(); } }