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