1
0
Fork 0

Add dynamic competitions on GUI

This commit is contained in:
Ethanell 2021-01-12 19:43:01 +01:00
parent 23cd5d4b3d
commit 56b41d49a4
5 changed files with 35 additions and 69 deletions

View file

@ -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<Slot> 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<Projection> projections = Projection.getAvailable(new Competition(this.competionType.getCompetition()));
ArrayList<Projection> 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;
}

View file

@ -75,7 +75,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="b1c37" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b1c37" binding="competitionButtonPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="25" left="50" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false">
@ -84,38 +84,7 @@
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2dfdc" class="javax.swing.JButton" binding="LMButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="75" height="-1"/>
</grid>
</constraints>
<properties>
<text value="LM"/>
</properties>
</component>
<component id="9869d" class="javax.swing.JButton" binding="HCButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="75" height="-1"/>
</grid>
</constraints>
<properties>
<text value="HC"/>
</properties>
</component>
<component id="bc004" class="javax.swing.JButton" binding="UCRButton" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="75" height="-1"/>
</grid>
</constraints>
<properties>
<text value="UCR"/>
</properties>
</component>
</children>
<children/>
</grid>
<hspacer id="975cc">
<constraints>

View file

@ -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<Slot> slots = new ArrayList<Slot>();
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();
}
}

View file

@ -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) {}
if (agenda.getDate() != null || agenda.getSlot() != null) {
updateMovies();
updateDates();

View file

@ -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();
}
}