* Add an listener on the Weigth view.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
+import javax.swing.*;
+
public class Country {
private String name;
private String region;
private double lat;
private double lng;
-
+ private ImageIcon flag;
public Country(String name, String region, double lat, double lng) {
setName(name);
this.lng = lng;
}
+ public int distanceTo(Country country) {
+ if ((this.lat == country.lat) && (this.lng == country.lng)) {
+ 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));
+ dist = Math.acos(dist);
+ dist = Math.toDegrees(dist);
+ dist = dist * 60 * 1.1515;
+ // Kilometers
+ dist = dist * 1.609344;
+ return dist.intValue();
+ }
+ }
+
@Override
public String toString() {
return "Country{" +
public class Person implements Comparator<Person> {
private Firstname firstname;
private Origin origin;
+ private Country country;
private Size size;
private Weight weight;
private Eye eye;
return origin;
}
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
public void setPersonSize(Size size) {
this.size = size;
}
return "Person{" +
"firstname=" + firstname.getFirstname() +
", origin=" + origin.getCountry() +
+ ", country=" + country +
", size=" + size.getSize() +
", weight=" + weight.getWeight() +
", eye=" + eye.getStrColor() + "(" + this.getEye().getColor().getRed() + "," + this.getEye().getColor().getGreen() + "," + this.getEye().getColor().getBlue() + ")" +
public Integer distanceTo(Person person) {
return this.getFirstname().distanceTo(person.getFirstname()) + this.getOrigin().distanceTo(person.getOrigin())
- + this.getPersonSize().distanceTo(person.getPersonSize()) + this.getWeight().distanceTo(person.getWeight())
- + this.getEye().distanceTo(person.getEye());
+ + this.getCountry().distanceTo(person.getCountry()) + this.getPersonSize().distanceTo(person.getPersonSize())
+ + this.getWeight().distanceTo(person.getWeight()) + this.getEye().distanceTo(person.getEye());
}
@Override
try {
this.personImage = ImageIO.read(new File("data/personImage.png"));
} catch (IOException e) {
- System.out.println(e.getStackTrace());
+ e.printStackTrace();
}
}
g.fillOval(50, 50, 6, 3);
g.fillOval(62, 50, 6, 3);
}
+
+ public void drawWeight(int weight) {
+ Graphics g = this.getGraphics();
+ g.setColor(Color.black);
+ g.fillOval(44, 76, 30, (weight * 20) / 600);
+ }
}
try {
this.personImage = ImageIO.read(new File("data/personImage.png"));
} catch (IOException e) {
- System.out.println(e.getStackTrace());
+ e.printStackTrace();
}
}
int imageWidth = 120;
int imageHeight = 180;
g2d.drawImage(this.personImage.getScaledInstance(imageWidth / 2, imageHeight / 2, Image.SCALE_SMOOTH), imageWidth / 4, imageHeight / 4, this);
+ // Eyes
g2d.setColor(personObj.getEye().getColor());
g2d.fillOval(50, 50, 6, 3);
g2d.fillOval(62, 50, 6, 3);
+ // Weigth
+ g2d.setColor(Color.black);
+ g2d.fillOval(44, 76, 30, (personObj.getWeight().getWeight() * 20) / 600);
}
}
import java.util.Scanner;
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> countryArrayListAsia = new ArrayList<>();
private ArrayList<Country> countryArrayListOceania = new ArrayList<>();
-
public Region() {
this.loadCSVCountries();
}
}
public void loadCSVCountries() {
- CSVUtils csvUtils = new CSVUtils();
Scanner scanner = null;
try {
scanner = new Scanner(new File(csvFile));
e.printStackTrace();
}
while (scanner.hasNext()) {
-
- List<String> line = csvUtils.parseLine(scanner.nextLine());
-
- String c3 = line.get(0);
- String[] splitArray = c3.split(",");
- String c2 = line.get(16);
- String[] splitArray2 = c2.split(",");
-
+ List<String> line = CSVUtils.parseLine(scanner.nextLine());
+ String countryList = line.get(0);
+ String[] countryArray = countryList.split(",");
+ String latLng = line.get(16);
+ String[] latLngArray = latLng.split(",");
if (line.get(12).equals("Europe")) {
- Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
+ Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
countryArrayListEurope.add(c);
} else if (line.get(12).equals("Africa")) {
- Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
+ Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
countryArrayListAfrica.add(c);
} else if (line.get(12).equals("Americas")) {
- Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
+ Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
countryArrayListAmericas.add(c);
} else if (line.get(12).equals("Asia")) {
- Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
+ Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
countryArrayListAsia.add(c);
} else if (line.get(12).equals("Oceania")) {
- Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
+ Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
countryArrayListOceania.add(c);
}
-
-
}
scanner.close();
/*Utils.displayArrayList(countryArrayListOceania);
Utils.displayArrayList(countryArrayListAmericas);
Utils.displayArrayList(countryArrayListAsia);
Utils.displayArrayList(countryArrayListEurope);*/
-
}
-
}
\ No newline at end of file
public class RegionView extends JPanel {
private Region regionObj;
- //private JLabel label;
private JTree tree;
RegionView(Region regionObj) {
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();
Country countryCursor = iter.next();
topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
top.add(topContinent);
-
}
} else if (continent.equals("Americas")) {
ListIterator<Country> iter = regionObj.getCountryArrayListAmericas().listIterator();
Country countryCursor = iter.next();
topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
top.add(topContinent);
-
}
} else if (continent.equals("Asia")) {
ListIterator<Country> iter = regionObj.getCountryArrayListAsia().listIterator();
Country countryCursor = iter.next();
topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
top.add(topContinent);
-
}
} else if (continent.equals("Oceania")) {
ListIterator<Country> iter = regionObj.getCountryArrayListOceania().listIterator();
Country countryCursor = iter.next();
topContinent.add(new DefaultMutableTreeNode(countryCursor.getName()));
top.add(topContinent);
-
}
}
}
tree = new JTree(top);
add(tree);
-
}
public void setRegionObj(Region regionObj) {
this.regionObj = regionObj;
-
}
}
import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
-public class WeightView extends JPanel {
+public class WeightView extends JPanel implements ItemListener {
private Weight weightObj;
private JLabel label;
private JComboBox<Integer> comboBox;
this.comboBox.setSelectedItem(this.getWeightObj().getWeight());
else
this.comboBox.setSelectedItem(this.getWeightObj().getDefaultWeight());
+ this.comboBox.addItemListener(this);
add(label);
add(comboBox);
}
public JComboBox<Integer> getComboBox() {
return comboBox;
}
+
+ @Override
+ public void itemStateChanged(ItemEvent event) {
+ if (event.getStateChange() == ItemEvent.SELECTED) {
+ Object item = event.getItem();
+ PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
+ personLeftPanel.drawWeight((int) item);
+ }
+ }
}