started creating the user class

This commit is contained in:
shaggy3007 2023-11-08 18:02:30 +01:00
parent 20c5a8de88
commit d77c241b3e
12 changed files with 155 additions and 169 deletions

View File

@ -4,6 +4,8 @@ import java.util.TreeSet;
public enum ActivityType {
Empty,
Closed,
Busy,
Retrieve,
FirstRelease,
Renew,

View File

@ -71,7 +71,11 @@ public class Date implements Comparable<Date> , Iterable<Date>{
} else if (month < 12) {
return new Date(1,++month,year);
} else return new Date(1,1,year+1);
} else {
return new Date(1,1,year+1);
}
}
};

View File

@ -16,7 +16,7 @@ public class Day implements Iterable<Day>,Comparable<Day> {
this.Name = Days.values()[ordinal-1];
this.date = date;
for (int i = 0 ; i < 6 ; i++) {
Slots.add(new Slot(ActivityType.Empty));
Slots.add(new Slot((Name.equals(Days.Sunday)||Name.equals(Days.Saturday))? ActivityType.Closed:ActivityType.Empty));
}
}

View File

@ -49,7 +49,7 @@ public class Year implements Comparable<Year>,Iterable<Year> {
}
public int nextYear() {
return year++;
return year+1;
}
public String toString() {
@ -62,6 +62,8 @@ public class Year implements Comparable<Year>,Iterable<Year> {
public TreeSet<Month> getMonths() {
return YMonths;
}
public int getYear() {
return year;
}
}

View File

@ -2,6 +2,7 @@ package ClientApp;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import Calendar.ActivityType;
import Calendar.Date;
@ -10,6 +11,8 @@ import Calendar.Month;
import Calendar.Slot;
import Calendar.Week;
import Calendar.Year;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@ -21,8 +24,9 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class ActivitySelector extends AbstractAppPane{
public class ActivitySelector extends AbstractAppPane {
private HBox Layout = new HBox();
private TreeSet<Year> years;
private Year year;
private Date date;
private Week week;
@ -32,31 +36,27 @@ public class ActivitySelector extends AbstractAppPane{
private Map<Day,HashMap<Slot,ComboBox<ActivityType>>> WeekMap = new HashMap<>();
private Scene Original;
public ActivitySelector (Year year,Date date) {
this.year = year;
public ActivitySelector (TreeSet<Year> years,Date date) {
this.years = years;
this.date = date;
Original = scena;
textFill();
//precWeek = new ActivitySelector(year,week.getWeekDays().first().getDate().getPrec());
Layout.autosize();
gridSetup();
scena.setRoot(this.Layout);
//System.out.println("DioB");
}
public ActivitySelector (Year year,Date date,Scene oScena) {
this.year = year;
public ActivitySelector (TreeSet<Year> years,Date date,Scene oScena) {
this.years = years;
this.date = date;
Original = oScena;
textFill();
//precWeek = new ActivitySelector(year,week.getWeekDays().first().getDate().getPrec());
Layout.autosize();
textFill();
gridSetup();
oScena.setRoot(this.Layout);
//System.out.println("DioB");
}
@Override
@ -66,80 +66,96 @@ public class ActivitySelector extends AbstractAppPane{
@Override
public void handle(ActionEvent arg0) {
System.out.println(week.getWeekDays().first().getDate().getPrec());
precWeek = new ActivitySelector(year,week.getWeekDays().first().getDate().getPrec(),Original);
//System.out.println(week.getWeekDays().first().getDate().getPrec());
try {
precWeek = new ActivitySelector(years,week.getWeekDays().first().getDate().getPrec(),Original);
}catch (Exception e) {
System.out.println(e.getMessage());
}
}
});
prec.setMinWidth(50);
Layout.getChildren().add(prec);
for (Day D : week.getWeekDays()) {
VBox DBox = new VBox();
DBox.autosize();
DBox.setMinWidth(200);
DBox.getChildren().add(new Text(D.toString()));
for (Slot S : D.getSlots()) {
DBox.getChildren().add(WeekMap.get(D).get(S));
WeekMap.get(D).get(S).setValue(S.getActivity());
WeekMap.get(D).get(S).setOnAction(new EventHandler<ActionEvent>() {
if (!S.getActivity().equals(ActivityType.Closed)) {
DBox.getChildren().add(WeekMap.get(D).get(S));
WeekMap.get(D).get(S).setValue(S.getActivity());
WeekMap.get(D).get(S).setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
S.SetActivity(WeekMap.get(D).get(S).getValue());
@Override
public void handle(ActionEvent arg0) {
S.SetActivity(WeekMap.get(D).get(S).getValue());
}
}
});
});
} else {
DBox.getChildren().add(new Text("Closed"));
}
}
Layout.getChildren().add(DBox);
}
Button next = new Button("Next");
next.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
nextWeek = new ActivitySelector(year,week.getWeekDays().last().getDate().iterator().next(),Original);
//scena.setRoot(nextWeek.getLayout());
//System.out.println("DioB");
try {
nextWeek = new ActivitySelector(years,week.getWeekDays().last().getDate().iterator().next(),Original);
}catch (Exception e) {
System.out.println(e.getMessage());
}
}
});
Layout.getChildren().add(next);
next.setMinWidth(50);
Layout.getChildren().add(next);
}
@Override
public void textFill() {
getWeek(date);
WeekMap.clear();
Activities.addAll(ActivityType.Names());
for (Day D: week.getWeekDays()) {
WeekMap.put(D,new HashMap<Slot,ComboBox<ActivityType>>());
for (Slot S: D.getSlots()) {
WeekMap.get(D).put(S, new ComboBox<ActivityType>(Activities));
}
}
}
public void getWeek(Date Wdate) {
for(Month M:year.getMonths()) {
if (M.getName().ordinal() == Wdate.getMonth()-1) {
System.out.println(M);
for(Week W:M.getWeeks()) {
if((W.getWeekDays().first().getDate().compareTo(Wdate) == -1 || W.getWeekDays().first().getDate().compareTo(Wdate) == 0) && (W.getWeekDays().last().getDate().compareTo(Wdate) == 1 || W.getWeekDays().last().getDate().compareTo(Wdate) == 0)) {
this.week = W;
break;
}
try {
getWeekandYear(date);
WeekMap.clear();
Activities.addAll(ActivityType.Names());
for (Day D: week.getWeekDays()) {
WeekMap.put(D,new HashMap<Slot,ComboBox<ActivityType>>());
for (Slot S: D.getSlots()) {
WeekMap.get(D).put(S, new ComboBox<ActivityType>(Activities));
}
}
} catch(Exception e) {
//Couldn't find the week
System.out.println("Couldn't find the week");
}
}
public void getWeekandYear(Date Wdate) throws WeekNotFoundException{
for(Year Y:years) {
if (Y.getYear()==Wdate.getYear()) {
year = Y;
for(Month M:year.getMonths()) {
if (M.getName().ordinal() == Wdate.getMonth()-1) {
//System.out.println(M);
for(Week W:M.getWeeks()) {
if((W.getWeekDays().first().getDate().compareTo(Wdate) == -1 || W.getWeekDays().first().getDate().compareTo(Wdate) == 0) && (W.getWeekDays().last().getDate().compareTo(Wdate) == 1 || W.getWeekDays().last().getDate().compareTo(Wdate) == 0)) {
this.week = W;
return;
}
}
}
}
break;
}
}
throw new WeekNotFoundException();
}
public HBox getLayout() {
return Layout;

View File

@ -13,8 +13,6 @@ import javafx.stage.Stage;
public class ErrorPane extends AbstractAppPane {
private String ErrorMessage;
private Stage ErrorStage = new Stage();
private Map<String,Text> Texts = new HashMap<>();
private Map<Text,Node> Fields = new HashMap<>();
public ErrorPane(String ErrorMessage) {
this.ErrorMessage = ErrorMessage;
gridSetup();

View File

@ -0,0 +1,5 @@
package ClientApp;
public class ExistingUserException extends Exception {
}

View File

@ -1,99 +0,0 @@
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

@ -1,9 +1,9 @@
package ClientApp;
import java.util.TreeSet;
import Calendar.Date;
import Calendar.Days;
import Calendar.Month;
import Calendar.Week;
import Calendar.Year;
import javafx.application.Application;
import javafx.stage.Stage;
@ -18,10 +18,24 @@ public class TestMain extends Application{
@Override
public void start(Stage stage) throws Exception {
TreeSet<Year> years = new TreeSet<>();
Year Y2023 = new Year(2023,Days.Monday);
Year Y2024 = Y2023.iterator().next();
years.add(Y2023);
years.add(Y2024);
//System.out.println(Y2023 + "\n" + Y2024);
AppPane Register = null;
try {
Register = new ActivitySelector(years,new Date(1,1,2020));
stage.setScene(Register.getScene());
stage.show();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
AppPane Register = new ActivitySelector(new Year(2023,Days.Monday),new Date(30,4,2023));
stage.setScene(Register.getScene());
stage.show();
}
}

View File

@ -0,0 +1,22 @@
package ClientApp;
import java.util.HashMap;
public class User {
private HashMap<UserDataTypes,String> UserData = new HashMap<>();
public User (HashMap<UserDataTypes,String> UserData) {
this.UserData=UserData;
}
public boolean Login(String name, String pass) {
if (name.equals(UserData.get(UserDataTypes.Nome)) && pass.equals(UserData.get(UserDataTypes.Password))) {
return true;
}
return false;
}
public String getName() {
return UserData.get(UserDataTypes.Nome);
}
public String getPassword() {
return UserData.get(UserDataTypes.Password);
}
}

View File

@ -0,0 +1,15 @@
package ClientApp;
import java.util.ArrayList;
public class UserList {
private ArrayList<User> Users = new ArrayList<>();
public void addUser(User o) throws ExistingUserException{
for (User U : Users) {
if (o.Login(U.getName(), U.getPassword())) {
throw new ExistingUserException();
}
}
Users.add(o);
}
}

View File

@ -0,0 +1,7 @@
package ClientApp;
public class WeekNotFoundException extends Exception {
private static final long serialVersionUID = 1L;
}