Amélioration
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
package fr.monkhanny.dorfromantik.gui;
|
package fr.monkhanny.dorfromantik.gui;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.components.Title;
|
import fr.monkhanny.dorfromantik.components.Title;
|
||||||
|
import fr.monkhanny.dorfromantik.listeners.CloseButtonListener;
|
||||||
import fr.monkhanny.dorfromantik.utils.Database;
|
import fr.monkhanny.dorfromantik.utils.Database;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -72,7 +73,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
seriesButtons = new ArrayList<>();
|
seriesButtons = new ArrayList<>();
|
||||||
|
|
||||||
// Pagination panel
|
// Pagination panel
|
||||||
JPanel paginationPanel = createPaginationPanel(buttonListener);
|
JPanel paginationPanel = createPaginationPanel();
|
||||||
|
|
||||||
// Load initial series
|
// Load initial series
|
||||||
loadSeriesForCurrentPage();
|
loadSeriesForCurrentPage();
|
||||||
@@ -87,7 +88,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
mainPanel.add(seedPanel, createGridBagConstraints(0, 6, 2));
|
mainPanel.add(seedPanel, createGridBagConstraints(0, 6, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSeriesForCurrentPage() {
|
public void loadSeriesForCurrentPage() {
|
||||||
// Clear existing buttons
|
// Clear existing buttons
|
||||||
modePanel.removeAll();
|
modePanel.removeAll();
|
||||||
seriesButtons.clear();
|
seriesButtons.clear();
|
||||||
@@ -177,11 +178,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
endDateSpinner.setEditor(new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd"));
|
endDateSpinner.setEditor(new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd"));
|
||||||
|
|
||||||
JButton filterButton = new JButton("Filtrer");
|
JButton filterButton = new JButton("Filtrer");
|
||||||
filterButton.addActionListener(e -> {
|
filterButton.addActionListener(new GameModeFilterButtonActionListener(this));
|
||||||
// Réinitialiser à la première page lors du filtrage
|
|
||||||
currentPage = 1;
|
|
||||||
loadSeriesForCurrentPage();
|
|
||||||
});
|
|
||||||
|
|
||||||
datePanel.add(startLabel);
|
datePanel.add(startLabel);
|
||||||
datePanel.add(startDateSpinner);
|
datePanel.add(startDateSpinner);
|
||||||
@@ -192,23 +189,15 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
return datePanel;
|
return datePanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createPaginationPanel(ActionListener buttonListener) {
|
private JPanel createPaginationPanel() {
|
||||||
JPanel paginationPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
JPanel paginationPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||||
paginationPanel.setOpaque(false);
|
paginationPanel.setOpaque(false);
|
||||||
|
|
||||||
prevButton = new JButton("Précédent");
|
prevButton = new JButton("Précédent");
|
||||||
prevButton.addActionListener(e -> {
|
prevButton.addActionListener(new GameModePrevButtonActionListener(this));
|
||||||
if (currentPage > 1) {
|
|
||||||
currentPage--;
|
|
||||||
loadSeriesForCurrentPage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
nextButton = new JButton("Suivant");
|
nextButton = new JButton("Suivant");
|
||||||
nextButton.addActionListener(e -> {
|
nextButton.addActionListener(new GameModeNextButtonActionListener(this));
|
||||||
currentPage++;
|
|
||||||
loadSeriesForCurrentPage();
|
|
||||||
});
|
|
||||||
|
|
||||||
pageLabel = new JLabel("Page 1");
|
pageLabel = new JLabel("Page 1");
|
||||||
pageLabel.setForeground(Color.WHITE);
|
pageLabel.setForeground(Color.WHITE);
|
||||||
@@ -220,6 +209,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
return paginationPanel;
|
return paginationPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) {
|
private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) {
|
||||||
// Utilisation de BorderLayout pour aligner correctement le bouton à gauche
|
// Utilisation de BorderLayout pour aligner correctement le bouton à gauche
|
||||||
JPanel topPanel = new JPanel(new BorderLayout());
|
JPanel topPanel = new JPanel(new BorderLayout());
|
||||||
@@ -244,10 +234,7 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
returnButton.setContentAreaFilled(false);
|
returnButton.setContentAreaFilled(false);
|
||||||
returnButton.setBorderPainted(false);
|
returnButton.setBorderPainted(false);
|
||||||
returnButton.setFocusPainted(false);
|
returnButton.setFocusPainted(false);
|
||||||
returnButton.addActionListener(e -> {
|
returnButton.addActionListener(new CloseButtonListener(mainMenu, gameModeFrame));
|
||||||
gameModeFrame.setVisible(false);
|
|
||||||
mainMenu.setVisible(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
return returnButton;
|
return returnButton;
|
||||||
}
|
}
|
||||||
@@ -271,25 +258,49 @@ public class GameModeSelectionPanel extends JPanel {
|
|||||||
|
|
||||||
private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
|
private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
|
||||||
JButton button = new JButton(modeName);
|
JButton button = new JButton(modeName);
|
||||||
button.setFont(new Font("Arial", Font.BOLD, 18)); // Slightly smaller font to accommodate longer text
|
button.setFont(new Font("Arial", Font.BOLD, 18)); // Texte clair et lisible
|
||||||
button.setBackground(new Color(0, 122, 255));
|
button.setForeground(Color.WHITE); // Texte en blanc
|
||||||
button.setForeground(Color.WHITE);
|
|
||||||
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
// 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);
|
button.setFocusPainted(false);
|
||||||
|
|
||||||
|
// Ajout de l'action
|
||||||
button.addActionListener(buttonListener);
|
button.addActionListener(buttonListener);
|
||||||
|
|
||||||
// Calculate button width dynamically based on text length
|
// Ajuster les dimensions du bouton
|
||||||
FontMetrics metrics = button.getFontMetrics(button.getFont());
|
button.setPreferredSize(new Dimension(200, 50)); // Taille standard pour tous les boutons
|
||||||
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));
|
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getCurrentPage() {
|
||||||
|
return currentPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentPage(int currentPage) {
|
||||||
|
this.currentPage = currentPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private JPanel createSeedPanel(ActionListener buttonListener) {
|
private JPanel createSeedPanel(ActionListener buttonListener) {
|
||||||
JPanel seedPanel = new JPanel();
|
JPanel seedPanel = new JPanel();
|
||||||
seedPanel.setOpaque(false);
|
seedPanel.setOpaque(false);
|
||||||
|
Reference in New Issue
Block a user