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;
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user