added nation and city selector
This commit is contained in:
parent
c7548bdf96
commit
2fe42dc224
|
@ -1,15 +1,15 @@
|
|||
package ClientApp;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
public class FileToMap {
|
||||
|
||||
private Map<String, List<String>> mymap = new HashMap<>();
|
||||
private Map<String, Set<String>> mymap = new HashMap<>();
|
||||
|
||||
public Map<String, List<String>> getMap() {
|
||||
public Map<String, Set<String>> getMap() {
|
||||
try (FileReader fr = new FileReader("Elaborato_IS/src/Data/città.txt")) {
|
||||
BufferedReader reader = new BufferedReader(fr);
|
||||
String line, nation, city;
|
||||
|
@ -18,7 +18,7 @@ public class FileToMap {
|
|||
pos = line.indexOf("@");
|
||||
nation = line.substring(0, pos);
|
||||
city = line.substring(pos + 1);
|
||||
mymap.putIfAbsent(nation, new ArrayList<String>());
|
||||
mymap.putIfAbsent(nation, new TreeSet<String>());
|
||||
mymap.get(nation).add(city);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -4,7 +4,10 @@ package ClientApp;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
@ -24,9 +27,9 @@ public class RegPane extends AbstractAppPane {
|
|||
private ComboBox<String> NationBox;
|
||||
private ObservableList<String> NationItems = FXCollections.observableArrayList();
|
||||
|
||||
private ComboBox<String> CityBox;
|
||||
private FileToMap FTM = new FileToMap();
|
||||
private ObservableList<String> CityItems = FXCollections.observableArrayList();
|
||||
|
||||
private ComboBox<String> CityBox = new ComboBox<>(CityItems);
|
||||
|
||||
private void fillCountries(Iterable<String> CountriesNames) {
|
||||
for (String Name: CountriesNames) {
|
||||
|
@ -34,8 +37,14 @@ public class RegPane extends AbstractAppPane {
|
|||
}
|
||||
NationBox = new ComboBox<String>(NationItems);
|
||||
}
|
||||
private void fillCities(Iterable<String> CitiesName) {
|
||||
CityItems.clear();
|
||||
for (String name: CitiesName) {
|
||||
CityItems.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void gridSetup() {
|
||||
pannello.setMinHeight(width);
|
||||
pannello.setMinWidth(heigth);
|
||||
|
@ -50,9 +59,15 @@ public class RegPane extends AbstractAppPane {
|
|||
pannello.add(Fields.get(Texts.get(name)), 1, x++);
|
||||
if (name.equals("Luogo")) {
|
||||
|
||||
((ComboBox<String>)Fields.get(Texts.get(name))).valueProperty().addListener((ObservableValue<? extends String> obs ,String oldValue, String newValue) -> {
|
||||
NationBox.valueProperty().addListener(new ChangeListener<String>() {
|
||||
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
|
||||
fillCities(FTM.getMap().get(NationBox.getValue()));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -83,9 +98,9 @@ public class RegPane extends AbstractAppPane {
|
|||
for (String s: S) {
|
||||
Names.add(s);
|
||||
}
|
||||
FileToMap FTM = new FileToMap();
|
||||
|
||||
fillCountries(FTM.getMap().keySet());
|
||||
Set<String> NationSet = new TreeSet<>();
|
||||
NationSet.addAll(FTM.getMap().keySet());
|
||||
fillCountries(NationSet);
|
||||
|
||||
textFill();
|
||||
gridSetup();
|
||||
|
@ -102,7 +117,7 @@ public class RegPane extends AbstractAppPane {
|
|||
if ( Name.equals("Luogo") ) {
|
||||
Texts.put( Name, new Text(Name+" di nascità") );
|
||||
Fields.put( Texts.get(Name), NationBox );
|
||||
} else if ( Name.equals("CittàL") ) {
|
||||
} else if ( Name.equals("Cittàl") ) {
|
||||
Texts.put( Name, new Text("Città di nascità") );
|
||||
Fields.put( Texts.get(Name), CityBox );
|
||||
} else if ( Name.equals("Data") ) {
|
||||
|
@ -111,11 +126,9 @@ public class RegPane extends AbstractAppPane {
|
|||
} else if ( Name.equals("Password") ) {
|
||||
Texts.put( Name, new Text(Name) );
|
||||
Fields.put( Texts.get(Name), new PasswordField() );
|
||||
|
||||
} else if ( Name.equals("RPassword") ) {
|
||||
Texts.put( Name, new Text("Repeat Password") );
|
||||
Fields.put( Texts.get(Name), new PasswordField() );
|
||||
|
||||
Fields.put( Texts.get(Name), new PasswordField() );
|
||||
} else {
|
||||
Texts.put( Name, new Text(Name) );
|
||||
Fields.put( Texts.get(Name), new TextField() );
|
||||
|
|
Loading…
Reference in New Issue