]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/WizardLayout.java
1a5a8f1b8d2b1193bbdf8eb1128efffd4e7b2f38
[GpsPrune.git] / src / tim / prune / gui / WizardLayout.java
1 package tim.prune.gui;
2
3 import java.awt.CardLayout;
4 import java.awt.Component;
5 import javax.swing.JPanel;
6
7 /**
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
10  */
11 public class WizardLayout extends CardLayout
12 {
13         private JPanel _panel = null;
14         private int    _currentCard = 0;
15         private int    _numCards = 0;
16
17         /**
18          * Constructor
19          * @param inPanel panel controlled by this layout
20          */
21         public WizardLayout(JPanel inPanel)
22         {
23                 super();
24                 _panel = inPanel;
25                 _panel.setLayout(this);
26         }
27
28         /**
29          * Add a card to this layout
30          * @param inCard
31          */
32         public void addCard(Component inCard)
33         {
34                 _panel.add(inCard, "card" + _numCards);
35                 _numCards++;
36         }
37
38         /**
39          * @return current card index (from 0)
40          */
41         public int getCurrentCardIndex() {
42                 return _currentCard;
43         }
44
45         /**
46          * Go to the first card
47          */
48         public void showFirstCard()
49         {
50                 first(_panel);
51                 _currentCard = 0;
52         }
53
54         /**
55          * Go to the next card
56          */
57         public void showNextCard()
58         {
59                 if (_currentCard < (_numCards-1))
60                 {
61                         next(_panel);
62                         _currentCard++;
63                 }
64         }
65
66         /**
67          * Go to the previous card
68          */
69         public void showPreviousCard()
70         {
71                 if (_currentCard > 0)
72                 {
73                         previous(_panel);
74                         _currentCard--;
75                 }
76         }
77
78         /**
79          * @return true if this is the first card
80          */
81         public boolean isFirstCard() {
82                 return _currentCard == 0;
83         }
84
85         /**
86          * @return true if this is the last card
87          */
88         public boolean isLastCard() {
89                 return _currentCard == (_numCards-1);
90         }
91
92         /**
93          * @param inIndex index (from 0) of the card to show
94          */
95         public void showCard(int inIndex)
96         {
97                 if (inIndex >= 0 && inIndex < _numCards) {
98                         show(_panel, "card" + inIndex);
99                         _currentCard = inIndex;
100                 }
101         }
102 }