package breadboard.tests;

import java.io.File;
import javax.swing.JFileChooser;
import breadboards.Breadboard;
import breadboards.GImage;

public class PhotoProcessor extends Breadboard {
  
  GImage originalImage;
  GImage grayscaleImage;
  GImage negativeImage;
  GImage blurredImage;
  
  int tick;
  
  public static void main(String[] args) {
    new PhotoProcessor();
  }

  public PhotoProcessor() {
    this.getButton1().setText("Load");
    this.getButton2().setText("Cycle");
    int tick = 0;
    this.getTimer().setDelay(1000);
    this.getPanel(this.NORTH).remove(this.getTextArea());
    this.getPanel(this.SOUTH).remove(this.getTextField());
    this.getPanel(this.SOUTH).remove(this.getLabel());
  }
  
  public void onButton2Click() { //Apply Filter button was clicked...
    
    grayscaleImage = makeGrayscale(originalImage);
    negativeImage = makeNegative(originalImage);
    blurredImage = makeBlurred(originalImage);
    
    this.getTimer().start();
  }
  
  public void onTimerTick() {
    this.removeAll();

    switch(tick % 4) {
    case 0: this.add(originalImage); break;
    case 1: this.add(negativeImage); break;
    case 2: this.add(grayscaleImage); break;
    case 3: this.add(blurredImage); break;
    }

    tick = (tick + 1) % 4;
    System.out.println(tick);
  }
  
  public void onButton1Click() { //Load button was clicked
    
    //get the name of an image file the user has selected
    final JFileChooser fileChooser = new JFileChooser();
    int fileChooserAction = fileChooser.showOpenDialog(this);
    
    if (fileChooserAction == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();
      String fileName = file.getPath();
      
      //construct GImages for the original picture, and the grayscale, negative, and blurred versions
      originalImage = new GImage(fileName);
      this.add(originalImage);
      
      //adjust the window size so that the central panel area fits the picture
      this.setCenterPanelSize((int) originalImage.getImage().getWidth(), (int) originalImage.getImage().getHeight()); 
    }
  }
  
  public GImage makeGrayscale(GImage image) {
    
    ///////////////////////////
    /// Put your code here! ///
    ///////////////////////////
  }
  
  public GImage makeNegative(GImage image) {

    ///////////////////////////
    /// Put your code here! ///
    ///////////////////////////
  }
  
  public GImage makeBlurred(GImage image) {

    ///////////////////////////
    /// Put your code here! ///
    /////////////////////////// 
  }
}

