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.1.1.1 2002/06/05 21:56:35 root 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.1.1.1  2002/06/05 21:56:35  root
076     * CS101 comes to Olin finally.
077     *
078     * Revision 1.1  2000/05/06 22:30:58  mharder
079     * Moved to scribble subdirectory.
080     *
081     * Revision 1.4  1998/07/24 16:44:52  tparnell
082     * Placate new javadoc behavior
083     *
084     * Revision 1.3  1998/07/22 17:59:34  tparnell
085     * modifications to reflect new cs101.* package structure
086     *
087     * Revision 1.2  1998/07/20 18:55:33  tparnell
088     * Added javadoc and logging.  Minor code mods for greater consistency
089     * between files.
090     *
091     */
092    
093    
094