File: WizardLayout.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (102 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package tim.prune.gui;

import java.awt.CardLayout;
import java.awt.Component;
import javax.swing.JPanel;

/**
 * Layout class enhancing the regular card layout to add the ability to
 * see which is the current card, how many cards there are, previous / next etc
 */
public class WizardLayout extends CardLayout
{
	private JPanel _panel = null;
	private int    _currentCard = 0;
	private int    _numCards = 0;

	/**
	 * Constructor
	 * @param inPanel panel controlled by this layout
	 */
	public WizardLayout(JPanel inPanel)
	{
		super();
		_panel = inPanel;
		_panel.setLayout(this);
	}

	/**
	 * Add a card to this layout
	 * @param inCard
	 */
	public void addCard(Component inCard)
	{
		_panel.add(inCard, "card" + _numCards);
		_numCards++;
	}

	/**
	 * @return current card index (from 0)
	 */
	public int getCurrentCardIndex() {
		return _currentCard;
	}

	/**
	 * Go to the first card
	 */
	public void showFirstCard()
	{
		first(_panel);
		_currentCard = 0;
	}

	/**
	 * Go to the next card
	 */
	public void showNextCard()
	{
		if (_currentCard < (_numCards-1))
		{
			next(_panel);
			_currentCard++;
		}
	}

	/**
	 * Go to the previous card
	 */
	public void showPreviousCard()
	{
		if (_currentCard > 0)
		{
			previous(_panel);
			_currentCard--;
		}
	}

	/**
	 * @return true if this is the first card
	 */
	public boolean isFirstCard() {
		return _currentCard == 0;
	}

	/**
	 * @return true if this is the last card
	 */
	public boolean isLastCard() {
		return _currentCard == (_numCards-1);
	}

	/**
	 * @param inIndex index (from 0) of the card to show
	 */
	public void showCard(int inIndex)
	{
		if (inIndex >= 0 && inIndex < _numCards) {
			show(_panel, "card" + inIndex);
			_currentCard = inIndex;
		}
	}
}