]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/CardStack.java
555c5449d141afe46afda5735bb4511c4dcc68b3
[GpsPrune.git] / tim / prune / correlate / CardStack.java
1 package tim.prune.correlate;
2
3 import java.awt.CardLayout;
4 import java.awt.Component;
5
6 import javax.swing.JPanel;
7
8 /**
9  * Panel to act as a card stack
10  */
11 public class CardStack extends JPanel
12 {
13         private int _numCards = 0;
14         private int _currCard = 0;
15         private CardLayout _layout = null;
16         private static final String cardName = "card";
17
18         /**
19          * Constructor
20          */
21         public CardStack()
22         {
23                 _layout = new CardLayout();
24                 setLayout(_layout);
25         }
26
27         /**
28          * Add a card to the stack
29          * @param inComponent component to add
30          */
31         public void addCard(Component inComponent)
32         {
33                 super.add(inComponent, cardName + _numCards);
34                 _numCards++;
35         }
36
37         /**
38          * @return current card index, starting from 0
39          */
40         public int getCurrentCardIndex()
41         {
42                 return _currCard;
43         }
44
45         /**
46          * @return number of cards in the stack
47          */
48         public int getNumCards()
49         {
50                 return _numCards;
51         }
52
53         /**
54          * Show the specified card
55          * @param inIndex index of card, starting from 0
56          */
57         public void showCard(int inIndex)
58         {
59                 if (inIndex >= 0 && inIndex < _numCards) {
60                         _currCard = inIndex;
61                         _layout.show(this, cardName + inIndex);
62                 }
63         }
64 }