Added ErrorPane and implemented various node implementation on Fields

This commit is contained in:
shaggy3007 2023-10-17 13:04:57 +02:00
parent 73ee8d093a
commit b0344bbe24
4 changed files with 99 additions and 22 deletions

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.text.Text; import javafx.scene.text.Text;
@ -14,22 +14,16 @@ public abstract class AbstractAppPane implements AppPane {
protected GridPane pannello = new GridPane(); protected GridPane pannello = new GridPane();
protected Map<String,Text> Texts = new HashMap<>(); protected Map<String,Text> Texts = new HashMap<>();
protected Map<Text,TextField> Fields = new HashMap<>(); protected Map<Text,Node> Fields = new HashMap<>();
protected Scene scena = new Scene(pannello); protected Scene scena = new Scene(pannello);
protected int heigth, width, insets; protected int heigth, width, insets;
protected List<String> Names = new ArrayList<>(); protected List<String> Names = new ArrayList<>();
@Override @Override
abstract public void gridSetup(); abstract public void gridSetup();
@Override @Override
public void textFill() { abstract public void textFill();
for (String s : Names) {
Texts.put(s, new Text(s));
Fields.put(Texts.get(s), new TextField());
}
}
public Scene getScene() { public Scene getScene() {
return scena; return scena;

View File

@ -0,0 +1,42 @@
package ClientApp;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ErrorPane extends AbstractAppPane {
private String ErrorMessage;
private Stage ErrorStage = new Stage();
public ErrorPane(String ErrorMessage) {
this.ErrorMessage = ErrorMessage;
gridSetup();
ErrorStage.setScene(scena);
}
@Override
public void gridSetup() {
pannello.setMinHeight(50);
pannello.setMinWidth(200);
pannello.setPadding(new Insets(10));
pannello.setVgap(5);
pannello.setHgap(5);
pannello.setAlignment(Pos.CENTER);
pannello.add(new Text(ErrorMessage), 0, 0);
Button CloseButton = new Button("Close");
pannello.add(CloseButton, 0, 1);
CloseButton.setOnAction( e -> {
ErrorStage.close();
});
}
public Stage getErrorStage() {
return ErrorStage;
}
@Override
public void textFill() {
// TODO Auto-generated method stub
// Not used for this Pane
}
}

View File

@ -7,6 +7,8 @@ import java.util.HashMap;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class RegPane extends AbstractAppPane { public class RegPane extends AbstractAppPane {
@ -25,20 +27,25 @@ public class RegPane extends AbstractAppPane {
pannello.add(Fields.get(Texts.get(s)), 1, x++); pannello.add(Fields.get(Texts.get(s)), 1, x++);
} }
Button RegButton = new Button("Register"); Button RegButton = new Button("Register");
RegButton.setOnAction(e->{ RegButton.setOnAction( e -> {
for(String name : UserDataTypes.Names()) { for(String name : UserDataTypes.Names()) {
String out = ""; if ( Fields.get(Texts.get(name)) instanceof TextField ) {
ClientInfo.put(name,Fields.get(Texts.get(name)).getText()); ClientInfo.put(name,((TextField)Fields.get(Texts.get(name))).getText());
Fields.get(Texts.get(name)).clear(); ((TextField)Fields.get(Texts.get(name))).clear();
out += ClientInfo.get(name); }
/*ClientInfo.put(name,Fields.get(Texts.get(name)).getText());
System.out.println(out); //Fields.get(Texts.get(name)).clear();*/
}
if (!CheckRegInfo()) {
ErrorPane ErSt = new ErrorPane("Invalid Credentials");
ErSt.getErrorStage().show();
} }
}); });
pannello.add(RegButton, x++, x); pannello.add(RegButton, x++, x);
} }
public RegPane (int insets, int width, int heigth, ArrayList<String> S) { public RegPane (int insets, int width, int heigth, ArrayList<String> S) {
this.width = width; this.width = width;
this.heigth = heigth; this.heigth = heigth;
@ -49,5 +56,34 @@ public class RegPane extends AbstractAppPane {
textFill(); textFill();
gridSetup(); gridSetup();
} }
private boolean CheckRegInfo() {
//TODO
return false;
}
public void textFill() {
for (String Name : Names) {
if ( Name.equals("Luogo") ) {
Texts.put( Name, new Text(Name+" di nascità") );
Fields.put( Texts.get(Name), new TextField() );
} else if ( Name.equals("Data") ) {
Texts.put(Name, new Text(Name+" di nascità") );
Fields.put( Texts.get(Name), new TextField() );
} else if ( Name.equals("Password") ) {
Texts.put( Name, new Text(Name) );
Fields.put( Texts.get(Name), new TextField() );
} else if ( Name.equals("RPassword") ) {
Texts.put( Name, new Text("Repeat Password") );
Fields.put( Texts.get(Name), new TextField() );
} else {
Texts.put( Name, new Text(Name) );
Fields.put( Texts.get(Name), new TextField() );
}
}
}
} }

View File

@ -3,10 +3,15 @@ package ClientApp;
import java.util.ArrayList; import java.util.ArrayList;
public enum UserDataTypes { public enum UserDataTypes {
GAY, Nome,
NERO, Cognome,
FROCIO, Città,
GRASSO; Provincia,
Luogo,
Data,
Password,
RPassword;
public static ArrayList<String> Names() { public static ArrayList<String> Names() {
ArrayList<String> names = new ArrayList<>(); ArrayList<String> names = new ArrayList<>();
for (var N: UserDataTypes.values()) { for (var N: UserDataTypes.values()) {