From 1fae90780c1ff433f6bda5c687f54c352ef435e8 Mon Sep 17 00:00:00 2001 From: shaggy3007 Date: Tue, 31 Oct 2023 12:56:10 +0100 Subject: [PATCH] added Activity selector not working completely --- Elaborato_IS/src/Calendar/ActivityType.java | 7 +- Elaborato_IS/src/Calendar/Calendar.java | 5 - Elaborato_IS/src/Calendar/Date.java | 11 ++ Elaborato_IS/src/Calendar/Day.java | 10 +- Elaborato_IS/src/Calendar/Slot.java | 14 ++ Elaborato_IS/src/Calendar/Year.java | 5 +- .../src/ClientApp/AbstractAppPane.java | 3 +- .../src/ClientApp/ActivitySelector.java | 128 ++++++++++++++++++ Elaborato_IS/src/ClientApp/ErrorPane.java | 6 + Elaborato_IS/src/ClientApp/LoginPage.java | 8 ++ Elaborato_IS/src/ClientApp/RegPane.java | 4 + Elaborato_IS/src/ClientApp/SlotsName.java | 10 ++ Elaborato_IS/src/ClientApp/TestMain.java | 10 +- 13 files changed, 204 insertions(+), 17 deletions(-) delete mode 100644 Elaborato_IS/src/Calendar/Calendar.java create mode 100644 Elaborato_IS/src/Calendar/Slot.java create mode 100644 Elaborato_IS/src/ClientApp/ActivitySelector.java create mode 100644 Elaborato_IS/src/ClientApp/SlotsName.java diff --git a/Elaborato_IS/src/Calendar/ActivityType.java b/Elaborato_IS/src/Calendar/ActivityType.java index 9b51752..3e8c3d6 100644 --- a/Elaborato_IS/src/Calendar/ActivityType.java +++ b/Elaborato_IS/src/Calendar/ActivityType.java @@ -3,16 +3,17 @@ package Calendar; import java.util.TreeSet; public enum ActivityType { + Empty, Retrieve, FirstRelease, Renew, Shipment, Lost, Ruined; - public TreeSet Names () { - TreeSet TMP = new TreeSet<>(); + public static TreeSet Names () { + TreeSet TMP = new TreeSet<>(); for (var name: ActivityType.values()) { - TMP.add(name.toString()); + TMP.add(name); } return TMP; } diff --git a/Elaborato_IS/src/Calendar/Calendar.java b/Elaborato_IS/src/Calendar/Calendar.java deleted file mode 100644 index 70e7e92..0000000 --- a/Elaborato_IS/src/Calendar/Calendar.java +++ /dev/null @@ -1,5 +0,0 @@ -package Calendar; - -public class Calendar { - -} diff --git a/Elaborato_IS/src/Calendar/Date.java b/Elaborato_IS/src/Calendar/Date.java index 3602c30..6b30be4 100644 --- a/Elaborato_IS/src/Calendar/Date.java +++ b/Elaborato_IS/src/Calendar/Date.java @@ -88,6 +88,17 @@ public class Date implements Comparable , Iterable{ public String toString() { return day + "/" + month + "/" + year; } + public Date getPrec() { + if (day == 1) { + if (month == 1) { + return new Date(DaysInMonth[11],12,year-1); + } else { + return new Date(DaysInMonth[month-2],month-1,year); + } + } else { + return new Date(day-1,month,year); + } + } } diff --git a/Elaborato_IS/src/Calendar/Day.java b/Elaborato_IS/src/Calendar/Day.java index 491cb2f..c400555 100644 --- a/Elaborato_IS/src/Calendar/Day.java +++ b/Elaborato_IS/src/Calendar/Day.java @@ -1,5 +1,6 @@ package Calendar; +import java.util.ArrayList; import java.util.Iterator; public class Day implements Iterable,Comparable { @@ -7,12 +8,17 @@ public class Day implements Iterable,Comparable { private Days Name; private int ordinal; private Date date; + private ArrayList Slots = new ArrayList<>(); public Day (Date date, int ordinal) { this.ordinal = ordinal; this.Name = Days.values()[ordinal-1]; this.date = date; + for (int i = 0 ; i < 6 ; i++) { + Slots.add(new Slot(ActivityType.Empty)); + } + } @Override @@ -54,5 +60,7 @@ public class Day implements Iterable,Comparable { public String toString() { return Name.toString() + ": " + date.toString(); } - + public ArrayList getSlots() { + return Slots; + } } diff --git a/Elaborato_IS/src/Calendar/Slot.java b/Elaborato_IS/src/Calendar/Slot.java new file mode 100644 index 0000000..6c3856f --- /dev/null +++ b/Elaborato_IS/src/Calendar/Slot.java @@ -0,0 +1,14 @@ +package Calendar; + +public class Slot { + private ActivityType Activity; + public Slot(ActivityType Activity) { + this.Activity = Activity; + } + public void SetActivity(ActivityType Activity) { + this.Activity = Activity; + } + public ActivityType getActivity() { + return Activity; + } +} diff --git a/Elaborato_IS/src/Calendar/Year.java b/Elaborato_IS/src/Calendar/Year.java index ffe2e1c..0866138 100644 --- a/Elaborato_IS/src/Calendar/Year.java +++ b/Elaborato_IS/src/Calendar/Year.java @@ -14,7 +14,7 @@ public class Year implements Comparable,Iterable { Month tmpMonth = new Month(year,1,firstDay); YMonths.add(tmpMonth); while (tmpMonth.getName().ordinal() < Months.December.ordinal()) { - System.out.println(tmpMonth); + tmpMonth = tmpMonth.iterator().next(); YMonths.add(tmpMonth); } @@ -59,6 +59,9 @@ public class Year implements Comparable,Iterable { } return out; } + public TreeSet getMonths() { + return YMonths; + } } diff --git a/Elaborato_IS/src/ClientApp/AbstractAppPane.java b/Elaborato_IS/src/ClientApp/AbstractAppPane.java index 9849ed2..b2aa4cf 100644 --- a/Elaborato_IS/src/ClientApp/AbstractAppPane.java +++ b/Elaborato_IS/src/ClientApp/AbstractAppPane.java @@ -17,8 +17,7 @@ import javafx.scene.text.Text; public abstract class AbstractAppPane implements AppPane { protected GridPane pannello = new GridPane(); - protected Map Texts = new HashMap<>(); - protected Map Fields = new HashMap<>(); + protected Scene scena = new Scene(pannello); protected int heigth, width, insets; diff --git a/Elaborato_IS/src/ClientApp/ActivitySelector.java b/Elaborato_IS/src/ClientApp/ActivitySelector.java new file mode 100644 index 0000000..150c50a --- /dev/null +++ b/Elaborato_IS/src/ClientApp/ActivitySelector.java @@ -0,0 +1,128 @@ +package ClientApp; + +import java.util.HashMap; +import java.util.Map; + +import Calendar.ActivityType; +import Calendar.Date; +import Calendar.Day; +import Calendar.Month; +import Calendar.Slot; +import Calendar.Week; +import Calendar.Year; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; + +public class ActivitySelector extends AbstractAppPane{ + private HBox Layout = new HBox(); + private Year year; + private Date date; + private Week week; + private ObservableList Activities = FXCollections.observableArrayList(); + private Map>> WeekMap = new HashMap<>(); + + public ActivitySelector (Year year,Date date) { + this.year = year; + this.date = date; + Layout.autosize(); + textFill(); + gridSetup(); + scena.setRoot(Layout); + } + public ActivitySelector (Year year,Date date, int Flag) { + this.year = year; + this.date = date; + Layout.autosize(); + textFill(); + gridSetup(); + + } + + @Override + public void gridSetup() { + Button prec = new Button("Previous"); + prec.setOnAction(new EventHandler() { + + @Override + public void handle(ActionEvent arg0) { + ActivitySelector prec = new ActivitySelector(year,week.getWeekDays().first().getDate().getPrec()); + scena.setRoot(prec.getLayout()); + } + + }); + Layout.getChildren().add(prec); + for (Day D : week.getWeekDays()) { + VBox DBox = new VBox(); + DBox.autosize(); + 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(ActivityType.Empty); + WeekMap.get(D).get(S).setOnAction(new EventHandler() { + + @Override + public void handle(ActionEvent arg0) { + S.SetActivity(WeekMap.get(D).get(S).getValue()); + + } + + }); + } + Layout.getChildren().add(DBox); + } + Button next = new Button("Next"); + next.setOnAction(new EventHandler() { + + @Override + public void handle(ActionEvent arg0) { + ActivitySelector next = new ActivitySelector(year,week.getWeekDays().last().getDate().iterator().next(),1); + scena.setRoot(next.getLayout()); + } + + }); + 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>()); + for (Slot S: D.getSlots()) { + WeekMap.get(D).put(S, new ComboBox(Activities)); + } + } + + + + + } + public void getWeek(Date Wdate) { + for(Month M:year.getMonths()) { + if (M.getName().ordinal() == date.getMonth()-1) { + for(Week W:M.getWeeks()) { + if((W.getWeekDays().first().getDate().compareTo(date) == -1 || W.getWeekDays().first().getDate().compareTo(date) == 0) && (W.getWeekDays().last().getDate().compareTo(date) == 1 || W.getWeekDays().last().getDate().compareTo(date) == 0)) { + this.week = W; + } + break; + } + break; + } + } + } + public HBox getLayout() { + return Layout; + } +} diff --git a/Elaborato_IS/src/ClientApp/ErrorPane.java b/Elaborato_IS/src/ClientApp/ErrorPane.java index 642389c..e7288d8 100644 --- a/Elaborato_IS/src/ClientApp/ErrorPane.java +++ b/Elaborato_IS/src/ClientApp/ErrorPane.java @@ -1,7 +1,11 @@ package ClientApp; +import java.util.HashMap; +import java.util.Map; + import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.text.Text; import javafx.stage.Stage; @@ -9,6 +13,8 @@ import javafx.stage.Stage; public class ErrorPane extends AbstractAppPane { private String ErrorMessage; private Stage ErrorStage = new Stage(); + private Map Texts = new HashMap<>(); + private Map Fields = new HashMap<>(); public ErrorPane(String ErrorMessage) { this.ErrorMessage = ErrorMessage; gridSetup(); diff --git a/Elaborato_IS/src/ClientApp/LoginPage.java b/Elaborato_IS/src/ClientApp/LoginPage.java index 0f8f8d9..fa182da 100644 --- a/Elaborato_IS/src/ClientApp/LoginPage.java +++ b/Elaborato_IS/src/ClientApp/LoginPage.java @@ -1,6 +1,14 @@ package ClientApp; +import java.util.HashMap; +import java.util.Map; + +import javafx.scene.Node; +import javafx.scene.text.Text; + public class LoginPage extends AbstractAppPane { + private Map Texts = new HashMap<>(); + private Map Fields = new HashMap<>(); @Override public void gridSetup() { diff --git a/Elaborato_IS/src/ClientApp/RegPane.java b/Elaborato_IS/src/ClientApp/RegPane.java index 2b99103..3a5a2d0 100644 --- a/Elaborato_IS/src/ClientApp/RegPane.java +++ b/Elaborato_IS/src/ClientApp/RegPane.java @@ -4,6 +4,7 @@ package ClientApp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -13,6 +14,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.DatePicker; @@ -30,6 +32,8 @@ public class RegPane extends AbstractAppPane { private FileToMap FTM = new FileToMap(); private ObservableList CityItems = FXCollections.observableArrayList(); private ComboBox CityBox = new ComboBox<>(CityItems); + private Map Texts = new HashMap<>(); + private Map Fields = new HashMap<>(); private void fillCountries(Iterable CountriesNames) { for (String Name: CountriesNames) { diff --git a/Elaborato_IS/src/ClientApp/SlotsName.java b/Elaborato_IS/src/ClientApp/SlotsName.java new file mode 100644 index 0000000..ae39281 --- /dev/null +++ b/Elaborato_IS/src/ClientApp/SlotsName.java @@ -0,0 +1,10 @@ +package ClientApp; + +public enum SlotsName { + First, + Second, + Third, + Fourth, + Fifth, + Sixth; +} diff --git a/Elaborato_IS/src/ClientApp/TestMain.java b/Elaborato_IS/src/ClientApp/TestMain.java index 6f2723f..f816768 100644 --- a/Elaborato_IS/src/ClientApp/TestMain.java +++ b/Elaborato_IS/src/ClientApp/TestMain.java @@ -1,10 +1,10 @@ package ClientApp; -import java.util.ArrayList; - +import Calendar.Date; +import Calendar.Days; +import Calendar.Year; import javafx.application.Application; import javafx.stage.Stage; -import java.util.function.*; public class TestMain extends Application{ public static void main(String args[]) { @@ -14,9 +14,9 @@ public class TestMain extends Application{ @Override public void start(Stage stage) throws Exception { - AppPane Register = new RegPane(10, 500, 500,UserDataTypes.Names()); + AppPane Register = new ActivitySelector(new Year(2023,Days.Monday),new Date(3,3,2023)); stage.setScene(Register.getScene()); stage.show(); - } + } }