/*
 Slide show designed to illustrate the use of arrays
 Written 10/19/99 by Kim Bruce
 Modified 4/7/02 by Andrea Danyluk
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import objectdraw.*;

public class SlidesF09 extends WindowController implements ActionListener {

	private static final int NUM_SLIDES = 7; // number of slides to be shown
	private static final double X_IMAGE = 50; // coordinates to display slides
	private static final double Y_IMAGE = 50;

	private Image[] image; // array of images for slides
	private VisibleImage[] slide; // array of drawable images for slides

	private JButton next; // buttons to go to next and previous slides

	private int current; // keeps track of which slide is showing
	private RandomIntGenerator slideGen; // generates random slides for show

	// Set up drawable images for display. Only show first. Create buttons for
	// moving through slides.
	public void begin() {
		Container contentPane = getContentPane();
		image = new Image[NUM_SLIDES]; // Load the images
		image[0] = getImage("rett.jpg");
		image[1] = getImage("kim.gif");
		image[2] = getImage("dave.jpg");
		image[3] = getImage("yi.jpg");
		image[4] = getImage("sara.jpg");
		image[5] = getImage("lori.jpg");
		image[6] = getImage("matt.jpg");

		slide = new VisibleImage[NUM_SLIDES]; // Create (and hide) drawable
		
		// images
		for (int counter = 0; counter < NUM_SLIDES; counter++) {
			slide[counter] = new VisibleImage(image[counter], X_IMAGE, Y_IMAGE,
					canvas);
			slide[counter].hide();
		}

		next = new JButton("another slide"); // Create and add listener for
		next.addActionListener(this);        // slide changing button

		JPanel buttonPanel = new JPanel(); // Set up button panel
		buttonPanel.add(next);
		contentPane.add(buttonPanel, "South"); // Add button panel to window
		contentPane.validate();

		current = 0; // Set up first slide

		slide[current].show();

		slideGen = new RandomIntGenerator(0, NUM_SLIDES - 1);
	}

	// Depending on button clicked on, go to next or previous slide
	public void actionPerformed(ActionEvent event) {
		slide[current].hide(); // hide last slide
		current = slideGen.nextValue();
		slide[current].show();
	}
}