-
Notifications
You must be signed in to change notification settings - Fork 2
/
CardJList.java
82 lines (73 loc) · 1.81 KB
/
CardJList.java
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
package editor.gui.display;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JList;
import editor.database.card.Card;
import editor.gui.settings.SettingsDialog;
/**
* This class represents an element that can display a list of cards by name.
* It cannot be edited and does not support selection.
*
* @author Alec Roelke
*/
@SuppressWarnings("serial")
public class CardJList extends JList<String>
{
/**
* List of cards to display.
*/
private List<Card> cards;
/**
* Create an empty CardJList.
*/
public CardJList()
{
this(new ArrayList<>());
}
/**
* Create a new CardJList displaying the given list of cards.
*
* @param c card list to display
*/
public CardJList(List<Card> c)
{
super();
cards = c;
setSelectionModel(new DefaultListSelectionModel()
{
{
setSelectionMode(SINGLE_SELECTION);
}
@Override
public void setSelectionInterval(int index0, int index1)
{
super.setSelectionInterval(-1, -1);
}
});
setModel(new DefaultListModel<String>()
{
@Override
public String getElementAt(int index)
{
return cards.get(index).unifiedName();
}
@Override
public int getSize()
{
return cards.size();
}
});
setVisibleRowCount(SettingsDialog.settings().editor.categories.explicits());
}
/**
* Set the list of cards to display.
*
* @param c New list to display
*/
public void setCards(List<Card> c)
{
cards = c;
}
}