add projection, update agenda
This commit is contained in:
parent
7c2140e9f7
commit
ca7d3f1136
10 changed files with 145 additions and 45 deletions
|
@ -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.*;
|
||||||
import javax.swing.event.MouseInputAdapter;
|
import javax.swing.event.MouseInputAdapter;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.Time;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Agenda extends JPanel {
|
public class Agenda extends JPanel {
|
||||||
|
@ -12,13 +21,18 @@ public class Agenda extends JPanel {
|
||||||
private String headers[];
|
private String headers[];
|
||||||
private int totalDay;
|
private int totalDay;
|
||||||
private int currentPage;
|
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.agendaPanel = agendaPanel;
|
||||||
this.headers = headers;
|
this.headers = competionType.getHeaders();
|
||||||
this.totalDay = totalDay;
|
this.totalDay = 11;
|
||||||
this.currentPage = currentPage;
|
this.currentPage = currentPage;
|
||||||
|
this.competionType = competionType;
|
||||||
this.agendaPanel.removeAll();
|
this.agendaPanel.removeAll();
|
||||||
int totalPages[] = dayToPage(9);
|
int totalPages[] = dayToPage();
|
||||||
if (this.currentPage >= totalPages.length) {
|
if (this.currentPage >= totalPages.length) {
|
||||||
this.currentPage = totalPages.length - 1;
|
this.currentPage = totalPages.length - 1;
|
||||||
} else if (this.currentPage < 0) {
|
} else if (this.currentPage < 0) {
|
||||||
|
@ -27,8 +41,23 @@ public class Agenda extends JPanel {
|
||||||
JScrollPane scroll = constructAgenda(totalPages[this.currentPage]);
|
JScrollPane scroll = constructAgenda(totalPages[this.currentPage]);
|
||||||
agendaPanel.add(scroll);
|
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;
|
int count = 0;
|
||||||
while (day >= 5) {
|
while (day >= 5) {
|
||||||
day = day - 5;
|
day = day - 5;
|
||||||
|
@ -52,7 +81,7 @@ public class Agenda extends JPanel {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TableModel dm = new TableModel(day, currentPage, headers.length);
|
TableModel dm = new TableModel(day, currentPage, headers.length);
|
||||||
JTable table = new JTable(dm) {
|
table = new JTable(dm) {
|
||||||
@Override
|
@Override
|
||||||
public boolean getScrollableTracksViewportHeight() {
|
public boolean getScrollableTracksViewportHeight() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -70,14 +99,13 @@ public class Agenda extends JPanel {
|
||||||
int row = table.getSelectedRow();
|
int row = table.getSelectedRow();
|
||||||
int column = table.getSelectedColumn();
|
int column = table.getSelectedColumn();
|
||||||
if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
|
if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
|
||||||
ProjectionHandler dialog;
|
|
||||||
if (table.getValueAt(row, column) == "") {
|
if (table.getValueAt(row, column) == "") {
|
||||||
dialog = new ProjectionHandler(ProjectionType.ADD);
|
openDialog(ProjectionType.ADD);
|
||||||
} else {
|
} 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.setBorder(BorderFactory.createEmptyBorder());
|
||||||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||||
this.agendaPanel.setPreferredSize(new Dimension(this.agendaPanel.getWidth(), headers.length * 100 + 20));
|
this.agendaPanel.setPreferredSize(new Dimension(this.agendaPanel.getWidth(), headers.length * 100 + 20));
|
||||||
|
updateMovies();
|
||||||
return scroll;
|
return scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateMovies() {
|
||||||
|
try {
|
||||||
|
ArrayList<Projection> 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() {
|
public int getCurrentPage() {
|
||||||
return this.currentPage;
|
return this.currentPage;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package GUI;
|
package GUI.Agenda;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
|
@ -1,4 +1,4 @@
|
||||||
package GUI;
|
package GUI.Agenda;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -14,7 +14,7 @@ public class TableModel extends AbstractTableModel {
|
||||||
columnNames = new String[this.day];
|
columnNames = new String[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] = "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++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Arrays.fill(data[i], "");
|
Arrays.fill(data[i], "");
|
BIN
src/main/java/GUI/Assets/Logo/logo_cannes.jpg
Normal file
BIN
src/main/java/GUI/Assets/Logo/logo_cannes.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
|
@ -1,5 +0,0 @@
|
||||||
package GUI;
|
|
||||||
|
|
||||||
public enum CompetType {
|
|
||||||
LM, UCR, HC
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
|
import GUI.Agenda.Agenda;
|
||||||
|
import GUI.Types.CompetType;
|
||||||
|
import GUI.Types.ProjectionType;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
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 menuItemEditProj = new JMenuItem("Edit projection");
|
||||||
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
|
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
|
||||||
private int currentPage;
|
private int currentPage;
|
||||||
|
private Agenda agenda;
|
||||||
String headers[] = {"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
String headers[] = {"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
private CompetType currentCompetition = CompetType.LM;
|
private CompetType currentCompetition = CompetType.LM;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new GUI();
|
||||||
|
}
|
||||||
|
|
||||||
public GUI() {
|
public GUI() {
|
||||||
super();
|
super();
|
||||||
construct();
|
construct();
|
||||||
|
@ -43,9 +52,11 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
ImageIcon img = new ImageIcon("src/main/java/GUI/Assets/Logo/logo_cannes.jpg");
|
||||||
|
setIconImage(img.getImage());
|
||||||
this.renderMenu();
|
this.renderMenu();
|
||||||
|
|
||||||
new Agenda(agendaPanel, headers, 8, this.currentPage);
|
new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
||||||
previousButton.addActionListener(this);
|
previousButton.addActionListener(this);
|
||||||
nextButton.addActionListener(this);
|
nextButton.addActionListener(this);
|
||||||
HCButton.addActionListener(this);
|
HCButton.addActionListener(this);
|
||||||
|
@ -62,46 +73,46 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
Object source = e.getSource();
|
Object source = e.getSource();
|
||||||
if (source == previousButton) {
|
if (source == previousButton) {
|
||||||
this.currentPage--;
|
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.currentPage = agenda.getCurrentPage();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
}
|
}
|
||||||
else if (source == nextButton) {
|
else if (source == nextButton) {
|
||||||
this.currentPage++;
|
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.currentPage = agenda.getCurrentPage();
|
||||||
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
} else if (source == LMButton) {
|
} else if (source == LMButton) {
|
||||||
|
this.currentCompetition = CompetType.LM;
|
||||||
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition);
|
||||||
currentCompetition = CompetType.LM;
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
} else if (source == HCButton) {
|
} else if (source == HCButton) {
|
||||||
this.headers = new String[]{"<html>Fin<br/>Matinée</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
this.headers = new String[]{"<html>Fin<br/>Matinée</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
this.currentCompetition = CompetType.HC;
|
||||||
currentCompetition = CompetType.HC;
|
this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
} else if (source == UCRButton) {
|
} else if (source == UCRButton) {
|
||||||
|
this.currentCompetition = CompetType.UCR;
|
||||||
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition);
|
||||||
currentCompetition = CompetType.UCR;
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
} else if (source == this.menuItemAddProj) {
|
} else if (source == this.menuItemAddProj) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD);
|
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD, agenda);
|
||||||
dialog.pack();
|
dialog.pack();
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
} else if (source == this.menuItemEditProj) {
|
} else if (source == this.menuItemEditProj) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT);
|
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT, agenda);
|
||||||
dialog.pack();
|
dialog.pack();
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
} else if (source == this.menuItemRemoveProj) {
|
} else if (source == this.menuItemRemoveProj) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE);
|
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE, agenda);
|
||||||
dialog.pack();
|
dialog.pack();
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import DB.*;
|
import DB.*;
|
||||||
|
import GUI.Agenda.Agenda;
|
||||||
|
import GUI.Types.ProjectionType;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ProjectionHandler extends JDialog {
|
public class ProjectionHandler extends JDialog {
|
||||||
|
@ -31,12 +35,16 @@ public class ProjectionHandler extends JDialog {
|
||||||
private JLabel roomLabel;
|
private JLabel roomLabel;
|
||||||
private JComboBox roomComboBox;
|
private JComboBox roomComboBox;
|
||||||
private ProjectionType projectionType;
|
private ProjectionType projectionType;
|
||||||
|
private Agenda agenda;
|
||||||
|
|
||||||
public ProjectionHandler(ProjectionType projectionType) {
|
public ProjectionHandler(ProjectionType projectionType, Agenda agenda) {
|
||||||
this.projectionType = projectionType;
|
this.projectionType = projectionType;
|
||||||
|
this.agenda = agenda;
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
setModal(true);
|
setModal(true);
|
||||||
setPreferredSize(new Dimension(500, 300));
|
setPreferredSize(new Dimension(500, 300));
|
||||||
|
ImageIcon img = new ImageIcon("src/main/java/GUI/Assets/Logo/logo_cannes.jpg");
|
||||||
|
setIconImage(img.getImage());
|
||||||
handleDialogName();
|
handleDialogName();
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@ -135,6 +143,8 @@ public class ProjectionHandler extends JDialog {
|
||||||
return;
|
return;
|
||||||
if (projectionType == ProjectionType.ADD)
|
if (projectionType == ProjectionType.ADD)
|
||||||
new Projection(Date.valueOf((LocalDate) dayComboBox.getSelectedItem()), (Competition) competitionComboBox.getSelectedItem(), (Room) roomComboBox.getSelectedItem(), (Movie) filmComboBox.getSelectedItem(), (Slot) slotComboBox.getSelectedItem());
|
new Projection(Date.valueOf((LocalDate) dayComboBox.getSelectedItem()), (Competition) competitionComboBox.getSelectedItem(), (Room) roomComboBox.getSelectedItem(), (Movie) filmComboBox.getSelectedItem(), (Slot) slotComboBox.getSelectedItem());
|
||||||
|
this.agenda.refresh();
|
||||||
|
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
src/main/java/GUI/Types/CompetType.java
Normal file
25
src/main/java/GUI/Types/CompetType.java
Normal file
|
@ -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", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
|
} else if (this.competition.equals("Hors Compétition")) {
|
||||||
|
return new String[]{"<html>Fin<br/>Matinée</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
|
}
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompetition() {
|
||||||
|
return this.competition;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package GUI;
|
package GUI.Types;
|
||||||
|
|
||||||
public enum ProjectionType {
|
public enum ProjectionType {
|
||||||
ADD, EDIT, REMOVE
|
ADD, EDIT, REMOVE
|
|
@ -1,10 +1,11 @@
|
||||||
package ProjectionPlanning;
|
package ProjectionPlanning;
|
||||||
|
|
||||||
import DB.*;
|
import DB.DB;
|
||||||
|
import Exceptions.NotFoundInTable;
|
||||||
import GUI.GUI;
|
import GUI.GUI;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws NotFoundInTable {
|
||||||
DB.connect();
|
DB.connect();
|
||||||
new GUI();
|
new GUI();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue