summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/config/Themes.java
blob: 00324f4703df74fe154d2614bca5b6c647ca03b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cuchaz.enigma.config;

import com.google.common.collect.ImmutableMap;
import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.EnigmaSyntaxKit;
import cuchaz.enigma.gui.highlight.BoxHighlightPainter;
import de.sciss.syntaxpane.DefaultSyntaxKit;

import javax.swing.*;
import java.io.IOException;

public class Themes {

    public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) {
        Config.getInstance().lookAndFeel = lookAndFeel;
	    updateTheme(gui);
    }

    public static void updateTheme(Gui gui) {
        Config.getInstance().lookAndFeel.apply(Config.getInstance());
        Config.getInstance().lookAndFeel.setGlobalLAF();
        try {
	        Config.getInstance().saveConfig();
        } catch (IOException e) {
            e.printStackTrace();
        }
        EnigmaSyntaxKit.invalidate();
        DefaultSyntaxKit.initKit();
        DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName());
        gui.boxHighlightPainters = ImmutableMap.of(
                "obfuscated", BoxHighlightPainter.create(Config.getInstance().obfuscatedColor, Config.getInstance().obfuscatedColorOutline),
                "proposed", BoxHighlightPainter.create(Config.getInstance().proposedColor, Config.getInstance().proposedColorOutline),
                "deobfuscated", BoxHighlightPainter.create(Config.getInstance().deobfuscatedColor, Config.getInstance().deobfuscatedColorOutline),
                "other", BoxHighlightPainter.create(null, Config.getInstance().otherColorOutline)
        );
        gui.setEditorTheme(Config.getInstance().lookAndFeel);
        SwingUtilities.updateComponentTreeUI(gui.getFrame());
    }
}