import java.util.Enumeration;

/**
 * A concrete child of the Drafter class that draws
 * a "hard coded" floor plan
 */
public class FloorPlanExample extends Drafter
{
    protected LineSegment                    wall;
    protected PiecewiseLinearCurve[]         rooms;
    
    /**
     * Default Constructor
     */
    public FloorPlanExample()
    {
       double[]      p, q;
       

       // Create a single wall
       p = new double[2];
       q = new double[2];
       p[0] = 330.0; p[1] = 210.0;
       q[0] = 390.0; q[1] = 210.0;
       wall = new LineSegment(new Point(p), new Point(q));
       
       // Create all of the rooms
       rooms = new PiecewiseLinearCurve[5];
       rooms[0] = new PiecewiseLinearCurve();
       addTo(rooms[0], 490,  40);
       addTo(rooms[0], 390,  40);
       addTo(rooms[0], 390, 210);
       addTo(rooms[0], 490, 210);
       addTo(rooms[0], 490,  40);
       
       rooms[1] = new PiecewiseLinearCurve();
       addTo(rooms[1], 390,  60);
       addTo(rooms[1], 350,  60);
       addTo(rooms[1], 350, 100);
       addTo(rooms[1], 390, 100);
       addTo(rooms[1], 390,  60);
       
       rooms[2] = new PiecewiseLinearCurve();
       addTo(rooms[2], 350,  60);
       addTo(rooms[2], 290,  60);
       addTo(rooms[2], 290, 120);
       addTo(rooms[2], 330, 120);
       addTo(rooms[2], 350, 110);
       addTo(rooms[2], 350,  60);
       
       rooms[3] = new PiecewiseLinearCurve();
       addTo(rooms[3], 330, 120);
       addTo(rooms[3], 240, 120);
       addTo(rooms[3], 240, 210);
       addTo(rooms[3], 260, 220);
       addTo(rooms[3], 310, 220);
       addTo(rooms[3], 330, 210);
       addTo(rooms[3], 330, 120);
       
       rooms[4] = new PiecewiseLinearCurve();
       addTo(rooms[4], 240, 120);
       addTo(rooms[4], 170, 120);
       addTo(rooms[4], 170, 210);
       addTo(rooms[4], 240, 210);
       addTo(rooms[4], 240, 120);
    }


    


    /**
     * A convenience method for adding a point to a 
     * PiecewiseLinearCurve
     *
     * @param line   The curve being added to
     * @param x      The x-coordinate of the new point
     * @param y      The y-coordinate of the new point
     */
    private void addTo(PiecewiseLinearCurve line, double x, double y)
    {
       double[]        v;
       
       v = new double[2];
       v[0] = x;
       v[1] = y;
       line.add(new Point(v));
    }

    

    /**
     * Draw the floor plan
     *
     * This method is called by the parent Drafter whenever
     * the floor plan needs to be drawn.
     *
     * @param max    The upper-right corner of the paper
     */
    public void draw(Point max)
    {
       Enumeration          e;
       Point                p;
       
       // Draw the wall
       e = wall.points();
       p = (Point)e.nextElement();
       moveTo(p);
       while (e.hasMoreElements())
       {
          p = (Point)e.nextElement();
          drawTo(p);
       }
       

       // Draw the rooms
       for (int i=0; i<rooms.length; i++)
       {
          e = rooms[i].points();
          p = (Point)e.nextElement();
          moveTo(p);
          while (e.hasMoreElements())
          {
             p = (Point)e.nextElement();
             drawTo(p);
          }
       }
    }
}
