001package ca.bc.webarts.javaFX.wizard;
002
003import javafx.application.Application;
004import javafx.beans.property.*;
005import javafx.beans.value.*;
006import javafx.collections.*;
007import javafx.event.*;
008import javafx.scene.*;
009import javafx.scene.control.*;
010import javafx.scene.layout.*;
011import javafx.stage.Stage;
012
013import java.util.Stack;
014
015/** basic wizard infrastructure class */
016abstract public class Wizard extends StackPane
017{
018  private static final int UNDEFINED = -1;
019  private ObservableList<WizardPage> pages = FXCollections.observableArrayList();
020  private Stack<Integer> history = new Stack<Integer>();
021  private int curPageIdx = UNDEFINED;
022
023  public Wizard(WizardPage... nodes)
024  {
025    pages.addAll(nodes);
026    navTo(0);
027    setStyle("-fx-padding: 10; -fx-background-color: cornsilk;");
028  }
029
030  void nextPage()
031  {
032    if (hasNextPage())
033    {
034      navTo(curPageIdx + 1);
035    }
036  }
037
038  void priorPage()
039  {
040    if (hasPriorPage())
041    {
042      navTo(history.pop(), false);
043    }
044  }
045
046  boolean hasNextPage()
047  {
048    return (curPageIdx < pages.size() - 1);
049  }
050
051  boolean hasPriorPage()
052  {
053    return !history.isEmpty();
054  }
055
056  void navTo(int nextPageIdx, boolean pushHistory)
057  {
058    if (nextPageIdx < 0 || nextPageIdx >= pages.size())
059    {
060      return;
061    }
062    if (curPageIdx != UNDEFINED)
063    {
064      if (pushHistory)
065      {
066        history.push(curPageIdx);
067      }
068    }
069
070    WizardPage nextPage = pages.get(nextPageIdx);
071    curPageIdx = nextPageIdx;
072    getChildren().clear();
073    getChildren().add(nextPage);
074    nextPage.manageButtons();
075  }
076
077  void navTo(int nextPageIdx)
078  {
079    navTo(nextPageIdx, true);
080  }
081
082  void navTo(String id)
083  {
084    Node page = lookup("#" + id);
085    if (page != null)
086    {
087      int nextPageIdx = pages.indexOf(page);
088      if (nextPageIdx != UNDEFINED)
089      {
090        navTo(nextPageIdx);
091      }
092    }
093  }
094
095  public void finish()
096  { }
097  public void cancel()
098  { }
099}
100
101/** Simple placeholder class for the customer entered survey response. */
102abstract class WizardData
103{
104 
105}
106