diff --git a/src/main/java/GUI/Agenda/Agenda.java b/src/main/java/GUI/Agenda/Agenda.java index ed5d61d..f5e169a 100644 --- a/src/main/java/GUI/Agenda/Agenda.java +++ b/src/main/java/GUI/Agenda/Agenda.java @@ -4,13 +4,12 @@ import Config.Config; import DB.Competition; import DB.Projection; import DB.Slot; -import Exceptions.NotFoundInTable; import Exceptions.ProjectionNotSpecified; import GUI.Agenda.Model.AgendaTableModel; import GUI.ProjectionHandler; import GUI.ProjectionSelecter; -import GUI.Types.CompetType; import GUI.Types.ProjectionType; +import lombok.Getter; import javax.swing.*; import javax.swing.event.MouseInputAdapter; @@ -28,18 +27,19 @@ public class Agenda extends JPanel { private Object headers[]; private int currentPage; private JTable table; - private CompetType competionType; + @Getter + private Competition competition; private Agenda agenda; private ArrayList slots; private Slot currentSlot; private LocalDate currentDay; - public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) { + public Agenda(JPanel agendaPanel, int currentPage, Competition competition) { this.agendaPanel = agendaPanel; - this.slots = competionType.getSlots(); + this.slots = Slot.getAll(competition); this.headers = slots.toArray(); this.currentPage = currentPage; - this.competionType = competionType; + this.competition = competition; this.agendaPanel.removeAll(); int totalPages[] = dayToPage(); if (this.currentPage >= totalPages.length) { @@ -101,7 +101,7 @@ public class Agenda extends JPanel { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(100); - Agenda tmp = this; + agenda = this; table.addMouseListener(new MouseInputAdapter() { @Override public void mouseReleased(MouseEvent mouseEvent) { @@ -113,7 +113,7 @@ public class Agenda extends JPanel { Projection projection = null; if (currentCellValue.getClass() == Projection.class) projection = (Projection) currentCellValue; - PopUpProjection popUpProjection = new PopUpProjection(projection, tmp); + PopUpProjection popUpProjection = new PopUpProjection(projection, agenda); popUpProjection.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); } } @@ -167,7 +167,7 @@ public class Agenda extends JPanel { private void updateMovies() { try { - ArrayList projections = Projection.getAvailable(new Competition(this.competionType.getCompetition())); + ArrayList projections = Projection.getAvailable(competition); for (Projection projection : projections) { addMovie(projection); } @@ -216,9 +216,6 @@ public class Agenda extends JPanel { return this.currentPage; } - public Competition getCompetition() throws NotFoundInTable { - return new Competition(competionType.getCompetition()); - } public Slot getSlot() { return currentSlot; diff --git a/src/main/java/GUI/Agenda/Model/ProjectionTableModel.java b/src/main/java/GUI/Agenda/Model/ProjectionTableModel.java index 3c3ca6d..40ae255 100644 --- a/src/main/java/GUI/Agenda/Model/ProjectionTableModel.java +++ b/src/main/java/GUI/Agenda/Model/ProjectionTableModel.java @@ -32,7 +32,7 @@ public class ProjectionTableModel extends AbstractTableModel { } public Projection getRowAt(int row) { - return (Projection) data[row]; + return data[row]; } @Override diff --git a/src/main/java/GUI/ProjectionSelecter.java b/src/main/java/GUI/ProjectionSelecter.java index 3797405..3a96796 100644 --- a/src/main/java/GUI/ProjectionSelecter.java +++ b/src/main/java/GUI/ProjectionSelecter.java @@ -21,6 +21,7 @@ public class ProjectionSelecter extends JDialog { public ProjectionSelecter(ArrayList projections, Agenda agenda) { this.agenda = agenda; + this.currentProjection = null; setContentPane(contentPane); setModal(true); setLocationRelativeTo(null); @@ -46,8 +47,8 @@ public class ProjectionSelecter extends JDialog { JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); + currentProjection = ((ProjectionTableModel) table.getModel()).getRowAt(row); if (e.getClickCount() == 2 && table.getSelectedRow() != -1) { - currentProjection = ((ProjectionTableModel) table.getModel()).getRowAt(row); agenda.openDialog(ProjectionType.EDIT, currentProjection); dispose(); } @@ -69,7 +70,6 @@ public class ProjectionSelecter extends JDialog { } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } - private void onOK() { agenda.openDialog(ProjectionType.EDIT, currentProjection); dispose();