automatic day/slot selection when adding
This commit is contained in:
parent
71412f825d
commit
c58cfaf148
3 changed files with 39 additions and 6 deletions
|
@ -3,6 +3,7 @@ package GUI.Agenda;
|
||||||
import DB.Competition;
|
import DB.Competition;
|
||||||
import DB.Projection;
|
import DB.Projection;
|
||||||
import DB.Slot;
|
import DB.Slot;
|
||||||
|
import Exceptions.NotFoundInTable;
|
||||||
import Exceptions.ProjectionNotSpecified;
|
import Exceptions.ProjectionNotSpecified;
|
||||||
import GUI.ProjectionHandler;
|
import GUI.ProjectionHandler;
|
||||||
import GUI.Types.CompetType;
|
import GUI.Types.CompetType;
|
||||||
|
@ -15,6 +16,7 @@ import java.awt.*;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -27,6 +29,9 @@ public class Agenda extends JPanel {
|
||||||
private CompetType competionType;
|
private CompetType competionType;
|
||||||
private Agenda agenda;
|
private Agenda agenda;
|
||||||
private ArrayList<Slot> slots;
|
private ArrayList<Slot> slots;
|
||||||
|
private Slot currentSlot;
|
||||||
|
private LocalDate currentDay;
|
||||||
|
|
||||||
public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) {
|
public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) {
|
||||||
this.agendaPanel = agendaPanel;
|
this.agendaPanel = agendaPanel;
|
||||||
this.slots = competionType.getSlots();
|
this.slots = competionType.getSlots();
|
||||||
|
@ -78,7 +83,6 @@ public class Agenda extends JPanel {
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return headers.length;
|
return headers.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getElementAt(int index) {
|
public Object getElementAt(int index) {
|
||||||
return headers[index];
|
return headers[index];
|
||||||
}
|
}
|
||||||
|
@ -113,7 +117,11 @@ public class Agenda extends JPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent) {
|
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;
|
Projection projection = null;
|
||||||
if (currentCellValue.getClass() == Projection.class)
|
if (currentCellValue.getClass() == Projection.class)
|
||||||
projection = (Projection) currentCellValue;
|
projection = (Projection) currentCellValue;
|
||||||
|
@ -194,4 +202,16 @@ public class Agenda extends JPanel {
|
||||||
public int getCurrentPage() {
|
public int getCurrentPage() {
|
||||||
return this.currentPage;
|
return this.currentPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Competition getCompetition() throws NotFoundInTable {
|
||||||
|
return new Competition(competionType.getCompetition());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Slot getSlot() {
|
||||||
|
return currentSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getDate() {
|
||||||
|
return currentDay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
package GUI.Agenda;
|
package GUI.Agenda;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class TableModel extends AbstractTableModel {
|
public class TableModel extends AbstractTableModel {
|
||||||
private String[] columnNames;
|
private LocalDate[] columnNames;
|
||||||
private Object[][] data;
|
private Object[][] data;
|
||||||
private int headerSize;
|
private int headerSize;
|
||||||
private int day;
|
private int day;
|
||||||
|
|
||||||
public TableModel(int day, int currentPage, int headerSize) {
|
public TableModel(int day, int currentPage, int headerSize) {
|
||||||
this.day = day;
|
this.day = day;
|
||||||
columnNames = new String[this.day];
|
columnNames = new LocalDate[this.day];
|
||||||
data = new Object[5][this.day];
|
data = new Object[5][this.day];
|
||||||
for (int i = 0; i < this.day; i++) {
|
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++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Arrays.fill(data[i], "");
|
Arrays.fill(data[i], "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return data.length;
|
return data.length;
|
||||||
|
@ -30,9 +32,13 @@ public class TableModel extends AbstractTableModel {
|
||||||
return columnNames.length;
|
return columnNames.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDate getColumn(int column) {
|
||||||
|
return columnNames[column];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnName(int column) {
|
public String getColumnName(int column) {
|
||||||
return columnNames[column];
|
return columnNames[column].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import DB.*;
|
import DB.*;
|
||||||
|
import Exceptions.NotFoundInTable;
|
||||||
import Exceptions.ProjectionNotSpecified;
|
import Exceptions.ProjectionNotSpecified;
|
||||||
import GUI.Agenda.Agenda;
|
import GUI.Agenda.Agenda;
|
||||||
import GUI.Types.ProjectionType;
|
import GUI.Types.ProjectionType;
|
||||||
|
@ -44,6 +45,12 @@ public class ProjectionHandler extends JDialog {
|
||||||
throw new ProjectionNotSpecified();
|
throw new ProjectionNotSpecified();
|
||||||
this.projectionType = projectionType;
|
this.projectionType = projectionType;
|
||||||
this.agenda = agenda;
|
this.agenda = agenda;
|
||||||
|
try {
|
||||||
|
competitionComboBox.getModel().setSelectedItem(agenda.getCompetition());
|
||||||
|
} catch (NotFoundInTable ignored) {
|
||||||
|
}
|
||||||
|
dayComboBox.getModel().setSelectedItem(agenda.getDate());
|
||||||
|
slotComboBox.getModel().setSelectedItem(agenda.getSlot());
|
||||||
createUIComponents();
|
createUIComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue