package fr.monkhanny.dorfromantik.enums; import java.io.File; import java.io.IOException; import java.awt.Font; import java.awt.FontFormatException; public enum Fonts { TITLE, BUTTON, SCORE; public String getFontPath() { switch (this) { case TITLE: return "./ressources/fonts/Contage-Black.ttf"; case BUTTON: return "./ressources/fonts/Contage-Regular.ttf"; case SCORE: return "./ressources/fonts/Contage-Bold.ttf"; default: throw new IllegalArgumentException("Unexpected value: " + this); } } public Font getFont(float size) { try { switch (this) { case TITLE: return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Black.ttf")).deriveFont(size); case BUTTON: return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Regular.ttf")).deriveFont(size); case SCORE: return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Bold.ttf")).deriveFont(size); default: throw new IllegalArgumentException("Unexpected value: " + this); } } catch (IOException | FontFormatException e) { e.printStackTrace(); // Retourner une police de secours si le fichier est introuvable ou s'il y a une erreur return new Font("Arial", Font.PLAIN, (int) size); } } }