/*---------------------------------------------------------------------------
File:         			CommentGrammar.java
Package:                        JFLAP Version 3.0
Author:			        Eric Gramond 
                                
Description of Contents:	Contains class CommentGrammar.
				
--------------------------------------------------------------------------*/

/* 
 * Susan H. Rodger, Magda Procopiuc, Octavian Procopiuc, Eric Gramond
 * Computer Science Department
 * Duke University
 * June 1998
 * Supported by National Science Foundation DUE-9596002 and DUE-9555084.
 *
 * Copyright (c) 1998
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the author.  The name of the author may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

package flap;

import java.util.*;
import java.awt.*;
import java.io.*;
import java.awt.image.*;
import java.awt.event.*;


/**
 * This a generic grammar. Basically made up of a set of Rules and a start Symbol
 * Then comments on the side and skipped lines have been added. It's a normal
 * grammar, it sut draws itself differently.
 */
public class CommentGrammar extends Grammar {


  public Vector myComments;
  public Vector myBlankLines;

  public CommentGrammar() {
    
    super();
    myComments = new Vector();
    myBlankLines = new Vector();

  }


  public void draw(Graphics g) {
    Enumeration e;
    int x = 3;
    int newX;
    int y;
    Rule r;
    FontMetrics fm = g.getFontMetrics();
    int h = fm.getAscent();
    y = h+5;
    int count = 0;
    
    for(e = myRules.elements(); e.hasMoreElements(); ) {
      
      r = (Rule) e.nextElement();
      if(((String) myBlankLines.elementAt(count)).equals("skip"))
        y+=h+3;
      newX = r.draw(g, x, y);
      g.setColor(Color.black);
      g.drawString((String) myComments.elementAt(count), maxX - 75, y);
      newX += 25 + fm.stringWidth((String) myComments.elementAt(count));
      y+=h + 3;
      maxX = Math.max(newX, maxX);
      count++;
    }
    maxY = y;
  }


}
