package org.cloudcoder.app.wizard.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.cloudcoder.app.wizard.model.Document;

public class WizardPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	
	private Document document;
	private int currentPage;

	public WizardPanel() {
		setPreferredSize(new Dimension(800, 600));

		setLayout(new BorderLayout());
		
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton prevButton = new JButton("<< Previous");
		JButton nextButton = new JButton("Next >>");
		buttonPanel.add(prevButton);
		buttonPanel.add(nextButton);
		buttonPanel.setPreferredSize(new Dimension(800, 40));
		add(buttonPanel, BorderLayout.PAGE_END);
		
		nextButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				onNext();
			}
		});
		prevButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				onPrevious();
			}
		});
	}

	protected void onNext() {
		// TODO Auto-generated method stub
		
	}

	protected void onPrevious() {
		// TODO Auto-generated method stub
		
	}

	public void setDocument(Document document) {
		this.document = document;
		// FIXME: for now, just add a single WizardPagePanel for the first Page
		WizardPagePanel panel = new WizardPagePanel();
		panel.setPage(document.get(0));
		add(panel, BorderLayout.CENTER);
		
		currentPage = 0;
	}
}

@@ -54,32 +54,60 @@
 t.BorderLayout;%0A
+import java.awt.CardLayout;%0A
 import java.awt.
@@ -373,16 +373,61 @@
 ocument;
+%0Aimport org.cloudcoder.app.wizard.model.Page;
 %0A%0Apublic
@@ -567,16 +567,101 @@
 entPage;
+%0A%09private JButton prevButton;%0A%09private JButton nextButton;%0A%09private JPanel pagePanel;
 %0A%0A%09publi
@@ -858,24 +858,21 @@
 HT));%0A%09%09
-JButton 
+this.
 prevButt
@@ -906,24 +906,21 @@
 us%22);%0A%09%09
-JButton 
+this.
 nextButt
@@ -1401,77 +1401,249 @@
 );%0A%09
-%7D%0A%0A%09protected void onNext() %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09
+%09%0A%09%09// Panel with CardLayout for displaying the WizardPagePanels%0A%09%09this.pagePanel = new JPanel();%0A%09%09pagePanel.setLayout(new CardLayout());%0A%09%09add(pagePanel, BorderLayout.CENTER);%0A%09%7D%0A%0A%09protected void onNext() %7B%0A%09%09currentPage++;%0A%09%09changePage();
 %0A%09%7D%0A
@@ -1680,45 +1680,38 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+currentPage--;%0A%09%09changePage();
 %0A%09%7D%0A
@@ -1791,80 +1791,121 @@
 ;%0A%09%09
-// FIXME: for now, just add a single WizardPagePanel for the first Page%0A
+%0A%09%09// Create WizardPagePanels%0A%09%09for (int i = 0; i %3C document.getNumPages(); i++) %7B%0A%09%09%09Page p = document.get(i);%0A%09
 %09%09Wi
@@ -1919,20 +1919,17 @@
 ePanel p
-anel
+p
  = new W
@@ -1952,95 +1952,352 @@
 ;%0A%09%09
-panel.setPage(document.get(0));%0A%09%09add(panel, BorderLayout.CENTER);%0A%09%09%0A%09%09currentPage = 0
+%09pp.setPage(p);%0A%09%09%09pagePanel.add(pp, String.valueOf(i));%0A%09%09%7D%0A%09%09%0A%09%09currentPage = 0;%0A%09%09changePage();%0A%09%7D%0A%0A%09private void changePage() %7B%0A%09%09CardLayout cl = (CardLayout) pagePanel.getLayout();%0A%09%09cl.show(pagePanel, String.valueOf(currentPage));%0A%09%09prevButton.setEnabled(currentPage %3E 0);%0A%09%09nextButton.setEnabled(currentPage %3C document.getNumPages() - 1)
 ;%0A%09%7D

support navigation between wizard pages