From 56b41d49a48f1041c942e7ebc126fc570fe802f4 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 12 Jan 2021 19:43:01 +0100 Subject: [PATCH 1/2] Add dynamic competitions on GUI --- src/main/java/GUI/Agenda/Agenda.java | 17 +++----- src/main/java/GUI/GUI.form | 35 +---------------- src/main/java/GUI/GUI.java | 45 +++++++++++----------- src/main/java/GUI/ProjectionHandler.java | 4 +- src/main/java/ProjectionPlanning/Main.java | 3 ++ 5 files changed, 35 insertions(+), 69 deletions(-) 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(); } } From d11cdb2caf16191cf30cb7acb895b6055ddf7958 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 12 Jan 2021 20:48:37 +0100 Subject: [PATCH 2/2] Implement MaterialUI theme --- build.gradle | 1 + src/main/java/GUI/GUI.form | 6 ++-- src/main/java/GUI/GUI.java | 6 ++++ src/main/java/GUI/ProjectionHandler.form | 4 +-- src/main/java/GUI/ProjectionHandler.java | 20 ++++++++++--- .../GUI/Theme/DangerContainedButtonUI.java | 28 +++++++++++++++++++ .../GUI/Theme/PrimaryContainedButtonUI.java | 28 +++++++++++++++++++ .../GUI/Theme/SecondaryContainedButtonUI.java | 28 +++++++++++++++++++ src/main/java/ProjectionPlanning/Main.java | 4 +++ 9 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 src/main/java/GUI/Theme/DangerContainedButtonUI.java create mode 100644 src/main/java/GUI/Theme/PrimaryContainedButtonUI.java create mode 100644 src/main/java/GUI/Theme/SecondaryContainedButtonUI.java diff --git a/build.gradle b/build.gradle index ea14aec..37d6120 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ dependencies { implementation 'com.googlecode.json-simple:json-simple:1.1.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + implementation 'io.github.vincenzopalazzo:material-ui-swing:1.1.1' } test { diff --git a/src/main/java/GUI/GUI.form b/src/main/java/GUI/GUI.form index bc3b58d..92ce595 100644 --- a/src/main/java/GUI/GUI.form +++ b/src/main/java/GUI/GUI.form @@ -31,19 +31,21 @@ - + + - + + diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index fbd83c4..48c94d8 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -4,6 +4,7 @@ import DB.Competition; import DB.Slot; import Exceptions.NotFoundInTable; import GUI.Agenda.Agenda; +import GUI.Theme.PrimaryContainedButtonUI; import GUI.Types.ProjectionType; import javax.swing.*; @@ -66,6 +67,7 @@ public class GUI extends JFrame implements ActionListener { competitionButtonPanel = new JPanel(); for (Competition competition : Competition.getAll()) { JButton button = new JButton(competition.getName()); + button.setUI(new PrimaryContainedButtonUI()); button.addActionListener(actionEvent -> switchAgenda(competition)); competitionButtonPanel.add(button); } @@ -103,5 +105,9 @@ public class GUI extends JFrame implements ActionListener { private void createUIComponents() { competitionButton(); + nextButton = new JButton(); + nextButton.setUI(new PrimaryContainedButtonUI()); + previousButton = new JButton(); + previousButton.setUI(new PrimaryContainedButtonUI()); } } diff --git a/src/main/java/GUI/ProjectionHandler.form b/src/main/java/GUI/ProjectionHandler.form index b1913d5..8ca8dce 100644 --- a/src/main/java/GUI/ProjectionHandler.form +++ b/src/main/java/GUI/ProjectionHandler.form @@ -80,7 +80,7 @@ - + @@ -88,7 +88,7 @@ - + diff --git a/src/main/java/GUI/ProjectionHandler.java b/src/main/java/GUI/ProjectionHandler.java index 450605f..78a1ae6 100644 --- a/src/main/java/GUI/ProjectionHandler.java +++ b/src/main/java/GUI/ProjectionHandler.java @@ -2,9 +2,11 @@ package GUI; import Config.Config; import DB.*; -import Exceptions.NotFoundInTable; import Exceptions.ProjectionNotSpecified; import GUI.Agenda.Agenda; +import GUI.Theme.DangerContainedButtonUI; +import GUI.Theme.PrimaryContainedButtonUI; +import GUI.Theme.SecondaryContainedButtonUI; import GUI.Types.ProjectionType; import javax.swing.*; @@ -55,14 +57,14 @@ public class ProjectionHandler extends JDialog { slotComboBox.getModel().setSelectedItem(agenda.getSlot()); updateRooms(); } - createUIComponents(); + createUI(); } public ProjectionHandler(ProjectionType projectionType, Agenda agenda, Projection projection) { this.projectionType = projectionType; this.agenda = agenda; this.projection = projection; - createUIComponents(); + createUI(); competitionComboBox.getModel().setSelectedItem(projection.getCompetition()); filmComboBox.getModel().setSelectedItem(projection.getMovie()); dayComboBox.getModel().setSelectedItem(projection.getStartDate().toLocalDate()); @@ -73,7 +75,7 @@ public class ProjectionHandler extends JDialog { comboBox.setEnabled(false); } - private void createUIComponents() { + private void createUI() { setContentPane(contentPane); setModal(true); setPreferredSize(new Dimension(500, 300)); @@ -97,6 +99,16 @@ public class ProjectionHandler extends JDialog { confirmButton.addActionListener(actionEvent -> confirm()); } + private void createUIComponents() { + confirmButton = new JButton(); + if (projectionType == ProjectionType.REMOVE) + confirmButton.setUI(new DangerContainedButtonUI()); + else + confirmButton.setUI(new PrimaryContainedButtonUI()); + cancelButton = new JButton(); + cancelButton.setUI(new SecondaryContainedButtonUI()); + } + private void updateCompetitions() { ArrayList competitions = Competition.getAll(); if (competitions != null) diff --git a/src/main/java/GUI/Theme/DangerContainedButtonUI.java b/src/main/java/GUI/Theme/DangerContainedButtonUI.java new file mode 100644 index 0000000..5bfdf89 --- /dev/null +++ b/src/main/java/GUI/Theme/DangerContainedButtonUI.java @@ -0,0 +1,28 @@ +package GUI.Theme; + +import mdlaf.animation.MaterialUIMovement; +import mdlaf.components.button.MaterialButtonUI; +import mdlaf.utils.MaterialColors; + +import javax.swing.*; + +public class DangerContainedButtonUI extends MaterialButtonUI { + @Override + public void installUI(JComponent c) { + super.mouseHoverEnabled = false; + super.installUI(c); + super.mouseHoverEnabled = true; + super.colorMouseHoverNormalButton = MaterialColors.RED_600; + super.background = MaterialColors.RED_700; + c.setBackground(super.background); + super.foreground = MaterialColors.WHITE; + c.setForeground(super.foreground); + + if (super.mouseHoverEnabled) { + c.addMouseListener( + MaterialUIMovement.getMovement(c, this.colorMouseHoverNormalButton) + ); + } + super.borderEnabled = false; + } +} diff --git a/src/main/java/GUI/Theme/PrimaryContainedButtonUI.java b/src/main/java/GUI/Theme/PrimaryContainedButtonUI.java new file mode 100644 index 0000000..3dc073a --- /dev/null +++ b/src/main/java/GUI/Theme/PrimaryContainedButtonUI.java @@ -0,0 +1,28 @@ +package GUI.Theme; + +import mdlaf.animation.MaterialUIMovement; +import mdlaf.components.button.MaterialButtonUI; +import mdlaf.utils.MaterialColors; + +import javax.swing.*; + +public class PrimaryContainedButtonUI extends MaterialButtonUI { + @Override + public void installUI(JComponent c) { + super.mouseHoverEnabled = false; + super.installUI(c); + super.mouseHoverEnabled = true; + super.colorMouseHoverNormalButton = MaterialColors.BLUE_600; + super.background = MaterialColors.BLUE_700; + c.setBackground(super.background); + super.foreground = MaterialColors.WHITE; + c.setForeground(super.foreground); + + if (super.mouseHoverEnabled) { + c.addMouseListener( + MaterialUIMovement.getMovement(c, this.colorMouseHoverNormalButton) + ); + } + super.borderEnabled = false; + } +} diff --git a/src/main/java/GUI/Theme/SecondaryContainedButtonUI.java b/src/main/java/GUI/Theme/SecondaryContainedButtonUI.java new file mode 100644 index 0000000..6c0c6e3 --- /dev/null +++ b/src/main/java/GUI/Theme/SecondaryContainedButtonUI.java @@ -0,0 +1,28 @@ +package GUI.Theme; + +import mdlaf.animation.MaterialUIMovement; +import mdlaf.components.button.MaterialButtonUI; +import mdlaf.utils.MaterialColors; + +import javax.swing.*; + +public class SecondaryContainedButtonUI extends MaterialButtonUI { + @Override + public void installUI(JComponent c) { + super.mouseHoverEnabled = false; + super.installUI(c); + super.mouseHoverEnabled = true; + super.colorMouseHoverNormalButton = MaterialColors.PURPLE_600; + super.background = MaterialColors.PURPLE_700; + c.setBackground(super.background); + super.foreground = MaterialColors.WHITE; + c.setForeground(super.foreground); + + if (super.mouseHoverEnabled) { + c.addMouseListener( + MaterialUIMovement.getMovement(c, this.colorMouseHoverNormalButton) + ); + } + super.borderEnabled = false; + } +} diff --git a/src/main/java/ProjectionPlanning/Main.java b/src/main/java/ProjectionPlanning/Main.java index d498f78..cf4e7eb 100644 --- a/src/main/java/ProjectionPlanning/Main.java +++ b/src/main/java/ProjectionPlanning/Main.java @@ -3,6 +3,10 @@ package ProjectionPlanning; import DB.DB; import Exceptions.NotFoundInTable; import GUI.GUI; +import mdlaf.MaterialLookAndFeel; +import mdlaf.themes.MaterialLiteTheme; + +import javax.swing.*; public class Main { public static void main(String[] args) throws NotFoundInTable {