package trafficlight;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */
import java.awt.* ;
import javax.swing.* ;

public class ModelView
extends JPanel {

  private final static int GREEN = 2 ;
  private final static int YELLOW = 1 ;
  private final static int RED = 0  ;

  TrafficLightModel tlm ;

  public ModelView(TrafficLightModel tlm) {
    this.tlm = tlm ;
  }

  private final static int SIZE = 20 ;
  private final static int SPACER = 5 ;

  public void paintComponent( Graphics gc ) {
    super.paintComponent(gc) ;
    int w = getWidth() ;
    int h = getHeight() ;
    h /= 4 ;
    w = w/2 - SIZE/2 ;

    Color theRed = Color.red.darker() ;
    Color theYel = Color.yellow.darker() ;
    Color theGre = Color.green.darker() ;

    switch( tlm.getLight() ) {
    case RED:
       theRed = theRed.brighter().brighter() ;
       break ;
    case YELLOW:
       theYel = theYel.brighter().brighter() ;
       break ;
    case GREEN:
       theGre = theGre.brighter().brighter() ;
       break ;
    }

    gc.drawRect(w-SPACER,h-SPACER,SIZE+2*SPACER,3*SIZE+4*SPACER) ;

    gc.setColor(theRed) ;
    gc.fillOval(w,h,SIZE,SIZE);
    gc.setColor(theYel) ;
    h += SIZE + SPACER ;
    gc.fillOval(w,h,SIZE,SIZE);
    gc.setColor(theGre) ;
    h += SIZE + SPACER ;
    gc.fillOval(w,h,SIZE,SIZE);
  }




}