Added nation and cities map

This commit is contained in:
shaggy3007 2023-10-19 16:46:43 +02:00
parent 2fdec5aaa9
commit c7548bdf96
6 changed files with 44855 additions and 20 deletions

View File

@ -9,7 +9,7 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.ComboBox;
import javafx.scene.control.SelectionMode;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
@ -21,19 +21,8 @@ public abstract class AbstractAppPane implements AppPane {
protected Map<Text,Node> Fields = new HashMap<>();
protected Scene scena = new Scene(pannello);
protected int heigth, width, insets;
protected List<String> Names = new ArrayList<>();
protected ObservableList<String> Countries = FXCollections.observableArrayList() ;
protected ListView<String> CountriesList = new ListView<>(Countries);
protected void fillCountries(Iterable<String> CountriesNames) {
for (String Name: CountriesNames) {
Countries.add(Name);
}
CountriesList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
}
abstract public void gridSetup();
@Override

View File

@ -0,0 +1,31 @@
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;
public class FileToMap {
private Map<String, List<String>> mymap = new HashMap<>();
public Map<String, List<String>> getMap() {
try (FileReader fr = new FileReader("Elaborato_IS/src/Data/città.txt")) {
BufferedReader reader = new BufferedReader(fr);
String line, nation, city;
int pos;
while ((line = reader.readLine()) != null) {
pos = line.indexOf("@");
nation = line.substring(0, pos);
city = line.substring(pos + 1);
mymap.putIfAbsent(nation, new ArrayList<String>());
mymap.get(nation).add(city);
}
} catch (Exception e) {
System.out.println("Il file città.txt non esiste");
}
return mymap;
}
}

View File

@ -0,0 +1,99 @@
package ClientApp;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class FillForm extends Application {
Text addressOne;
Text addressTwo;
Text mobileOne;
Text email;
@Override
public void start(Stage stage) throws Exception {
Label companyNameLbl = new Label("Company Name");
ComboBox<String> companyName = new ComboBox<String>();
companyName.setEditable(true);
populateCompanyName(companyName);
addComboListener(companyName);
HBox companyHbox = new HBox(25);
companyHbox.getChildren().addAll(companyNameLbl, companyName);
Label addressOneLbl = new Label("Address One");
addressOne = new Text();
HBox addressOneHbox = new HBox();
addressOneHbox.getChildren().addAll(addressOneLbl, addressOne);
Label addressTwoLbl = new Label("Address two");
addressTwo = new Text();
HBox addressTwoHbox = new HBox();
addressTwoHbox.getChildren().addAll(addressTwoLbl, addressTwo);
Label mobileLbl = new Label("Company Name");
mobileOne = new Text();
HBox mobileHbox = new HBox();
mobileHbox.getChildren().addAll(mobileLbl, mobileOne);
Label emailLbl = new Label("Company Name");
email = new Text();
HBox emailHbox = new HBox();
emailHbox.getChildren().addAll(emailLbl, email);
VBox form = new VBox(20);
form.getChildren().addAll(companyHbox, addressOneHbox, addressTwoHbox,
mobileHbox, emailHbox);
Scene scene = new Scene(form);
stage.setScene(scene);
scene.getStylesheets().add("/comboStyles.css");
stage.show();
}
private void addComboListener(final ComboBox<String> combo) {
combo.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
if (combo.getValue().equals("Apple")) {
addressOne.setText("\t Apple address one");
addressTwo.setText("\t Apple address two");
mobileOne.setText("\t Apple mobile number");
email.setText("\t Apple email");
} else {
addressOne.setText("\t tua");
addressTwo.setText("\t madre");
mobileOne.setText("\t grandissima");
email.setText("\t troia");
}
}
});
}
public void populateCompanyName(ComboBox<String> combo) {
combo.getItems().add("Intel");
combo.getItems().add("Apple");
combo.getItems().add("Microsoft");
}
public static void main(String[] args) {
launch(args);
}
}

View File

@ -3,20 +3,39 @@ package ClientApp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class RegPane extends AbstractAppPane {
private HashMap<String,String> ClientInfo = new HashMap<>();
private List<String> Names = new ArrayList<>();
private ComboBox<String> NationBox;
private ObservableList<String> NationItems = FXCollections.observableArrayList();
private ComboBox<String> CityBox;
private ObservableList<String> CityItems = FXCollections.observableArrayList();
private void fillCountries(Iterable<String> CountriesNames) {
for (String Name: CountriesNames) {
NationItems.add(Name);
}
NationBox = new ComboBox<String>(NationItems);
}
@SuppressWarnings("unchecked")
public void gridSetup() {
pannello.setMinHeight(width);
pannello.setMinWidth(heigth);
@ -31,8 +50,10 @@ public class RegPane extends AbstractAppPane {
pannello.add(Fields.get(Texts.get(name)), 1, x++);
if (name.equals("Luogo")) {
((ScrollPane)Fields.get(Texts.get(name))).setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
((ScrollPane)Fields.get(Texts.get(name))).setFitToWidth(true);
((ComboBox<String>)Fields.get(Texts.get(name))).valueProperty().addListener((ObservableValue<? extends String> obs ,String oldValue, String newValue) -> {
});
}
}
Button RegButton = new Button("Register");
@ -62,10 +83,10 @@ public class RegPane extends AbstractAppPane {
for (String s: S) {
Names.add(s);
}
ArrayList<String> TEST = new ArrayList<>();
TEST.add("China");
TEST.add("Korea");
fillCountries(TEST);
FileToMap FTM = new FileToMap();
fillCountries(FTM.getMap().keySet());
textFill();
gridSetup();
}
@ -80,7 +101,10 @@ public class RegPane extends AbstractAppPane {
for (String Name : Names) {
if ( Name.equals("Luogo") ) {
Texts.put( Name, new Text(Name+" di nascità") );
Fields.put( Texts.get(Name), new ScrollPane( CountriesList ) );
Fields.put( Texts.get(Name), NationBox );
} 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") ) {
Texts.put(Name, new Text(Name+" di nascità") );
Fields.put( Texts.get(Name), new DatePicker() );

View File

@ -8,6 +8,7 @@ public enum UserDataTypes {
Città,
Provincia,
Luogo,
Cittàl,
Data,
Password,
RPassword;

File diff suppressed because it is too large Load Diff