1
0
Fork 0

automatic day/slot selection when adding

This commit is contained in:
Tergel TSAGAAN 2021-01-12 14:45:38 +01:00
parent 71412f825d
commit c58cfaf148
3 changed files with 39 additions and 6 deletions

View file

@ -3,6 +3,7 @@ package GUI.Agenda;
import DB.Competition;
import DB.Projection;
import DB.Slot;
import Exceptions.NotFoundInTable;
import Exceptions.ProjectionNotSpecified;
import GUI.ProjectionHandler;
import GUI.Types.CompetType;
@ -15,6 +16,7 @@ import java.awt.*;
import java.awt.event.MouseEvent;
import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@ -27,6 +29,9 @@ public class Agenda extends JPanel {
private CompetType competionType;
private Agenda agenda;
private ArrayList<Slot> slots;
private Slot currentSlot;
private LocalDate currentDay;
public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) {
this.agendaPanel = agendaPanel;
this.slots = competionType.getSlots();
@ -78,7 +83,6 @@ public class Agenda extends JPanel {
public int getSize() {
return headers.length;
}
public Object getElementAt(int index) {
return headers[index];
}
@ -113,7 +117,11 @@ public class Agenda extends JPanel {
@Override
public void mousePressed(MouseEvent mouseEvent) {
Object currentCellValue = table.getValueAt(table.rowAtPoint(mouseEvent.getPoint()), table.getTableHeader().columnAtPoint(mouseEvent.getPoint()));
int row = table.rowAtPoint(mouseEvent.getPoint());
int column = table.getTableHeader().columnAtPoint(mouseEvent.getPoint());
currentDay = dm.getColumn(column);
currentSlot = (Slot) lm.getElementAt(row);
Object currentCellValue = table.getValueAt(row, column);
Projection projection = null;
if (currentCellValue.getClass() == Projection.class)
projection = (Projection) currentCellValue;
@ -194,4 +202,16 @@ public class Agenda extends JPanel {
public int getCurrentPage() {
return this.currentPage;
}
public Competition getCompetition() throws NotFoundInTable {
return new Competition(competionType.getCompetition());
}
public Slot getSlot() {
return currentSlot;
}
public LocalDate getDate() {
return currentDay;
}
}

View file

@ -1,25 +1,27 @@
package GUI.Agenda;
import javax.swing.table.AbstractTableModel;
import java.time.LocalDate;
import java.util.Arrays;
public class TableModel extends AbstractTableModel {
private String[] columnNames;
private LocalDate[] columnNames;
private Object[][] data;
private int headerSize;
private int day;
public TableModel(int day, int currentPage, int headerSize) {
this.day = day;
columnNames = new String[this.day];
columnNames = new LocalDate[this.day];
data = new Object[5][this.day];
for (int i = 0; i < this.day; i++) {
this.columnNames[i] = String.format("2021-05-%d", 10 + (i + 1) + (5 * (currentPage)));
this.columnNames[i] = LocalDate.of(2021, 05, (i + 11) + (5 * (currentPage)));
}
for (int i = 0; i < 5; i++) {
Arrays.fill(data[i], "");
}
}
@Override
public int getRowCount() {
return data.length;
@ -30,9 +32,13 @@ public class TableModel extends AbstractTableModel {
return columnNames.length;
}
public LocalDate getColumn(int column) {
return columnNames[column];
}
@Override
public String getColumnName(int column) {
return columnNames[column];
return columnNames[column].toString();
}
@Override

View file

@ -1,6 +1,7 @@
package GUI;
import DB.*;
import Exceptions.NotFoundInTable;
import Exceptions.ProjectionNotSpecified;
import GUI.Agenda.Agenda;
import GUI.Types.ProjectionType;
@ -44,6 +45,12 @@ public class ProjectionHandler extends JDialog {
throw new ProjectionNotSpecified();
this.projectionType = projectionType;
this.agenda = agenda;
try {
competitionComboBox.getModel().setSelectedItem(agenda.getCompetition());
} catch (NotFoundInTable ignored) {
}
dayComboBox.getModel().setSelectedItem(agenda.getDate());
slotComboBox.getModel().setSelectedItem(agenda.getSlot());
createUIComponents();
}