/**@(#) ShapeFactory.java 1.0 99/07/24 Larry Rodrigues
  **/
package com.vistech.shapes;
/** A factory class that provides static methods to construct or copy a shape.
  * @version 1.0  24  July 1999
  * @author Larry Rodrigues
  * This class defines the Shape types.
  * Given a shape type, the corrsponding shape can be
  * created by createShape method.
  **/
public class ShapeFactory {
   /** Constructs a specified shape.
     * @param shapeType the shape type.
     * @return the selected shape object.
     */
   static public Shapes createShapes(int shapeType){
       switch(shapeType){
          case Drawable.BOX: return( new Box());
          case Drawable.ELLIPSE: return(new Ellipse());
          case Drawable.ARROW: return(new Arrow());
          case Drawable.DOUBLE_HEADED_ARROW:
             Arrow arrow = new Arrow();
             arrow.setDoubleHeaded(true);
             return arrow;
          case Drawable.LINE:return(new Line());
          case Drawable.ANNOTEXT: return(new AnnoText());
          case Drawable.CURVE: return(new Curve());
          default: return null;
      }
   }

   /** Copies a specified shape.
     * @param shapeType the shape type.
     * @return the selected shape object.
     */
   static public Shapes copyShape(Shapes shape){
       Shapes sh = null;
       if(shape instanceof Box){ sh = new Box(); }
       if(shape instanceof Ellipse) { sh = new Ellipse();}
       if(shape instanceof Arrow) { sh = new Arrow();}
       if(shape instanceof AnnoText) {
          sh = new AnnoText();
          AnnoText newShape = ((AnnoText)sh);
          AnnoText oldShape = ((AnnoText)shape);
          newShape.curStr =  new StringBuffer(oldShape.curStr.toString());
          newShape.backSpaceOn = oldShape.backSpaceOn;
          newShape.curChar = oldShape.curChar;
          newShape.totWid = oldShape.totWid;
          newShape.lastChar = oldShape.lastChar;
       }
       if(shape instanceof Curve){ sh = new Curve();}
       if(shape instanceof Line){sh = new Line();}

       if(sh == null) return null;
       sh.init(shape.getStartPosition().x,shape.getStartPosition().y );
       sh.setCurrentPosition(new java.awt.Point(shape.cur.x,shape.cur.y));
       sh.setDrawingColor(shape.getDrawingColor());
       sh.setStroke(shape.getStroke());
       sh.setFont(shape.getFont());
       sh.setFillColor(shape.getFillColor());
       sh.setFillOn(shape.getFillOn());
       sh.setGeneralPath(shape.getGeneralPath());
       sh.setSmallRectsOn(shape.getSmallRectsOn());
       return sh;
   }

   /** A utility method that returns the shape type as a string.
     * @param shapeType the shape type.
     */
   static public String getTypeAsString(int shapeType){
       switch(shapeType){
	        case Drawable.BOX: return("Box");
          case Drawable.ELLIPSE:return("Ellipse");
          case Drawable.ARROW: return("Arrow");
          case Drawable.DOUBLE_HEADED_ARROW:return "Double Headed Arrow";
          case Drawable.LINE:return( "Line");
          case Drawable.ANNOTEXT:return( "Text");
          case Drawable.CURVE:return("Curve");
          default:return null;
       }
   }
}