this.name = name;
}
+ public String getName() {
+ return name;
+ }
+
public void setRegion(String region) {
this.region = region;
}
Person emptyPerson = new Person();
PersonView emptyPersonView = new PersonView(emptyPerson, personArrayList);
- Region r = new Region();
- r.getCsvFile();
-
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
private ArrayList<Person> personArrayList;
private FirstnameView firstnameView;
private OriginView originView;
+ private RegionView regionView;
private SizeView sizeView;
private WeightView weightView;
private EyeView eyeView;
setPersonObj(personObj);
setFirstnameView(new FirstnameView(14, this.personObj.getFirstname()));
setOriginView(new OriginView(this.personObj.getOrigin()));
+ setRegionView(new RegionView(new Region()));
setSizeView(new SizeView(this.personObj.getPersonSize()));
setWeightView(new WeightView(this.personObj.getWeight()));
setEyeView(new EyeView(this.personObj.getEye()));
eastPanel.add(eyeView);
westPanel.setLayout(new BoxLayout(this.westPanel, BoxLayout.PAGE_AXIS));
westPanel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
- westPanel.add(originView);
+ //westPanel.add(originView);
+ westPanel.add(regionView);
}
public Person getPersonObj() {
this.originView = originView;
}
+ public void setRegionView(RegionView regionView) {
+ this.regionView = regionView;
+ }
+
+
/**
* @return
*/
public class Region {
private String csvFile = "data/countries.csv";
+ private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"};
private ArrayList<Country> countryArrayListEurope = new ArrayList<>();
private ArrayList<Country> countryArrayListAfrica = new ArrayList<>();
private ArrayList<Country> countryArrayListAmericas = new ArrayList<>();
public Region() {
+ this.loadCSVCountries();
}
- public void getCsvFile() {
+ public String[] getContinents() {
+ return continents;
+ }
+
+ public ArrayList<Country> getCountryArrayListAfrica() {
+ return countryArrayListAfrica;
+ }
+
+ public ArrayList<Country> getCountryArrayListAsia() {
+ return countryArrayListAsia;
+ }
+
+ public ArrayList<Country> getCountryArrayListAmericas() {
+ return countryArrayListAmericas;
+ }
+
+ public ArrayList<Country> getCountryArrayListEurope() {
+ return countryArrayListEurope;
+ }
+
+ public ArrayList<Country> getCountryArrayListOceania() {
+ return countryArrayListOceania;
+ }
+
+ public void loadCSVCountries() {
CSVUtils csvUtils = new CSVUtils();
Scanner scanner = null;
try {
Utils.displayArrayList(countryArrayListAmericas);
Utils.displayArrayList(countryArrayListAsia);
Utils.displayArrayList(countryArrayListEurope);*/
+
}
}
\ No newline at end of file
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) {