001    /*
002     * ScribbleData.java
003     * Part of the Scribble problem set.
004     *
005     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
006     * For more information, see http://www.ai.mit.edu/projects/cs101, the
007     * CS101 homepage 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 scribble;
014    
015    import java.awt.*;
016    import java.util.*;
017    import cs101.awt.Line;
018    
019    /**
020     * ScribbleData is a repository of lines for use with a SmartCanvas.
021     * It has methods to add and clear lines, as well as paint on a given
022     * Graphics context.
023     *
024     * <P>Copyright (c) 1998 Massachusetts Institute of Technology
025     *
026     * @author Lynn Andrea Stein, las@ai.mit.edu
027     * @author Todd C. Parnell, tparnell@ai.mit.edu
028     * @version $Id: ScribbleData.java,v 1.2 2004/04/20 15:49:25 gus Exp $
029     */
030    public class ScribbleData {
031    
032      /** The Component whose lines we're storing. */
033      private Component gui;
034      /** Where we store the lines. */
035      private Vector lines = new Vector(100, 100);
036    
037      /** Initilizes an empty ScribbleData. */
038      public ScribbleData() {
039      }
040                              
041      /** Initilizes an empty ScribbleData. */
042      public ScribbleData(Component gui) {
043        this.gui = gui;
044      }
045    
046      /** Sets the Component we paint on. */
047      public void setGUI(Component gui) {
048        this.gui = gui;
049      }
050    
051      /** Paints all lines on this onto g. */
052      protected void paintLines (Graphics g) {
053        for (int i = 0; i < lines.size(); i++) {
054          ((Line)lines.elementAt(i)).drawOn(g);
055        }
056      }
057    
058      /** Stores a new line into this. */
059      public synchronized void addLine (Line newLine) {
060        lines.addElement(newLine);
061        if (this.gui != null) {
062          newLine.drawOn(this.gui.getGraphics());
063        }
064      }
065    
066      /** Clears all Lines from this. */
067      public synchronized void clearLines() {
068        lines.removeAllElements();
069        gui.repaint();
070      }
071    }
072    
073    /*
074     * $Log: ScribbleData.java,v $
075     * Revision 1.2  2004/04/20 15:49:25  gus
076     * taking ownership
077     *
078     * Revision 1.1  2003/07/11 16:17:20  jon
079     * Initial commit of spring03 scribble source.
080     *
081     * Revision 1.1.1.1  2002/06/05 21:56:35  root
082     * CS101 comes to Olin finally.
083     *
084     * Revision 1.1  2000/05/06 22:30:58  mharder
085     * Moved to scribble subdirectory.
086     *
087     * Revision 1.4  1998/07/24 16:44:52  tparnell
088     * Placate new javadoc behavior
089     *
090     * Revision 1.3  1998/07/22 17:59:34  tparnell
091     * modifications to reflect new cs101.* package structure
092     *
093     * Revision 1.2  1998/07/20 18:55:33  tparnell
094     * Added javadoc and logging.  Minor code mods for greater consistency
095     * between files.
096     *
097     */
098    
099    
100    
101