diff --git a/src/main/java/GUI/Agenda.java b/src/main/java/GUI/Agenda/Agenda.java similarity index 55% rename from src/main/java/GUI/Agenda.java rename to src/main/java/GUI/Agenda/Agenda.java index 31091e6..887e03b 100644 --- a/src/main/java/GUI/Agenda.java +++ b/src/main/java/GUI/Agenda/Agenda.java @@ -1,10 +1,19 @@ -package GUI; +package GUI.Agenda; + +import DB.Competition; +import DB.Projection; +import GUI.ProjectionHandler; +import GUI.Types.CompetType; +import GUI.Types.ProjectionType; import javax.swing.*; import javax.swing.event.MouseInputAdapter; import javax.swing.table.TableColumnModel; import java.awt.*; import java.awt.event.MouseEvent; +import java.sql.Date; +import java.sql.Time; +import java.util.ArrayList; import java.util.Arrays; public class Agenda extends JPanel { @@ -12,13 +21,18 @@ public class Agenda extends JPanel { private String headers[]; private int totalDay; private int currentPage; - public Agenda(JPanel agendaPanel, String headers[], int totalDay, int currentPage) { + private JTable table; + private CompetType competionType; + private Agenda agenda; + + public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) { this.agendaPanel = agendaPanel; - this.headers = headers; - this.totalDay = totalDay; + this.headers = competionType.getHeaders(); + this.totalDay = 11; this.currentPage = currentPage; + this.competionType = competionType; this.agendaPanel.removeAll(); - int totalPages[] = dayToPage(9); + int totalPages[] = dayToPage(); if (this.currentPage >= totalPages.length) { this.currentPage = totalPages.length - 1; } else if (this.currentPage < 0) { @@ -27,18 +41,33 @@ public class Agenda extends JPanel { JScrollPane scroll = constructAgenda(totalPages[this.currentPage]); agendaPanel.add(scroll); } - private int[] dayToPage(int totalDay) { - int day = totalDay; + + public void refresh() { + this.agendaPanel.removeAll(); + int totalPages[] = dayToPage(); + if (this.currentPage >= totalPages.length) { + this.currentPage = totalPages.length - 1; + } else if (this.currentPage < 0) { + this.currentPage = 0; + } + JScrollPane scroll = constructAgenda(totalPages[this.currentPage]); + agendaPanel.add(scroll); + agendaPanel.repaint(); + agendaPanel.revalidate(); + } + + private int[] dayToPage() { + int day = this.totalDay; int count = 0; while (day >= 5) { - day = day-5; + day = day - 5; count++; } - int rest = totalDay - 5*count; - int totalPages = rest < 5 ? count+1:count; + int rest = totalDay - 5 * count; + int totalPages = rest < 5 ? count + 1 : count; int pages[] = new int[totalPages]; Arrays.fill(pages, 5); - if (rest < 5) pages[totalPages-1] = rest; + if (rest < 5) pages[totalPages - 1] = rest; return pages; } private JScrollPane constructAgenda(int day) { @@ -52,7 +81,7 @@ public class Agenda extends JPanel { } }; TableModel dm = new TableModel(day, currentPage, headers.length); - JTable table = new JTable(dm) { + table = new JTable(dm) { @Override public boolean getScrollableTracksViewportHeight() { return true; @@ -70,14 +99,13 @@ public class Agenda extends JPanel { int row = table.getSelectedRow(); int column = table.getSelectedColumn(); if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) { - ProjectionHandler dialog; if (table.getValueAt(row, column) == "") { - dialog = new ProjectionHandler(ProjectionType.ADD); + openDialog(ProjectionType.ADD); } else { - dialog = new ProjectionHandler(ProjectionType.EDIT); + openDialog(ProjectionType.EDIT); + } - dialog.pack(); - dialog.setVisible(true); + } } }); @@ -100,10 +128,40 @@ public class Agenda extends JPanel { scroll.setBorder(BorderFactory.createEmptyBorder()); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); this.agendaPanel.setPreferredSize(new Dimension(this.agendaPanel.getWidth(), headers.length * 100 + 20)); - + updateMovies(); return scroll; } + private void updateMovies() { + try { + ArrayList projections = Projection.getAvailable(new Competition(this.competionType.getCompetition())); + for (Projection projection : projections) { + addMovie(projection.getStartDate(), projection.getSlot().getStartTime(), projection.getMovie().getName()); + } + } catch (Exception e) { + } + } + + private void openDialog(ProjectionType projectionType) { + ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD, this); + ; + dialog.pack(); + dialog.setVisible(true); + } + + private void addMovie(Date startDate, Time time, String movieName) { + int column = this.table.getColumn(startDate.toString()).getModelIndex(); + int row = 0; + String times[] = {"08:30:00", "11:30:00", "15:00:00", "18:00:00", "21:00:00"}; + for (int i = 0; i < times.length; i++) { + if (times[i].equals(time.toString())) { + row = i; + break; + } + } + table.setValueAt(movieName, row, column); + } + public int getCurrentPage() { return this.currentPage; } diff --git a/src/main/java/GUI/RowHeaderRenderer.java b/src/main/java/GUI/Agenda/RowHeaderRenderer.java similarity index 97% rename from src/main/java/GUI/RowHeaderRenderer.java rename to src/main/java/GUI/Agenda/RowHeaderRenderer.java index dd7a2c3..172f4e1 100644 --- a/src/main/java/GUI/RowHeaderRenderer.java +++ b/src/main/java/GUI/Agenda/RowHeaderRenderer.java @@ -1,4 +1,4 @@ -package GUI; +package GUI.Agenda; import javax.swing.*; import javax.swing.table.JTableHeader; diff --git a/src/main/java/GUI/TableModel.java b/src/main/java/GUI/Agenda/TableModel.java similarity index 90% rename from src/main/java/GUI/TableModel.java rename to src/main/java/GUI/Agenda/TableModel.java index eda7239..6a14608 100644 --- a/src/main/java/GUI/TableModel.java +++ b/src/main/java/GUI/Agenda/TableModel.java @@ -1,4 +1,4 @@ -package GUI; +package GUI.Agenda; import javax.swing.table.AbstractTableModel; import java.util.Arrays; @@ -14,7 +14,7 @@ public class TableModel extends AbstractTableModel { columnNames = new String[this.day]; data = new Object[5][this.day]; for (int i = 0; i < this.day; i++) { - this.columnNames[i] = "Jour " + ((i + 1) + (5 * (currentPage))); + this.columnNames[i] = String.format("2021-05-%d", 10 + (i + 1) + (5 * (currentPage))); } for (int i = 0; i < 5; i++) { Arrays.fill(data[i], ""); diff --git a/src/main/java/GUI/Assets/Logo/logo_cannes.jpg b/src/main/java/GUI/Assets/Logo/logo_cannes.jpg new file mode 100644 index 0000000..ec11a6b Binary files /dev/null and b/src/main/java/GUI/Assets/Logo/logo_cannes.jpg differ diff --git a/src/main/java/GUI/CompetType.java b/src/main/java/GUI/CompetType.java deleted file mode 100644 index 9b0e1a5..0000000 --- a/src/main/java/GUI/CompetType.java +++ /dev/null @@ -1,5 +0,0 @@ -package GUI; - -public enum CompetType { - LM, UCR, HC -} \ No newline at end of file diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index b8b0877..b939d2c 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -1,5 +1,9 @@ package GUI; +import GUI.Agenda.Agenda; +import GUI.Types.CompetType; +import GUI.Types.ProjectionType; + import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -19,9 +23,14 @@ public class GUI extends JFrame implements ActionListener { private JMenuItem menuItemEditProj = new JMenuItem("Edit projection"); private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection"); private int currentPage; + private Agenda agenda; String headers[] = {"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; private CompetType currentCompetition = CompetType.LM; + public static void main(String[] args) { + new GUI(); + } + public GUI() { super(); construct(); @@ -43,9 +52,11 @@ public class GUI extends JFrame implements ActionListener { setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + ImageIcon img = new ImageIcon("src/main/java/GUI/Assets/Logo/logo_cannes.jpg"); + setIconImage(img.getImage()); this.renderMenu(); - new Agenda(agendaPanel, headers, 8, this.currentPage); + new Agenda(agendaPanel, this.currentPage, this.currentCompetition); previousButton.addActionListener(this); nextButton.addActionListener(this); HCButton.addActionListener(this); @@ -62,46 +73,46 @@ public class GUI extends JFrame implements ActionListener { Object source = e.getSource(); if (source == previousButton) { this.currentPage--; - Agenda agenda = new Agenda(agendaPanel, headers, 8, this.currentPage); + Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition); this.currentPage = agenda.getCurrentPage(); this.repaint(); this.revalidate(); } else if (source == nextButton) { this.currentPage++; - Agenda agenda = new Agenda(agendaPanel, headers, 8, this.currentPage); + 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.headers = new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; - Agenda agenda = new Agenda(agendaPanel, headers, 8, 0); - currentCompetition = CompetType.LM; + this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); } else if (source == HCButton) { this.headers = new String[]{"Fin
Matinée", "Fin
Après-midi", "Soirée"}; - Agenda agenda = new Agenda(agendaPanel, headers, 8, 0); - currentCompetition = CompetType.HC; + 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.headers = new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; - Agenda agenda = new Agenda(agendaPanel, headers, 8, 0); - currentCompetition = CompetType.UCR; + this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); } else if (source == this.menuItemAddProj) { - ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD); + ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD, agenda); dialog.pack(); dialog.setVisible(true); } else if (source == this.menuItemEditProj) { - ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT); + ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT, agenda); dialog.pack(); dialog.setVisible(true); } else if (source == this.menuItemRemoveProj) { - ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE); + ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE, agenda); dialog.pack(); dialog.setVisible(true); } diff --git a/src/main/java/GUI/ProjectionHandler.java b/src/main/java/GUI/ProjectionHandler.java index ac5b01e..da80f57 100644 --- a/src/main/java/GUI/ProjectionHandler.java +++ b/src/main/java/GUI/ProjectionHandler.java @@ -1,14 +1,18 @@ package GUI; import DB.*; +import GUI.Agenda.Agenda; +import GUI.Types.ProjectionType; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.sql.Date; import java.time.LocalDate; -import java.util.*; -import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Set; import java.util.stream.Collectors; public class ProjectionHandler extends JDialog { @@ -31,12 +35,16 @@ public class ProjectionHandler extends JDialog { private JLabel roomLabel; private JComboBox roomComboBox; private ProjectionType projectionType; + private Agenda agenda; - public ProjectionHandler(ProjectionType projectionType) { + public ProjectionHandler(ProjectionType projectionType, Agenda agenda) { this.projectionType = projectionType; + this.agenda = agenda; setContentPane(contentPane); setModal(true); setPreferredSize(new Dimension(500, 300)); + ImageIcon img = new ImageIcon("src/main/java/GUI/Assets/Logo/logo_cannes.jpg"); + setIconImage(img.getImage()); handleDialogName(); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -135,6 +143,8 @@ public class ProjectionHandler extends JDialog { return; if (projectionType == ProjectionType.ADD) new Projection(Date.valueOf((LocalDate) dayComboBox.getSelectedItem()), (Competition) competitionComboBox.getSelectedItem(), (Room) roomComboBox.getSelectedItem(), (Movie) filmComboBox.getSelectedItem(), (Slot) slotComboBox.getSelectedItem()); + this.agenda.refresh(); + dispose(); } } diff --git a/src/main/java/GUI/Types/CompetType.java b/src/main/java/GUI/Types/CompetType.java new file mode 100644 index 0000000..aefc382 --- /dev/null +++ b/src/main/java/GUI/Types/CompetType.java @@ -0,0 +1,25 @@ +package GUI.Types; + +public enum CompetType { + LM("Long Métrage"), + UCR("Un Certain Regard"), + HC("Hors Compétition"); + final private String competition; + + CompetType(String competition) { + this.competition = competition; + } + + public String[] getHeaders() { + if (this.competition.equals("Long Métrage") || this.competition.equals("Un Certain Regard")) { + return new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; + } else if (this.competition.equals("Hors Compétition")) { + return new String[]{"Fin
Matinée", "Fin
Après-midi", "Soirée"}; + } + return new String[0]; + } + + public String getCompetition() { + return this.competition; + } +} \ No newline at end of file diff --git a/src/main/java/GUI/ProjectionType.java b/src/main/java/GUI/Types/ProjectionType.java similarity index 73% rename from src/main/java/GUI/ProjectionType.java rename to src/main/java/GUI/Types/ProjectionType.java index ceccf0f..bf84265 100644 --- a/src/main/java/GUI/ProjectionType.java +++ b/src/main/java/GUI/Types/ProjectionType.java @@ -1,4 +1,4 @@ -package GUI; +package GUI.Types; public enum ProjectionType { ADD, EDIT, REMOVE diff --git a/src/main/java/ProjectionPlanning/Main.java b/src/main/java/ProjectionPlanning/Main.java index ce5d0cd..0e11a2e 100644 --- a/src/main/java/ProjectionPlanning/Main.java +++ b/src/main/java/ProjectionPlanning/Main.java @@ -1,10 +1,11 @@ package ProjectionPlanning; -import DB.*; +import DB.DB; +import Exceptions.NotFoundInTable; import GUI.GUI; public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws NotFoundInTable { DB.connect(); new GUI(); }