Skip to content

Commit

Permalink
Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
emilews committed Aug 19, 2019
1 parent d133aee commit 412d6f1
Showing 32 changed files with 497 additions and 89 deletions.
28 changes: 19 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 26 additions & 5 deletions core/src/countries/Countries.java
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@

public class Countries {
//Variables for reading from file
private BufferedReader bufferedReader = null;
private BufferedWriter bufferedWriter = null;
private static BufferedReader bufferedReader = null;
private static BufferedWriter bufferedWriter = null;
//Variable for data holder, an ArrayList that uses the Country object only
private static ArrayList<Country> data = new ArrayList<>();
//Variable for csv file name
private final String CSV_FILE_PATH = "Countries.csv";
private static final String CSV_FILE_PATH = "Countries.csv";
//Instance of data holder
private static Countries instance;
//Private constructor
@@ -58,6 +58,28 @@ public static List<String> getAllContinents(){
conts.addAll(tempList.keySet());
return conts;
}
public static List<String> getAllLangs(){
List<String> langs = new ArrayList<>();
HashMap<String, Integer> tempList = new HashMap<>();
for(int i = 0; i < data.size(); i++){
tempList.put(data.get(i).lang, i);
}
langs.addAll(tempList.keySet());
return langs;
}

public static List<String> getAllCountries(){
List<String> all = new ArrayList<>();
for(Country c : data){
StringBuilder sb = new StringBuilder();
sb.append(c.continent + ", ");
sb.append(c.name + ", ");
sb.append(c.size + ", ");
sb.append(c.lang);
all.add(sb.toString());
}
return all;
}

public List<String> getCountriesBySize(int size){
List<String> countries = new ArrayList<>();
@@ -86,10 +108,9 @@ private void populate() throws Exception {
}
}

public static void addNewCountry(String continent, String name, int size, String lang){
public static void addNewCountry(String continent, String name, int size, String lang) throws IOException {
Country c = new Country(continent, name, size, lang);
data.add(c);

}


61 changes: 61 additions & 0 deletions desktop/src/controllers/AgregarController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package controllers;

import countries.Countries;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import views.Main;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class AgregarController implements Initializable {
private Countries countries;
{
countries = Countries.getInstance();
}
static ObservableList<String> continents = FXCollections.observableArrayList();
{
continents.addAll(countries.getAllContinents());
}
@FXML
public TextField contName;
public TextField countName;
public TextField countSize;
public TextField countLang;


@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

}
public void addCountry() throws IOException {
int size = 0;
try{
size = Integer.valueOf(countSize.getText());
}catch (Exception e){
Stage stage = new Stage();
stage.setTitle("Error!");
stage.initModality(Modality.APPLICATION_MODAL);
BorderPane b = new BorderPane();
b.setCenter(new Text("That's not a number!"));
Scene scene = new Scene(b, 100,100);
stage.setScene(scene);
stage.show();
}
Countries.addNewCountry(contName.getText(),countName.getText(),Integer.valueOf(countSize.getText()),countLang.getText());
}
public void returnToMenu() throws IOException {
Main.returnToMenuFromOtherPlaces();
}
}
43 changes: 43 additions & 0 deletions desktop/src/controllers/ContinentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package controllers;

import countries.Countries;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ListView;
import views.Main;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class ContinentController implements Initializable {
private Countries countries;
{
countries = Countries.getInstance();
}
static ObservableList<String> continents = FXCollections.observableArrayList();
{
continents.addAll(countries.getAllContinents());
}
@FXML
public ChoiceBox<String> contChoice;
public ListView<String> byContinentList;


@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

}
public void populateListByContinent(){
ObservableList<String> paises = FXCollections.observableArrayList();
paises.addAll(countries.getCountriesByContinent(contChoice.getValue()));
byContinentList.getItems().clear();
byContinentList.getItems().addAll(paises);
}
public void returnToMenu() throws IOException {
Main.returnToMenuFromOtherPlaces();
}
}
28 changes: 0 additions & 28 deletions desktop/src/controllers/Controller.java

This file was deleted.

42 changes: 42 additions & 0 deletions desktop/src/controllers/LangController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package controllers;

import countries.Countries;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListView;
import views.Main;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class LangController implements Initializable {
private Countries countries;
{
countries = Countries.getInstance();
}
@FXML
public ListView<String> byLangList;
public ChoiceBox<String> langChoice;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
langChoice.getItems().clear();
langChoice.getItems().addAll(Countries.getAllLangs());
}
public void populateListByLang(){
ObservableList<String> paises = FXCollections.observableArrayList();
paises.addAll(countries.getCountriesByLang(langChoice.getValue()));
byLangList.getItems().clear();
byLangList.getItems().addAll(paises);
}
public void returnToMenu() throws IOException {
Main.returnToMenuFromOtherPlaces();
}
}
66 changes: 66 additions & 0 deletions desktop/src/controllers/SizeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package controllers;

import countries.Countries;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import views.Main;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

public class SizeController implements Initializable {
private Countries countries;
{
countries = Countries.getInstance();
}
@FXML
public ListView<String> bySizeList;
public TextField sizeTextField;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

}

public void populateListBySize(){
ObservableList<String> paises = FXCollections.observableArrayList();
int sizeToLookFor = 0;
try{
sizeToLookFor = Integer.valueOf(sizeTextField.getText());
}catch (Exception e){
Stage stage = new Stage();
stage.setTitle("Error!");
stage.initModality(Modality.APPLICATION_MODAL);
BorderPane b = new BorderPane();
b.setCenter(new Text("That's not a number!"));
Scene scene = new Scene(b, 100,100);
stage.setScene(scene);
stage.show();
}
List<String> result = countries.getCountriesBySize(sizeToLookFor);
if(result.size() != 0){
paises.addAll(result);
}else{
ObservableList<String> temp = FXCollections.observableArrayList("No existen países con una extensión de" + sizeToLookFor + " o mayor.");
}

bySizeList.getItems().clear();
bySizeList.getItems().addAll(paises);
}
public void returnToMenu() throws IOException {
Main.returnToMenuFromOtherPlaces();
}
}
Loading

0 comments on commit 412d6f1

Please sign in to comment.