Implement and modify to display JTree with countries
[Persons_Comparator.git] / src / RegionView.java
index 1a28f5a3c5100d0826619f3717def39b197c7493..25b646dc19c1fd9508ccce3dbf723e6b98a5522d 100644 (file)
@@ -1,13 +1,65 @@
 import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import java.util.ListIterator;
 
 public class RegionView extends JPanel {
     private Region regionObj;
-    private JLabel label;
+    //private JLabel label;
+    private JTree tree;
 
     RegionView(Region regionObj) {
         setRegionObj(regionObj);
-        this.label = new JLabel();
-        this.label.setText("Region");
+        DefaultMutableTreeNode top = new DefaultMutableTreeNode("Region");
+
+        for (String continent : regionObj.getContinents()) {
+            DefaultMutableTreeNode topContinent = new DefaultMutableTreeNode(continent);
+            System.out.println(continent.equals("Europe"));
+
+            if (continent.equals("Europe")) {
+                ListIterator<Country> iter = regionObj.getCountryArrayListEurope().listIterator();
+                while (iter.hasNext()) {
+                    Country countryCursor = iter.next();
+                    topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
+                    top.add(topContinent);
+
+                }
+            } else if (continent.equals("Africa")) {
+                ListIterator<Country> iter = regionObj.getCountryArrayListAfrica().listIterator();
+                while (iter.hasNext()) {
+                    Country countryCursor = iter.next();
+                    topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
+                    top.add(topContinent);
+
+                }
+            } else if (continent.equals("Americas")) {
+                ListIterator<Country> iter = regionObj.getCountryArrayListAmericas().listIterator();
+                while (iter.hasNext()) {
+                    Country countryCursor = iter.next();
+                    topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
+                    top.add(topContinent);
+
+                }
+            } else if (continent.equals("Asia")) {
+                ListIterator<Country> iter = regionObj.getCountryArrayListAsia().listIterator();
+                while (iter.hasNext()) {
+                    Country countryCursor = iter.next();
+                    topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
+                    top.add(topContinent);
+
+                }
+            } else if (continent.equals("Oceania")) {
+                ListIterator<Country> iter = regionObj.getCountryArrayListOceania().listIterator();
+                while (iter.hasNext()) {
+                    Country countryCursor = iter.next();
+                    topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
+                    top.add(topContinent);
+
+                }
+            }
+        }
+        tree = new JTree(top);
+        add(tree);
+
     }
 
     public void setRegionObj(Region regionObj) {