diff --git a/src/main/java/GUI/Agenda/Agenda.java b/src/main/java/GUI/Agenda/Agenda.java index cc3b6e3..f8d951c 100644 --- a/src/main/java/GUI/Agenda/Agenda.java +++ b/src/main/java/GUI/Agenda/Agenda.java @@ -4,11 +4,10 @@ import Config.Config; import DB.Competition; import DB.Projection; import DB.Slot; -import Exceptions.NotFoundInTable; import Exceptions.ProjectionNotSpecified; import GUI.ProjectionHandler; -import GUI.Types.CompetType; import GUI.Types.ProjectionType; +import lombok.Getter; import javax.swing.*; import javax.swing.event.MouseInputAdapter; @@ -26,18 +25,18 @@ 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 = competition.getSlots(); this.headers = slots.toArray(); this.currentPage = currentPage; - this.competionType = competionType; + this.competition = competition; this.agendaPanel.removeAll(); int totalPages[] = dayToPage(); if (this.currentPage >= totalPages.length) { @@ -162,7 +161,7 @@ public class Agenda extends JPanel { private void updateMovies() { try { - ArrayList projections = Projection.getAvailable(new Competition(this.competionType.getCompetition())); + ArrayList projections = Projection.getAvailable(this.competition); for (Projection projection : projections) { addMovie(projection); } @@ -203,10 +202,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/GUI.form b/src/main/java/GUI/GUI.form index 0ddae9d..bc3b58d 100644 --- a/src/main/java/GUI/GUI.form +++ b/src/main/java/GUI/GUI.form @@ -75,7 +75,7 @@ - + @@ -84,38 +84,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index 27fd50e..fbd83c4 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -1,8 +1,9 @@ package GUI; +import DB.Competition; import DB.Slot; +import Exceptions.NotFoundInTable; import GUI.Agenda.Agenda; -import GUI.Types.CompetType; import GUI.Types.ProjectionType; import javax.swing.*; @@ -19,6 +20,7 @@ public class GUI extends JFrame implements ActionListener { private JButton LMButton; private JButton HCButton; private JButton UCRButton; + private JPanel competitionButtonPanel; private JMenuBar menuBar = new JMenuBar(); private JMenu menuFichier = new JMenu("File"); private JMenuItem menuItemAddProj = new JMenuItem("Add projection"); @@ -26,9 +28,9 @@ public class GUI extends JFrame implements ActionListener { private int currentPage; private Agenda agenda; private ArrayList slots = new ArrayList(); - private CompetType currentCompetition = CompetType.LM; + private Competition currentCompetition = new Competition("Long Métrage"); - public GUI() { + public GUI() throws NotFoundInTable { super(); construct(); } @@ -55,15 +57,18 @@ public class GUI extends JFrame implements ActionListener { agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition); previousButton.addActionListener(this); nextButton.addActionListener(this); - HCButton.addActionListener(this); - LMButton.addActionListener(this); - UCRButton.addActionListener(this); menuItemAddProj.addActionListener(this); menuItemRemoveProj.addActionListener(this); setVisible(true); } - private void switchCompetition(CompetType competType) { + private void competitionButton() { + competitionButtonPanel = new JPanel(); + for (Competition competition : Competition.getAll()) { + JButton button = new JButton(competition.getName()); + button.addActionListener(actionEvent -> switchAgenda(competition)); + competitionButtonPanel.add(button); + } } @Override @@ -80,21 +85,6 @@ public class GUI extends JFrame implements ActionListener { Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition); this.currentPage = agenda.getCurrentPage(); - this.repaint(); - this.revalidate(); - } else if (source == LMButton) { - this.currentCompetition = CompetType.LM; - this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); - this.repaint(); - this.revalidate(); - } else if (source == HCButton) { - this.currentCompetition = CompetType.HC; - this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); - this.repaint(); - this.revalidate(); - } else if (source == UCRButton) { - this.currentCompetition = CompetType.UCR; - this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); } else if (source == this.menuItemAddProj) { @@ -103,4 +93,15 @@ public class GUI extends JFrame implements ActionListener { agenda.openDialog(ProjectionType.REMOVE); } } + + private void switchAgenda(Competition competition) { + this.currentCompetition = competition; + this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); + this.repaint(); + this.revalidate(); + } + + private void createUIComponents() { + competitionButton(); + } } diff --git a/src/main/java/GUI/ProjectionHandler.java b/src/main/java/GUI/ProjectionHandler.java index 7e0e48d..450605f 100644 --- a/src/main/java/GUI/ProjectionHandler.java +++ b/src/main/java/GUI/ProjectionHandler.java @@ -46,9 +46,7 @@ public class ProjectionHandler extends JDialog { throw new ProjectionNotSpecified(); this.projectionType = projectionType; this.agenda = agenda; - try { - competitionComboBox.getModel().setSelectedItem(agenda.getCompetition()); - } catch (NotFoundInTable ignored) {} + competitionComboBox.getModel().setSelectedItem(agenda.getCompetition()); if (agenda.getDate() != null || agenda.getSlot() != null) { updateMovies(); updateDates(); diff --git a/src/main/java/ProjectionPlanning/Main.java b/src/main/java/ProjectionPlanning/Main.java index 0e11a2e..d498f78 100644 --- a/src/main/java/ProjectionPlanning/Main.java +++ b/src/main/java/ProjectionPlanning/Main.java @@ -7,6 +7,9 @@ import GUI.GUI; public class Main { public static void main(String[] args) throws NotFoundInTable { DB.connect(); + try { + UIManager.setLookAndFeel(new MaterialLookAndFeel(new MaterialLiteTheme())); + } catch (UnsupportedLookAndFeelException ignored) {} new GUI(); } }