Commit | Line | Data |
---|---|---|
f56708fa | 1 | import javax.swing.*; |
822afd4f SP |
2 | import javax.swing.tree.DefaultMutableTreeNode; |
3 | import java.util.ListIterator; | |
f56708fa SP |
4 | |
5 | public class RegionView extends JPanel { | |
6 | private Region regionObj; | |
822afd4f SP |
7 | //private JLabel label; |
8 | private JTree tree; | |
f56708fa SP |
9 | |
10 | RegionView(Region regionObj) { | |
11 | setRegionObj(regionObj); | |
822afd4f SP |
12 | DefaultMutableTreeNode top = new DefaultMutableTreeNode("Region"); |
13 | ||
14 | for (String continent : regionObj.getContinents()) { | |
15 | DefaultMutableTreeNode topContinent = new DefaultMutableTreeNode(continent); | |
16 | System.out.println(continent.equals("Europe")); | |
17 | ||
18 | if (continent.equals("Europe")) { | |
19 | ListIterator<Country> iter = regionObj.getCountryArrayListEurope().listIterator(); | |
20 | while (iter.hasNext()) { | |
21 | Country countryCursor = iter.next(); | |
22 | topContinent.add(new DefaultMutableTreeNode(countryCursor.getName())); | |
23 | top.add(topContinent); | |
24 | ||
25 | } | |
26 | } else if (continent.equals("Africa")) { | |
27 | ListIterator<Country> iter = regionObj.getCountryArrayListAfrica().listIterator(); | |
28 | while (iter.hasNext()) { | |
29 | Country countryCursor = iter.next(); | |
30 | topContinent.add(new DefaultMutableTreeNode(countryCursor.getName())); | |
31 | top.add(topContinent); | |
32 | ||
33 | } | |
34 | } else if (continent.equals("Americas")) { | |
35 | ListIterator<Country> iter = regionObj.getCountryArrayListAmericas().listIterator(); | |
36 | while (iter.hasNext()) { | |
37 | Country countryCursor = iter.next(); | |
38 | topContinent.add(new DefaultMutableTreeNode(countryCursor.getName())); | |
39 | top.add(topContinent); | |
40 | ||
41 | } | |
42 | } else if (continent.equals("Asia")) { | |
43 | ListIterator<Country> iter = regionObj.getCountryArrayListAsia().listIterator(); | |
44 | while (iter.hasNext()) { | |
45 | Country countryCursor = iter.next(); | |
46 | topContinent.add(new DefaultMutableTreeNode(countryCursor.getName())); | |
47 | top.add(topContinent); | |
48 | ||
49 | } | |
50 | } else if (continent.equals("Oceania")) { | |
51 | ListIterator<Country> iter = regionObj.getCountryArrayListOceania().listIterator(); | |
52 | while (iter.hasNext()) { | |
53 | Country countryCursor = iter.next(); | |
54 | topContinent.add(new DefaultMutableTreeNode(countryCursor.getName())); | |
55 | top.add(topContinent); | |
56 | ||
57 | } | |
58 | } | |
59 | } | |
60 | tree = new JTree(top); | |
61 | add(tree); | |
62 | ||
f56708fa SP |
63 | } |
64 | ||
65 | public void setRegionObj(Region regionObj) { | |
66 | this.regionObj = regionObj; | |
67 | ||
68 | } | |
71754579 | 69 | } |