Use config for dates
This commit is contained in:
parent
b2fb461fd4
commit
61a0b623c9
4 changed files with 27 additions and 14 deletions
|
@ -21,8 +21,8 @@ public class Config {
|
|||
Map.entry("user", ""),
|
||||
Map.entry("password", "")))
|
||||
),
|
||||
Map.entry("startDate", ""),
|
||||
Map.entry("endDate", "")
|
||||
Map.entry("startDate", LocalDate.of(2021, 5, 11).toString()),
|
||||
Map.entry("endDate", LocalDate.of(2021, 5, 22).toString())
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -66,11 +66,19 @@ public class Config {
|
|||
return (JSONObject) Config.getConfig().get("db");
|
||||
}
|
||||
|
||||
static public LocalDate getStartDate() throws InvalidConfig {
|
||||
return (LocalDate) Config.getConfig().get("startDate");
|
||||
static public LocalDate getStartDate() {
|
||||
try {
|
||||
return LocalDate.parse((String) Config.getConfig().get("startDate"));
|
||||
} catch (InvalidConfig e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public LocalDate getEndDate() throws InvalidConfig {
|
||||
return (LocalDate) Config.getConfig().get("endDate");
|
||||
static public LocalDate getEndDate() {
|
||||
try {
|
||||
return LocalDate.parse((String) Config.getConfig().get("endDate"));
|
||||
} catch (InvalidConfig e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package GUI.Agenda;
|
||||
|
||||
import Config.Config;
|
||||
import DB.Competition;
|
||||
import DB.Projection;
|
||||
import DB.Slot;
|
||||
|
@ -23,7 +24,6 @@ import java.util.Arrays;
|
|||
public class Agenda extends JPanel {
|
||||
private JPanel agendaPanel;
|
||||
private Object headers[];
|
||||
private int totalDay;
|
||||
private int currentPage;
|
||||
private JTable table;
|
||||
private CompetType competionType;
|
||||
|
@ -36,7 +36,6 @@ public class Agenda extends JPanel {
|
|||
this.agendaPanel = agendaPanel;
|
||||
this.slots = competionType.getSlots();
|
||||
this.headers = slots.toArray();
|
||||
this.totalDay = 11;
|
||||
this.currentPage = currentPage;
|
||||
this.competionType = competionType;
|
||||
this.agendaPanel.removeAll();
|
||||
|
@ -65,7 +64,8 @@ public class Agenda extends JPanel {
|
|||
}
|
||||
|
||||
private int[] dayToPage() {
|
||||
int day = this.totalDay;
|
||||
int totalDay = Config.getEndDate().compareTo(Config.getStartDate());
|
||||
int day = totalDay;
|
||||
int count = 0;
|
||||
while (day >= 5) {
|
||||
day = day - 5;
|
||||
|
@ -87,7 +87,7 @@ public class Agenda extends JPanel {
|
|||
return headers[index];
|
||||
}
|
||||
};
|
||||
TableModel dm = new TableModel(day, currentPage, headers.length);
|
||||
TableModel dm = new TableModel(day, currentPage);
|
||||
table = new JTable(dm) {
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package GUI.Agenda;
|
||||
|
||||
import Config.Config;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
|
@ -7,15 +9,17 @@ import java.util.Arrays;
|
|||
public class TableModel extends AbstractTableModel {
|
||||
private LocalDate[] columnNames;
|
||||
private Object[][] data;
|
||||
private int headerSize;
|
||||
private int day;
|
||||
|
||||
public TableModel(int day, int currentPage, int headerSize) {
|
||||
public TableModel(int day, int currentPage) {
|
||||
this.day = day;
|
||||
columnNames = new LocalDate[this.day];
|
||||
data = new Object[5][this.day];
|
||||
|
||||
LocalDate startDate = Config.getStartDate();
|
||||
|
||||
for (int i = 0; i < this.day; i++) {
|
||||
this.columnNames[i] = LocalDate.of(2021, 05, (i + 11) + (5 * (currentPage)));
|
||||
this.columnNames[i] = startDate.plusDays(i + 5 * (currentPage));
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Arrays.fill(data[i], "");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package GUI;
|
||||
|
||||
import Config.Config;
|
||||
import DB.*;
|
||||
import Exceptions.NotFoundInTable;
|
||||
import Exceptions.ProjectionNotSpecified;
|
||||
|
@ -117,7 +118,7 @@ public class ProjectionHandler extends JDialog {
|
|||
roomComboBox.removeAllItems();
|
||||
Competition competition = (Competition) competitionComboBox.getSelectedItem();
|
||||
Set<Date> dates = competition.getProjections().stream().map(p -> p.getStartDate()).collect(Collectors.toSet());
|
||||
LocalDate[] localDates = LocalDate.of(2021, 5, 11).datesUntil(LocalDate.of(2021, 5, 22)).toArray(LocalDate[]::new);
|
||||
LocalDate[] localDates = Config.getStartDate().datesUntil(Config.getEndDate()).toArray(LocalDate[]::new);
|
||||
if (competition.getDays() != 0 && dates.size() >= competition.getDays() && !(projectionType == ProjectionType.EDIT && projection.getCompetition().getName().equals(competition.getName())))
|
||||
localDates = dates.stream().map(Date::toLocalDate).toArray(LocalDate[]::new);
|
||||
|
||||
|
|
Reference in a new issue