/*
 * $Id$
 * 
 * (c)reated: 28-Feb-05 by boehm@javatux.de
 */

package verkehrs;

//import verkehrs.utils.MyObservable;



/**
 * Modell einer Verkehrsampel
 * (engl.: TrafficLight - eines der wenigen Beispiel, wo das deutsche Wort
 * kuerzer ist; und da ich schreibfaul bin, habe ich mich fuer "Ampel"
 * entschieden;-)
 * 
 * @author <a href="mailto:boehm@javatux.de">oliver</a>
 * @since 28.02.2005
 * @version $revision$
 */
@Model
public class AmpelModel /* extends MyObservable */ {
    
    // dieses Attribut sollte eine Warnung erzeugen
    //private AmpelView view = new AmpelView();

    //  some public constants
	public static final int OUT_OF_ORDER = 0;
    public static final int RED = 1;
    public static final int RED_YELLOW = 2;
    public static final int GREEN = 3;
    public static final int YELLOW = 4;

    /**
     * Zustand der Ampel (rot, gelb, gruen...)
     * TODO nicht als 'int' sondern als 'enum' realisieren
     */
    private int state = RED;

    //	switch to next state
    public void nextState() {
        state++;
        if (state > YELLOW) { //  not nice,
            state = RED;      //  but it works
        }
    }

    //  reset traffic light
    public void reset() {
        state = RED;
    }

    //  get state of traffic light
    public int getState() {
        return (state);
    }
    
    public String toString() {
        switch (state) {
        case RED:           return "rot";
        case RED_YELLOW:    return "rot-gelb";
        case GREEN:         return "gruen";
        case YELLOW:        return "gelb";
        default:            return "ausser Betrieb";
        }
    }

}