From 181bfd02e236c32bd6fa7d4fc1fb1909211bb069 Mon Sep 17 00:00:00 2001 From: Moncef STITI Date: Thu, 5 Dec 2024 17:01:00 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameModeFilterButtonActionListener.java | 18 ++++ .../gui/GameModeHoverEffectMouseListener.java | 46 ++++++++++ .../gui/GameModeNextButtonActionListener.java | 18 ++++ .../gui/GameModePrevButtonActionListener.java | 20 ++++ .../gui/GameModeSelectionPanel.java | 91 +++++++++++-------- 5 files changed, 153 insertions(+), 40 deletions(-) create mode 100644 src/fr/monkhanny/dorfromantik/gui/GameModeFilterButtonActionListener.java create mode 100644 src/fr/monkhanny/dorfromantik/gui/GameModeHoverEffectMouseListener.java create mode 100644 src/fr/monkhanny/dorfromantik/gui/GameModeNextButtonActionListener.java create mode 100644 src/fr/monkhanny/dorfromantik/gui/GameModePrevButtonActionListener.java diff --git a/src/fr/monkhanny/dorfromantik/gui/GameModeFilterButtonActionListener.java b/src/fr/monkhanny/dorfromantik/gui/GameModeFilterButtonActionListener.java new file mode 100644 index 0000000..db0a125 --- /dev/null +++ b/src/fr/monkhanny/dorfromantik/gui/GameModeFilterButtonActionListener.java @@ -0,0 +1,18 @@ +package fr.monkhanny.dorfromantik.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class GameModeFilterButtonActionListener implements ActionListener { + private GameModeSelectionPanel panel; + + public GameModeFilterButtonActionListener(GameModeSelectionPanel panel) { + this.panel = panel; + } + + @Override + public void actionPerformed(ActionEvent e) { + panel.setCurrentPage(1); // Reset to first page when filtering + panel.loadSeriesForCurrentPage(); + } +} diff --git a/src/fr/monkhanny/dorfromantik/gui/GameModeHoverEffectMouseListener.java b/src/fr/monkhanny/dorfromantik/gui/GameModeHoverEffectMouseListener.java new file mode 100644 index 0000000..dba2c80 --- /dev/null +++ b/src/fr/monkhanny/dorfromantik/gui/GameModeHoverEffectMouseListener.java @@ -0,0 +1,46 @@ +package fr.monkhanny.dorfromantik.gui; + +import java.awt.Color; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JButton; + +public class GameModeHoverEffectMouseListener extends MouseAdapter { + private Color defaultColor; + private Color hoverColor; + private Color clickColor; + + public GameModeHoverEffectMouseListener(Color defaultColor, Color hoverColor, Color clickColor) { + this.defaultColor = defaultColor; + this.hoverColor = hoverColor; + this.clickColor = clickColor; + } + + @Override + public void mouseEntered(MouseEvent e) { + if (e.getSource() instanceof JButton button) { + button.setBackground(hoverColor); + } + } + + @Override + public void mouseExited(MouseEvent e) { + if (e.getSource() instanceof JButton button) { + button.setBackground(defaultColor); + } + } + + @Override + public void mousePressed(MouseEvent e) { + if (e.getSource() instanceof JButton button) { + button.setBackground(clickColor); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (e.getSource() instanceof JButton button) { + button.setBackground(hoverColor); + } + } +} diff --git a/src/fr/monkhanny/dorfromantik/gui/GameModeNextButtonActionListener.java b/src/fr/monkhanny/dorfromantik/gui/GameModeNextButtonActionListener.java new file mode 100644 index 0000000..6644c54 --- /dev/null +++ b/src/fr/monkhanny/dorfromantik/gui/GameModeNextButtonActionListener.java @@ -0,0 +1,18 @@ +package fr.monkhanny.dorfromantik.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class GameModeNextButtonActionListener implements ActionListener { + private GameModeSelectionPanel panel; + + public GameModeNextButtonActionListener(GameModeSelectionPanel panel) { + this.panel = panel; + } + + @Override + public void actionPerformed(ActionEvent e) { + panel.setCurrentPage(panel.getCurrentPage() + 1); + panel.loadSeriesForCurrentPage(); + } +} diff --git a/src/fr/monkhanny/dorfromantik/gui/GameModePrevButtonActionListener.java b/src/fr/monkhanny/dorfromantik/gui/GameModePrevButtonActionListener.java new file mode 100644 index 0000000..54643ec --- /dev/null +++ b/src/fr/monkhanny/dorfromantik/gui/GameModePrevButtonActionListener.java @@ -0,0 +1,20 @@ +package fr.monkhanny.dorfromantik.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class GameModePrevButtonActionListener implements ActionListener { + private GameModeSelectionPanel panel; + + public GameModePrevButtonActionListener(GameModeSelectionPanel panel) { + this.panel = panel; + } + + @Override + public void actionPerformed(ActionEvent e) { + if (panel.getCurrentPage() > 1) { + panel.setCurrentPage(panel.getCurrentPage() - 1); + panel.loadSeriesForCurrentPage(); + } + } +} diff --git a/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java b/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java index 43959f0..3d14fe8 100644 --- a/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java +++ b/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java @@ -1,6 +1,7 @@ package fr.monkhanny.dorfromantik.gui; import fr.monkhanny.dorfromantik.components.Title; +import fr.monkhanny.dorfromantik.listeners.CloseButtonListener; import fr.monkhanny.dorfromantik.utils.Database; import javax.swing.*; @@ -72,7 +73,7 @@ public class GameModeSelectionPanel extends JPanel { seriesButtons = new ArrayList<>(); // Pagination panel - JPanel paginationPanel = createPaginationPanel(buttonListener); + JPanel paginationPanel = createPaginationPanel(); // Load initial series loadSeriesForCurrentPage(); @@ -87,7 +88,7 @@ public class GameModeSelectionPanel extends JPanel { mainPanel.add(seedPanel, createGridBagConstraints(0, 6, 2)); } - private void loadSeriesForCurrentPage() { + public void loadSeriesForCurrentPage() { // Clear existing buttons modePanel.removeAll(); seriesButtons.clear(); @@ -177,11 +178,7 @@ public class GameModeSelectionPanel extends JPanel { endDateSpinner.setEditor(new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd")); JButton filterButton = new JButton("Filtrer"); - filterButton.addActionListener(e -> { - // Réinitialiser à la première page lors du filtrage - currentPage = 1; - loadSeriesForCurrentPage(); - }); + filterButton.addActionListener(new GameModeFilterButtonActionListener(this)); datePanel.add(startLabel); datePanel.add(startDateSpinner); @@ -192,34 +189,27 @@ public class GameModeSelectionPanel extends JPanel { return datePanel; } - private JPanel createPaginationPanel(ActionListener buttonListener) { + private JPanel createPaginationPanel() { JPanel paginationPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); paginationPanel.setOpaque(false); - + prevButton = new JButton("Précédent"); - prevButton.addActionListener(e -> { - if (currentPage > 1) { - currentPage--; - loadSeriesForCurrentPage(); - } - }); - + prevButton.addActionListener(new GameModePrevButtonActionListener(this)); + nextButton = new JButton("Suivant"); - nextButton.addActionListener(e -> { - currentPage++; - loadSeriesForCurrentPage(); - }); - + nextButton.addActionListener(new GameModeNextButtonActionListener(this)); + pageLabel = new JLabel("Page 1"); pageLabel.setForeground(Color.WHITE); - + paginationPanel.add(prevButton); paginationPanel.add(pageLabel); paginationPanel.add(nextButton); - + return paginationPanel; } + private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) { // Utilisation de BorderLayout pour aligner correctement le bouton à gauche JPanel topPanel = new JPanel(new BorderLayout()); @@ -244,10 +234,7 @@ public class GameModeSelectionPanel extends JPanel { returnButton.setContentAreaFilled(false); returnButton.setBorderPainted(false); returnButton.setFocusPainted(false); - returnButton.addActionListener(e -> { - gameModeFrame.setVisible(false); - mainMenu.setVisible(true); - }); + returnButton.addActionListener(new CloseButtonListener(mainMenu, gameModeFrame)); return returnButton; } @@ -271,25 +258,49 @@ public class GameModeSelectionPanel extends JPanel { private JButton createGameModeButton(String modeName, ActionListener buttonListener) { JButton button = new JButton(modeName); - button.setFont(new Font("Arial", Font.BOLD, 18)); // Slightly smaller font to accommodate longer text - button.setBackground(new Color(0, 122, 255)); - button.setForeground(Color.WHITE); - button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); + button.setFont(new Font("Arial", Font.BOLD, 18)); // Texte clair et lisible + button.setForeground(Color.WHITE); // Texte en blanc + + // Appliquer un fond dégradé + button.setBackground(new Color(70, 130, 180)); // Fond initial + button.setOpaque(true); + + // Ajouter des bordures arrondies + button.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(new Color(255, 255, 255, 120), 2), // Bordure extérieure blanche et semi-transparente + BorderFactory.createEmptyBorder(10, 20, 10, 20) // Espacement intérieur + )); + + button.addMouseListener(new GameModeHoverEffectMouseListener( + new Color(70, 130, 180), // Default + new Color(100, 180, 255), // Hover + new Color(50, 100, 160) // Click + )); + + + // Supprimer l'effet de focus par défaut button.setFocusPainted(false); + + // Ajout de l'action button.addActionListener(buttonListener); - // Calculate button width dynamically based on text length - FontMetrics metrics = button.getFontMetrics(button.getFont()); - int textWidth = metrics.stringWidth(modeName); - int buttonWidth = Math.max(200, textWidth + 40); // Minimum 200, with 20px padding on each side - - button.setPreferredSize(new Dimension(buttonWidth, 50)); - button.setMinimumSize(new Dimension(buttonWidth, 50)); - button.setMaximumSize(new Dimension(buttonWidth, 50)); - + // Ajuster les dimensions du bouton + button.setPreferredSize(new Dimension(200, 50)); // Taille standard pour tous les boutons + return button; } + + public int getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; + } + + + private JPanel createSeedPanel(ActionListener buttonListener) { JPanel seedPanel = new JPanel(); seedPanel.setOpaque(false);