diff --git a/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java b/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java index f6fcc6b..42340c0 100644 --- a/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java +++ b/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java @@ -22,6 +22,7 @@ import java.util.Locale; import java.util.Map; import javax.swing.JOptionPane; +import javax.swing.UIManager; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -67,6 +68,17 @@ public class Main Locale.setDefault(Locale.FRANCE); + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception e) + { + new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); + System.err.print("Caused by "); + e.printStackTrace(); + } + try { new File(Main.class.getResource("/assets").toURI()); diff --git a/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java b/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java index 7159156..5dd8925 100644 --- a/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java +++ b/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java @@ -3,6 +3,7 @@ */ package galaxyoyo.gameengine.frame; +import galaxyoyo.gameengine.frame.listeners.ChangeLAFListener; import galaxyoyo.gameengine.frame.listeners.CreateMapListener; import galaxyoyo.gameengine.frame.listeners.OpenMapListener; @@ -44,9 +45,14 @@ public class MainFrame extends JFrame private JMenuBar menuBar = new JMenuBar(); private JMenu fichier = new JMenu("Fichier"); + private JMenu display = new JMenu("Affichage"); private JMenu editMaps = new JMenu("Cartes"); + private JMenu changeLAF = new JMenu("Modfier l'apparence"); private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); private JMenuItem openMap = new JMenuItem("Ouvrir"); + private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me"); + private JMenuItem javaLAF = new JMenuItem("Apparence Java"); + private JMenuItem darkLAF = new JMenuItem("Apparence sombre"); /** * Constructeur @@ -64,6 +70,7 @@ public class MainFrame extends JFrame this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); + display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK); createMap.addActionListener(new CreateMapListener()); editMaps.add(createMap); @@ -72,7 +79,17 @@ public class MainFrame extends JFrame fichier.add(editMaps); + systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this)); + changeLAF.add(systemLAF); + javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this)); + changeLAF.add(javaLAF); + darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this)); + changeLAF.add(darkLAF); + + display.add(changeLAF); + menuBar.add(fichier); + menuBar.add(display); this.setJMenuBar(menuBar); } diff --git a/src/main/java/galaxyoyo/gameengine/frame/listeners/ChangeLAFListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/ChangeLAFListener.java new file mode 100644 index 0000000..f128dae --- /dev/null +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/ChangeLAFListener.java @@ -0,0 +1,70 @@ +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.gameengine.frame.MainFrame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +public class ChangeLAFListener implements ActionListener +{ + private final JMenuItem item; + private final JFrame frame; + + public ChangeLAFListener(JMenuItem LAF, MainFrame f) + { + this.item = LAF; + this.frame = f; + } + + @Override + public void actionPerformed(ActionEvent event) + { + if (item.getText().toLowerCase().contains("sys")) + { + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception e) + { + new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); + System.err.print("Caused by "); + e.printStackTrace(); + } + SwingUtilities.updateComponentTreeUI(frame); + } + else if (item.getText().toLowerCase().contains("java")) + { + try + { + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + } + catch (Exception e) + { + new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); + System.err.print("Caused by "); + e.printStackTrace(); + } + SwingUtilities.updateComponentTreeUI(frame); + } + else if (item.getText().toLowerCase().contains("sombre")) + { + try + { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); + } + catch (Exception e) + { + new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); + System.err.print("Caused by "); + e.printStackTrace(); + } + SwingUtilities.updateComponentTreeUI(frame); + } + } +}