package org.jabref.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;

import org.jabref.Globals;
import org.jabref.gui.keyboard.EmacsKeyBindings;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.preferences.JabRefPreferences;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Static variables for graphics files and keyboard shortcuts.
 */
public class GUIGlobals {
    public static Color editorTextColor;
    public static Color validFieldBackgroundColor;
    public static Color activeBackgroundColor;
    public static Color invalidFieldBackgroundColor;
    public static Font currentFont;
    public static final Color NULL_FIELD_COLOR = new Color(75, 130, 95); // Valid field, green.

    public static final Color ACTIVE_EDITOR_COLOR = new Color(230, 230, 255);
    public static final int WIDTH_ICON_COL = JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL) + 12; // add some additional space to improve appearance

    public static final int WIDTH_ICON_COL_RANKING = 5 * JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL); // Width of Ranking Icon Column

    public static final String UNTITLED_TITLE = Localization.lang("untitled");

    //	Colors.
    public static final Color ENTRY_EDITOR_LABEL_COLOR = new Color(100, 100, 150); // Empty field, blue.

    private static final Logger LOGGER = LoggerFactory.getLogger(GUIGlobals.class);

    private GUIGlobals() {
    }

    public static void updateEntryEditorColors() {
        GUIGlobals.activeBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR);
        GUIGlobals.validFieldBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.VALID_FIELD_BACKGROUND_COLOR);
        GUIGlobals.invalidFieldBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.INVALID_FIELD_BACKGROUND_COLOR);
        GUIGlobals.editorTextColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.FIELD_EDITOR_TEXT_COLOR);
    }

    /**
     * Perform initializations that are only used in graphical mode. This is to prevent
     * the "Xlib: connection to ":0.0" refused by server" error when access to the X server
     * on Un*x is unavailable.
     */
    public static void init() {
        if (Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS)) {
            EmacsKeyBindings.load();
        }

        // Set up entry editor colors, first time:
        GUIGlobals.updateEntryEditorColors();

        GUIGlobals.currentFont = new Font(Globals.prefs.get(JabRefPreferences.FONT_FAMILY),
                Globals.prefs.getInt(JabRefPreferences.FONT_STYLE), Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));

        // Set WM_CLASS using reflection for certain Un*x window managers
        if (!OS.WINDOWS && !OS.OS_X) {
            try {
                Toolkit xToolkit = Toolkit.getDefaultToolkit();
                java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
                awtAppClassNameField.setAccessible(true);
                awtAppClassNameField.set(xToolkit, "org-jabref-JabRefMain");
            } catch (Exception e) {
                // ignore any error since this code only works for certain toolkits
            }
        }

    }

    public static void setFont(int size) {
        currentFont = new Font(currentFont.getFamily(), currentFont.getStyle(), size);
        // update preferences
        Globals.prefs.putInt(JabRefPreferences.FONT_SIZE, size);
    }

}

@@ -66,33 +66,8 @@
 ont;
-%0Aimport java.awt.Toolkit;
 %0A%0Aim
@@ -187,41 +187,8 @@
 on;%0A
-import org.jabref.logic.util.OS;%0A
 impo
@@ -2757,604 +2757,8 @@
 ));%0A
-%0A        // Set WM_CLASS using reflection for certain Un*x window managers%0A        if (!OS.WINDOWS && !OS.OS_X) %7B%0A            try %7B%0A                Toolkit xToolkit = Toolkit.getDefaultToolkit();%0A                java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField(%22awtAppClassName%22);%0A                awtAppClassNameField.setAccessible(true);%0A                awtAppClassNameField.set(xToolkit, %22org-jabref-JabRefMain%22);%0A            %7D catch (Exception e) %7B%0A                // ignore any error since this code only works for certain toolkits%0A            %7D%0A        %7D%0A%0A
     

Remove reflection hack to set WM_CLASS (#4034)