3 import java.awt.CardLayout;
4 import java.awt.Component;
5 import javax.swing.JPanel;
8 * Layout class enhancing the regular card layout to add the ability to
9 * see which is the current card, how many cards there are, previous / next etc
11 public class WizardLayout extends CardLayout
13 private JPanel _panel = null;
14 private int _currentCard = 0;
15 private int _numCards = 0;
19 * @param inPanel panel controlled by this layout
21 public WizardLayout(JPanel inPanel)
25 _panel.setLayout(this);
29 * Add a card to this layout
32 public void addCard(Component inCard)
34 _panel.add(inCard, "card" + _numCards);
39 * @return current card index (from 0)
41 public int getCurrentCardIndex() {
46 * Go to the first card
48 public void showFirstCard()
57 public void showNextCard()
59 if (_currentCard < (_numCards-1))
67 * Go to the previous card
69 public void showPreviousCard()
79 * @return true if this is the first card
81 public boolean isFirstCard() {
82 return _currentCard == 0;
86 * @return true if this is the last card
88 public boolean isLastCard() {
89 return _currentCard == (_numCards-1);
93 * @param inIndex index (from 0) of the card to show
95 public void showCard(int inIndex)
97 if (inIndex >= 0 && inIndex < _numCards) {
98 show(_panel, "card" + inIndex);
99 _currentCard = inIndex;