Ajouts d'une version BETA du menu principal qui respecte le modèle MVC et la responsabilité unique + Modifications du README.md
This commit is contained in:
33
TestV2/src/fr/monkhanny/dorfromantik/utils/FontLoader.java
Normal file
33
TestV2/src/fr/monkhanny/dorfromantik/utils/FontLoader.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Classe utilitaire pour charger des polices à partir de fichiers.
|
||||
* @version 1.0
|
||||
* @author Moncef STITI
|
||||
* @see Fonts
|
||||
* @see Font
|
||||
*/
|
||||
public class FontLoader {
|
||||
|
||||
/**
|
||||
* Charge une police à partir du fichier spécifié.
|
||||
* @param fontEnumName Enumération de la police à charger.
|
||||
* @return La police chargée.
|
||||
* @throws IOException Si une erreur se produit lors de la lecture du fichier.
|
||||
* @throws FontFormatException Si une erreur se produit lors de la création de la police.
|
||||
*/
|
||||
public static Font loadFont(Fonts fontEnumName) throws IOException, FontFormatException {
|
||||
String fontFilePath = fontEnumName.getFontPath();
|
||||
File fontFile = new File(fontFilePath);
|
||||
Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(customFont);
|
||||
return customFont;
|
||||
}
|
||||
}
|
70
TestV2/src/fr/monkhanny/dorfromantik/utils/FontManager.java
Normal file
70
TestV2/src/fr/monkhanny/dorfromantik/utils/FontManager.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FontManager {
|
||||
|
||||
private static Font titleFont;
|
||||
private static Font buttonFont;
|
||||
|
||||
// Charge et applique la police spécifique en fonction de Fonts
|
||||
public static void loadCustomFont(Fonts fontEnum) {
|
||||
try {
|
||||
Font loadedFont = FontLoader.loadFont(fontEnum);
|
||||
if (fontEnum == Fonts.TITLE) {
|
||||
titleFont = loadedFont;
|
||||
} else if (fontEnum == Fonts.BUTTON) {
|
||||
buttonFont = loadedFont;
|
||||
}
|
||||
} catch (IOException | FontFormatException e) {
|
||||
throw new RuntimeException("Failed to load font: " + fontEnum, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtient la police du titre avec une taille spécifique
|
||||
public static Font getTitleFont(float size) {
|
||||
if (titleFont == null) {
|
||||
throw new IllegalStateException("Title font not loaded. Please load the font first.");
|
||||
}
|
||||
return titleFont.deriveFont(size);
|
||||
}
|
||||
|
||||
// Obtient la police du bouton avec une taille spécifique
|
||||
public static Font getButtonFont(float size) {
|
||||
if (buttonFont == null) {
|
||||
throw new IllegalStateException("Button font not loaded. Please load the font first.");
|
||||
}
|
||||
return buttonFont.deriveFont(size);
|
||||
}
|
||||
|
||||
// Ajuste la taille de la police du titre selon la taille du composant sans la modifier directement
|
||||
public static Font getAdjustedTitleFont(Component component, float minSize, float maxSize) {
|
||||
if (titleFont == null) {
|
||||
throw new IllegalStateException("Title font not loaded. Please load the font first.");
|
||||
}
|
||||
float newSize = Math.max(minSize, Math.min(maxSize, component.getWidth() / 12f));
|
||||
return titleFont.deriveFont(newSize);
|
||||
}
|
||||
|
||||
// Ajuste la taille de la police du bouton selon la taille du composant sans la modifier directement
|
||||
public static Font getAdjustedButtonFont(Component component, float minSize, float maxSize) {
|
||||
if (buttonFont == null) {
|
||||
throw new IllegalStateException("Button font not loaded. Please load the font first.");
|
||||
}
|
||||
float newSize = Math.max(minSize, Math.min(maxSize, component.getHeight() / 20f));
|
||||
return buttonFont.deriveFont(newSize);
|
||||
}
|
||||
|
||||
// Définir manuellement une police de titre personnalisée
|
||||
public static void setTitleFont(Font font) {
|
||||
titleFont = font;
|
||||
}
|
||||
|
||||
// Définir manuellement une police de bouton personnalisée
|
||||
public static void setButtonFont(Font font) {
|
||||
buttonFont = font;
|
||||
}
|
||||
}
|
35
TestV2/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java
Normal file
35
TestV2/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* Classe utilitaire pour charger des images à partir de fichiers.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Moncef STITI
|
||||
*/
|
||||
public class ImageLoader {
|
||||
/**
|
||||
* Icône de l'application.
|
||||
*/
|
||||
public static final Image APPLICATION_ICON = ImageLoader.loadImage("./ressources/images/Application/Application_Icon.jpg");
|
||||
|
||||
/**
|
||||
* Charge une image à partir du fichier spécifié.
|
||||
*
|
||||
* @param filePath Chemin du fichier image à charger.
|
||||
* @return L'image chargée, ou null si une erreur se produit.
|
||||
*/
|
||||
public static Image loadImage(String filePath) {
|
||||
try {
|
||||
File imageFile = new File(filePath);
|
||||
return ImageIO.read(imageFile);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Erreur lors du chargement de l'image : " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user