-
Notifications
You must be signed in to change notification settings - Fork 19
/
RiskListModel.java
74 lines (50 loc) · 1.7 KB
/
RiskListModel.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
import java.util.Observer;
import java.util.Observable;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
/**
* Allows the creation of JLists with updating strings from the RiskModel.
* This class allows the creation of lists that stay updated to the lists of current
* player's hand, occupied countries, and countries adjacent to the selected, occupied
* country.
* @author Ted Mader
* @version Alpha
* @date 5/02/14
**/
public class RiskListModel extends DefaultListModel implements Observer {
private int i;
private String type;
private String display;
private ArrayList<String> stringList;
private RiskModel model;
public RiskListModel (RiskModel model, String type) {
super();
this.model = model;
this.type = type;
}
// Updates the state of the RiskList
public void update(Observable obs, Object obj) {
// System.out.println("Refreshing...");
display = (String)obj;
if (type == "cards" && type == display) {
// System.out.println("Notified cards list.");
removeAllElements();
for (i = 0; i < model.getCardsList().size(); i++) {
addElement(model.getCardsList().get(i));
}
} else if (type == "countryA" && type == display) {
// System.out.println("Notified country A list.");
removeAllElements();
for (i = 0; i < model.getCountryAList().size(); i++) {
addElement(model.getCountryAList().get(i));
}
} else if (type == "countryB" && type == display) {
// System.out.println("Notified country B list.");
removeAllElements();
for (i = 0; i < model.getCountryBList().size(); i++) {
addElement(model.getCountryBList().get(i));
}
} else {
}
}
}