public class ModeSnapshotState extends ModeStates
{
    @Override
    public String getValue()
    {
        return "Snapshot ->";
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        printMovingTo(rightState);
        
        return rightState;
    }
} public class RaspberryPiShutdownState extends RaspberryPiStates
{
    @Override
    public String getValue()
    {
        return "<- Shutdown";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        printMovingTo(leftState);
        
        return leftState;
    }
    
    @Override
    public PhotoramaState selectButton()
    {
        printMovingTo(selectState);
        
        return selectState;
    }
} public class RaspberryPiOnState extends RaspberryPiStates
{
    @Override
    public String getValue()
    {
        return "On ->";
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        printMovingTo(rightState);
        
        return rightState;
    }
    
    @Override
    public PhotoramaState upButton()
    {
        printMovingTo(upState);
        
        return upState;
    }
    
    @Override
    public PhotoramaState selectButton()
    {
        String className = getClass().getSimpleName();
        System.out.println(className + " does nothing for SELECT button pushes.");
        
        return this;        
    }
} public class RaspberryPiConfirmShutdownState extends RaspberryPiStates
{
    private String value = "Confirm Shutdown?";
    
    @Override
    public String getValue()
    {
        return value;
    }
    
    @Override
    public PhotoramaState selectButton()
    {
        value = "Shutting Down";

        System.out.println( value.trim() );

// TODO: actually shutdown        
        
        return this;
    }
    
    @Override
    public PhotoramaState upButton()
    {
        printMovingTo(upState);
        
        return upState;
    }
    
    
} public class PhotoramaModeState extends PhotoramaStates
{
   
    @Override
    public String getValue()
    {
        return "Mode ->";
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        System.out.println("moving to " + rightState.getClass().getSimpleName());
        
        return rightState;
    }
    
    public PhotoramaState upButton()
    {
        String className = getClass().getSimpleName();
        System.out.println(className + " does nothing for UP button pushes.");
        
        return this;
    }
} public class PhotoramaRaspberryPiState extends PhotoramaStates
{    
   
    
    @Override
    public String getValue()
    {
        return "<- Raspberry Pi";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        printMovingTo(leftState);
        
        return leftState;
    }
    
//    @Override
//    public PhotoramaState selectButton()
//    {
//        printMovingTo(selectState);
//
//        return selectState;
//    }
} public interface PhotoramaState
{
    public void setCamera(Camera camera);
    
    public String getLabel();
    public String getValue();
    
    public PhotoramaState leftButton();
    public PhotoramaState rightButton();
    public PhotoramaState upButton();
    public PhotoramaState downButton();
    public PhotoramaState selectButton();
    
    public void setLeftButton(PhotoramaState leftState);
    public void setRightButton(PhotoramaState rightState);
    public void setUpButton(PhotoramaState upState);
    public void setDownButton(PhotoramaState downState);
    public void setSelectButton(PhotoramaState selectState);
}
 public class SnapshotOffState extends FootPedalStates
{
    @Override
    public String getValue()
    {
        return "<- Off";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        printMovingTo(leftState);
        
        return leftState;
    }    
} public class FootPedalOnState extends FootPedalStates
{
    @Override
    public String getValue()
    {
        return "On ->";
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        printMovingTo(rightState);
        
        return rightState;
    }    
} public class FootPedalSnapshotState extends FootPedalStates
{
    public FootPedalSnapshotState()
    {
        value = "[select]";
    }
    
    @Override
    public PhotoramaState selectButton()
    {
//        value = "taking snapshot";

        System.out.println( value.trim() );

        camera.takeSnapshot();
        
        Sleeper.sleepo(3000);
        
        System.out.println("snapshot taken");
        
        return this;
    }
} public class ModeTimeLapseState extends ModeStates
{
    public ModeTimeLapseState()
    {
        value = "<- Time Lapse";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        printMovingTo(leftState);
        
        return leftState;
    }
} public class HoursState extends MinutesState
{
    public HoursState()
    {
        label = "Hours";
        
        value = "1";        
    }
} public class MinutesState extends RootState
{
    protected int delta = 1;
    
    public MinutesState()
    {
        label = "Minutes";
        value = "5";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        Integer i = Integer.valueOf(value);

        i -= delta;
        
        value = String.valueOf(i);
        
        TimeLapseStates.setTimelapse(camera, this);
        
        String className = getClass().getSimpleName();
        System.out.println(className + " decremented minute value.");
        
        return this;
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        Integer i = Integer.valueOf(value);
        i += delta;
        
        value = String.valueOf(i);
        
        TimeLapseStates.setTimelapse(camera, this);
        
        String className = getClass().getSimpleName();
        System.out.println(className + " incremented minute value.");
        
        return this;
    }
    
    @Override
    public PhotoramaState upButton()
    {
        PhotoramaState upState = super.upButton();
        
        camera.stopTimelapse();
        
        return upState;
    }
} public class SecondsState extends MinutesState
{
    public SecondsState()
    {
        label = "Seconds";
        
        value = "30";
    }
} public class TimeLapseHoursState extends TimeLapseStates
{
    public TimeLapseHoursState()
    {
        value = "<- Hours";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        return leftState;
    }
} public class TimeLapseMinutesState extends TimeLapseStates
{
    public TimeLapseMinutesState()
    {
        value = "<- Minutes ->";
    }
    
    @Override
    public PhotoramaState leftButton()
    {
        return leftState;
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        return rightState;
    }
} public class TimeLapseSecondsState extends TimeLapseStates
{
    public TimeLapseSecondsState()
    {
        value = "Seconds ->";
    }
    
    @Override
    public PhotoramaState rightButton()
    {
        return rightState;
    }
}
import org.onebeartoe.electronics.photorama.states.mode.ModeSnapshotState;
import org.onebeartoe.electronics.photorama.states.raspberry.pi.RaspberryPiShutdownState;
import org.onebeartoe.electronics.photorama.states.raspberry.pi.RaspberryPiOnState;
import org.onebeartoe.electronics.photorama.states.raspberry.pi.RaspberryPiConfirmShutdownState;
import org.onebeartoe.electronics.photorama.states.PhotoramaModeState;
import org.onebeartoe.electronics.photorama.states.PhotoramaRaspberryPiState;
import org.onebeartoe.electronics.photorama.states.PhotoramaState;
import org.onebeartoe.electronics.photorama.states.foot.pedal.SnapshotOffState;
import org.onebeartoe.electronics.photorama.states.foot.pedal.FootPedalOnState;
import org.onebeartoe.electronics.photorama.states.foot.pedal.FootPedalSnapshotState;
import org.onebeartoe.electronics.photorama.states.mode.ModeTimeLapseState;
import org.onebeartoe.electronics.photorama.states.time.lapse.HoursState;
import org.onebeartoe.electronics.photorama.states.time.lapse.MinutesState;
import org.onebeartoe.electronics.photorama.states.time.lapse.SecondsState;
import org.onebeartoe.electronics.photorama.states.time.lapse.TimeLapseHoursState;
import org.onebeartoe.electronics.photorama.states.time.lapse.TimeLapseMinutesState;
import org.onebeartoe.electronics.photorama.states.time.lapse.TimeLapseSecondsState;


package org.onebeartoe.electronics.photorama;


/**
 * @author Roberto Marquez
 */
public class Photorama 
{
    private PhotoramaState photoramaModeState;

    private Camera camera;

    public void setCamera(Camera camera)
    {
        this.camera = camera;
    }
    
    public Photorama(Camera camera)
    {
        this.camera = camera;
        populateStates();
    }
    
    public PhotoramaState getRootState()
    {
        return photoramaModeState;
    }
    
    private void populateStates()
    {
        PhotoramaState modeFootPedalState = new ModeSnapshotState();
        
        PhotoramaState photoramaRaspberryPiState = new PhotoramaRaspberryPiState();
        
        PhotoramaState raspberryPiConfirmShutdownState = new RaspberryPiConfirmShutdownState();
        
        PhotoramaState raspberryPiShutdownState = new RaspberryPiShutdownState();
        raspberryPiShutdownState.setSelectButton(raspberryPiConfirmShutdownState);

        raspberryPiConfirmShutdownState.setUpButton(raspberryPiShutdownState);
        
        PhotoramaState raspberryPiOnState = new RaspberryPiOnState();
        
        raspberryPiOnState.setRightButton(raspberryPiShutdownState);
        raspberryPiOnState.setUpButton(photoramaRaspberryPiState);
        
        raspberryPiShutdownState.setLeftButton(raspberryPiOnState);
        
        // this is the root state
        photoramaModeState = new PhotoramaModeState();
        photoramaModeState.setRightButton(photoramaRaspberryPiState);
        photoramaModeState.setSelectButton(modeFootPedalState);
        photoramaModeState.setCamera(camera);
        
        photoramaRaspberryPiState.setLeftButton(photoramaModeState);
        photoramaRaspberryPiState.setSelectButton(raspberryPiOnState);
        
        PhotoramaState footPedalOnState = new FootPedalOnState();
        
        PhotoramaState snapshotOffState = new SnapshotOffState();
        snapshotOffState.setLeftButton(footPedalOnState);
        snapshotOffState.setUpButton(modeFootPedalState);
        
        PhotoramaState footPedalSnapshotState = new FootPedalSnapshotState();
        footPedalSnapshotState.setUpButton(footPedalOnState);
        
        footPedalOnState.setUpButton(modeFootPedalState);
        footPedalOnState.setSelectButton(footPedalSnapshotState);
        footPedalOnState.setRightButton(snapshotOffState);

        PhotoramaState secondsState = new SecondsState();

        PhotoramaState timeLapseSecondsState = new TimeLapseSecondsState();
        timeLapseSecondsState.setSelectButton(secondsState);
        
        secondsState.setUpButton(timeLapseSecondsState);
        
        PhotoramaState hoursState = new HoursState();
        
        PhotoramaState timeLapseHoursState = new TimeLapseHoursState();
        timeLapseHoursState.setSelectButton(hoursState);
        
        hoursState.setUpButton(timeLapseHoursState);
        
        MinutesState minutesState = new MinutesState();
        minutesState.setCamera(camera);


        PhotoramaState timeLapseMinutesState = new TimeLapseMinutesState();
