private String flag;
private String csvFile = "data/countries.csv";
+ public Country() {
+ }
+
+ public Country(String name) {
+ setName(name);
+ initCountryFromCSV(name);
+ }
+
public Country(String name, String region, double lat, double lng, String flag) {
setName(name);
setRegion(region);
setFlag(flag);
}
- public Country(String name) {
- setName(name);
- loadCSVOneCountry(this.name);
-
- }
-
public void setName(String name) {
this.name = name;
}
}
public int distanceTo(Country country) {
- if ((this.lat == country.lat) && (this.lng == country.lng)) {
+ if ((this.getLat() == country.getLat()) && (this.getLng() == country.getLng())) {
return 0;
} else {
- double theta = this.lng - country.lng;
- Double dist = Math.sin(Math.toRadians(this.lat)) * Math.sin(Math.toRadians(country.lat)) + Math.cos(Math.toRadians(this.lat)) * Math.cos(Math.toRadians(country.lat)) * Math.cos(Math.toRadians(theta));
+ double theta = this.getLng() - country.getLng();
+ Double dist = Math.sin(Math.toRadians(this.getLat())) * Math.sin(Math.toRadians(country.getLat())) + Math.cos(Math.toRadians(this.getLat())) * Math.cos(Math.toRadians(country.getLat())) * Math.cos(Math.toRadians(theta));
dist = Math.acos(dist);
dist = Math.toDegrees(dist);
dist = dist * 60 * 1.1515;
}
}
- public void loadCSVOneCountry(String name) {
+ private void initCountryFromCSV(String name) {
Scanner scanner = null;
try {
scanner = new Scanner(new File(csvFile));
String[] countryArray = countryList.split(",");
String latLng = line.get(16);
String[] latLngArray = latLng.split(",");
-
-
if (countryArray[1].equals(name)) {
setRegion(line.get(12));
setLat(Double.parseDouble(latLngArray[0]));
}
}
scanner.close();
- /*Utils.displayArrayList(countryArrayListOceania);
- Utils.displayArrayList(countryArrayListAfrica);
- Utils.displayArrayList(countryArrayListAmericas);
- Utils.displayArrayList(countryArrayListAsia);
- Utils.displayArrayList(countryArrayListEurope);*/
}
-
@Override
public String toString() {
return "Country{" +
{"Australia"} /* Oceania */
};
-
Origin() {
}
}
public int distanceTo(Origin origin) {
-
-
return 0;
}
}
Person() {
setFirstname(new Firstname());
setOrigin(new Origin());
+ setCountry(new Country());
setPersonSize(new Size());
setWeight(new Weight());
setEye(new Eye());
Person(String firstname, String country, Integer size, Integer weight, String colorEye) {
setFirstname(new Firstname(firstname));
setOrigin(new Origin(country));
+ setCountry(new Country(country));
setPersonSize(new Size(size));
setWeight(new Weight(weight));
setEye(new Eye(colorEye));
return "Person{" +
"firstname=" + firstname.getFirstname() +
", origin=" + origin.getCountry() +
- ", country=" + country +
+ ", country=" + country.getName() +
", size=" + size.getSize() +
", weight=" + weight.getWeight() +
", eye=" + eye.getStrColor() + "(" + this.getEye().getColor().getRed() + "," + this.getEye().getColor().getGreen() + "," + this.getEye().getColor().getBlue() + ")" +
this.originView = originView;
}
+ public RegionView getRegionView() {
+ return regionView;
+ }
+
public void setRegionView(RegionView regionView) {
this.regionView = regionView;
}
-
/**
* @return
*/
public void actionPerformed(ActionEvent actionEvent) {
//TODO: one can implement a smarter way of getting all inputs values inside the main panel.
String firstname = this.getFirstnameView().getTextField().getText();
- String country = null;
- if (this.getOriginView().getComboBox().getSelectedIndex() != -1)
- country = (String) this.getOriginView().getComboBox().getSelectedObjects()[0];
+ String countryName = null;
+ if (this.getRegionView().getTree().getLastSelectedPathComponent() != null)
+ countryName = this.getRegionView().getTree().getLastSelectedPathComponent().toString();
+ /*if (this.getOriginView().getComboBox().getSelectedIndex() != -1)
+ countryName = (String) this.getOriginView().getComboBox().getSelectedObjects()[0];*/
Integer size = (Integer) this.getSizeView().getSpinner().getValue();
Integer weight = (Integer) this.getWeightView().getComboBox().getSelectedItem();
String eye_color = (String) this.getEyeView().getColorsList().getSelectedValue();
- if (firstname.equals("") || country == null || eye_color == null) {
+ if (firstname.equals("") || countryName == null || eye_color == null) {
JOptionPane.showMessageDialog(this,
"Some required fields are missing.",
"Error",
JOptionPane.ERROR_MESSAGE);
} else {
this.getPersonObj().setFirstname(new Firstname(firstname));
- this.getPersonObj().setOrigin(new Origin(country));
+ //this.getPersonObj().setOrigin(new Origin(countryName));
+ this.getPersonObj().setCountry(new Country(countryName));
this.getPersonObj().setPersonSize(new Size(size));
this.getPersonObj().setWeight(new Weight(weight));
this.getPersonObj().setEye(new Eye(eye_color));
}
}
if (node.getChildCount() > 0) {
- node = sortTree(node);
+ sortTree(node);
}
}
return root;
}
}
+ public JTree getTree() {
+ return tree;
+ }
+
public void setRegionObj(Region regionObj) {
this.regionObj = regionObj;
}