mirror of
https://github.com/ynerant/Level-Editor.git
synced 2024-11-26 05:13:48 +00:00
Possibilité de changer le style de foenêtre ('Look And Feel')
This commit is contained in:
parent
6bbb25322a
commit
226e4d46a4
@ -22,6 +22,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
@ -67,6 +68,17 @@ public class Main
|
|||||||
|
|
||||||
Locale.setDefault(Locale.FRANCE);
|
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
|
try
|
||||||
{
|
{
|
||||||
new File(Main.class.getResource("/assets").toURI());
|
new File(Main.class.getResource("/assets").toURI());
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package galaxyoyo.gameengine.frame;
|
package galaxyoyo.gameengine.frame;
|
||||||
|
|
||||||
|
import galaxyoyo.gameengine.frame.listeners.ChangeLAFListener;
|
||||||
import galaxyoyo.gameengine.frame.listeners.CreateMapListener;
|
import galaxyoyo.gameengine.frame.listeners.CreateMapListener;
|
||||||
import galaxyoyo.gameengine.frame.listeners.OpenMapListener;
|
import galaxyoyo.gameengine.frame.listeners.OpenMapListener;
|
||||||
|
|
||||||
@ -44,9 +45,14 @@ public class MainFrame extends JFrame
|
|||||||
|
|
||||||
private JMenuBar menuBar = new JMenuBar();
|
private JMenuBar menuBar = new JMenuBar();
|
||||||
private JMenu fichier = new JMenu("Fichier");
|
private JMenu fichier = new JMenu("Fichier");
|
||||||
|
private JMenu display = new JMenu("Affichage");
|
||||||
private JMenu editMaps = new JMenu("Cartes");
|
private JMenu editMaps = new JMenu("Cartes");
|
||||||
|
private JMenu changeLAF = new JMenu("Modfier l'apparence");
|
||||||
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
|
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
|
||||||
private JMenuItem openMap = new JMenuItem("Ouvrir");
|
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
|
* Constructeur
|
||||||
@ -64,6 +70,7 @@ public class MainFrame extends JFrame
|
|||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
|
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
|
||||||
|
display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK);
|
||||||
|
|
||||||
createMap.addActionListener(new CreateMapListener());
|
createMap.addActionListener(new CreateMapListener());
|
||||||
editMaps.add(createMap);
|
editMaps.add(createMap);
|
||||||
@ -72,7 +79,17 @@ public class MainFrame extends JFrame
|
|||||||
|
|
||||||
fichier.add(editMaps);
|
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(fichier);
|
||||||
|
menuBar.add(display);
|
||||||
|
|
||||||
this.setJMenuBar(menuBar);
|
this.setJMenuBar(menuBar);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user