001    /*
002     * Spirograph.java
003     * part of the Spirograph problem set
004     *
005     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
006     * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the
007     * CS101 homepage</a> or email <las@ai.mit.edu>.
008     *
009     * Copyright (C) 1998 Massachusetts Institute of Technology.
010     * Please do not redistribute without obtaining permission.
011     */
012    
013    package spirograph;
014    
015    import java.io.*;
016    import java.awt.*;
017    
018    /** This class handles a lot of the initialization for the Spirograph.
019     * It creates an instance of DotFrame and CodeBox and creates
020     * instances of the name passed in on the command line.
021     * It also creates the CodeBox and the AccelHandlers and passes
022     * them to the appropriate objects. <p>
023     *
024     * <p>Copyright © 1998 Massachusetts Institute of Technology<br />
025     * Copyright © 2003 Franklin W. Olin College of Engineering</p>
026     *
027     *
028     * @author Luis Sarmenta, lfgs@cag.lcs.mit.edu
029     * @author Henry Wong, henryw@mit.edu
030     * @version $Id: Spirograph.java,v 1.5 2004/02/09 20:55:03 gus Exp $
031     * @see AccelHandler
032     * @see CodeBox
033     * @see DotFrame
034     */
035    public class Spirograph {
036        /** The initial height of the {@link DotPanel}.
037         */    
038      public static final int HEIGHT = 400;
039      /** The initial width of the {@link DotPanel}.
040       */  
041      public static final int WIDTH = 400;
042      /** Size of the dot as it will appear in the GUI. */
043      public static final int BALLSIZE = 10;
044      /** Minimum timestep for updates. */
045      public static final double TIMESTEP = 1;    
046      /** The strength of a gravity source.
047       */  
048      public static final int GRAV = 1000;
049      /** Maximum dot velocity allowed. */
050      public static final double MAXVEL = 60;
051      /** The size of an elipse foci point.
052       */  
053      public static final int FOCUSSIZE = 6;
054    
055      /** Problem set wide default font. */
056      public static final Font DEFAULTFONT = new Font("Plain", Font.PLAIN, 12);
057        
058      private Accelerator xAccel, yAccel;
059      private Coord xCoord = new Coord();
060      private Coord yCoord = new Coord();
061      private AccelHandler xHandler, yHandler;
062      private DotFrame myFrame;
063      private CodeBox cb;
064        
065      /** 
066       * Attempt to construct a new Spirograph with the given Accleration
067       * Handlers.  Abort if either handler cannot be created.
068       *
069       * @param xArg The name of the file containing new AccelHandler for the x direction
070       * @param yArg The name of the file containing new AccelHandler for the y direction
071       */
072      public Spirograph(String xArg, String yArg) {
073            
074        if ( xArg == null ) {
075          xAccel = new Dummy();
076        } else {
077          System.out.println ("Trying to get class: " + xArg);      
078          xAccel = SpiroUtils.createAccel(xArg);    
079        }
080            
081        if ( yArg == null )
082          yAccel = new Dummy();
083        else {
084          System.out.println ("Trying to get class: " + yArg);      
085          yAccel = SpiroUtils.createAccel(yArg);
086        }
087    
088        if ((xAccel == null)||(yAccel == null)) {
089          System.exit(0);
090        }
091            
092            
093        xHandler = new AccelHandler(xAccel, xCoord, yCoord);
094        yHandler = new AccelHandler(yAccel, yCoord, xCoord);
095    
096        cb = new CodeBox(xHandler, yHandler);
097        
098        myFrame = new DotFrame(xHandler, yHandler, xCoord, yCoord);
099      }
100    }
101    
102    /*
103     * $Log: Spirograph.java,v $
104     * Revision 1.5  2004/02/09 20:55:03  gus
105     * javadoc fixes
106     *
107     * Revision 1.4  2003/01/17 21:01:31  gus
108     * Finish javadoc
109     *
110     * Revision 1.3  2003/01/15 17:36:10  gus
111     * adding log keywords to files that don't have them
112     *
113     */