<commit_before>
package com.techjar.ledcm.util.input;

import com.techjar.ledcm.LEDCubeManager;
import com.techjar.ledcm.gui.GUI;
import com.techjar.ledcm.gui.GUIBackground;
import com.techjar.ledcm.gui.GUICallback;
import com.techjar.ledcm.gui.GUIContainer;
import com.techjar.ledcm.gui.GUIInputOption;
import com.techjar.ledcm.gui.GUILabel;
import com.techjar.ledcm.gui.GUIScrollBox;
import com.techjar.ledcm.gui.GUISpacer;
import com.techjar.ledcm.gui.GUITabbed;
import com.techjar.ledcm.gui.screen.ScreenMainControl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.lwjgl.util.Color;

/**
 *
 * @author Techjar
 */
public class InputBindingManager {
    private static final List<InputBinding> bindings = new ArrayList<>();
    private static boolean configLoaded;
    private static boolean settingsLoaded;

    private InputBindingManager() {
    }

    public static List<InputBinding> getBindings() {
        return Collections.unmodifiableList(bindings);
    }

    public static void addBinding(InputBinding binding) {
        if (configLoaded) loadConfig(binding);
        if (settingsLoaded) setupSettings();
        bindings.add(binding);
    }

    public static void removeBinding(InputBinding binding) {
        if (settingsLoaded) setupSettings();
        bindings.remove(binding);
    }

    public static void loadAllConfig() {
        for (InputBinding binding : bindings) {
            loadConfig(binding);
        }
        configLoaded = true;
    }

    public static void setupSettings() {
        ScreenMainControl screen = LEDCubeManager.getInstance().getScreenMainControl();
        final GUITabbed tabbed = screen.controlsTabbed;
        tabbed.clear();
        List<String> categories = new ArrayList<>();
        for (InputBinding binding : bindings) {
            if (!categories.contains(binding.getCategory())) {
                categories.add(binding.getCategory());
            }
        }
        final List<GUIContainer> boxes = new ArrayList<>();
        for (String category : categories) {
            GUIScrollBox box = new GUIScrollBox(new Color(255, 0, 0));
            box.setScrollXMode(GUIScrollBox.ScrollMode.DISABLED);
            box.setScrollYMode(GUIScrollBox.ScrollMode.AUTOMATIC);
            boxes.add(box);
            tabbed.addTab(category, box);
            int boxWidth = (int)box.getContainerBox().getWidth();
            float position = 10;
            int labelWidth = 0;
            for (InputBinding binding : bindings) {
                int width = screen.font.getWidth(binding.getName());<commit_msg>Fix operation order issue and prevent ID conflicts in InputBindingManager<commit_after>
package com.techjar.ledcm.util.input;

import com.techjar.ledcm.LEDCubeManager;
import com.techjar.ledcm.gui.GUI;
import com.techjar.ledcm.gui.GUIBackground;
import com.techjar.ledcm.gui.GUICallback;
import com.techjar.ledcm.gui.GUIContainer;
import com.techjar.ledcm.gui.GUIInputOption;
import com.techjar.ledcm.gui.GUILabel;
import com.techjar.ledcm.gui.GUIScrollBox;
import com.techjar.ledcm.gui.GUISpacer;
import com.techjar.ledcm.gui.GUITabbed;
import com.techjar.ledcm.gui.screen.ScreenMainControl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.lwjgl.util.Color;

/**
 *
 * @author Techjar
 */
public class InputBindingManager {
    private static final List<InputBinding> bindings = new ArrayList<>();
    private static boolean configLoaded;
    private static boolean settingsLoaded;

    private InputBindingManager() {
    }

    public static List<InputBinding> getBindings() {
        return Collections.unmodifiableList(bindings);
    }

    public static void addBinding(InputBinding binding) {
        if (bindings.contains(binding)) return;
        for (InputBinding bind : bindings) {
            if (bind.getId().toLowerCase().equals(binding.getId().toLowerCase())) {
                throw new IllegalArgumentException("Binding with ID \"" + binding.getId() + "\" already exists!");
            }
        }
        bindings.add(binding);
        if (configLoaded) loadConfig(binding);
        if (settingsLoaded) setupSettings();
    }

    public static void removeBinding(InputBinding binding) {
        if (!bindings.contains(binding)) return;
        bindings.remove(binding);
        if (settingsLoaded) setupSettings();
    }

    public static void loadAllConfig() {
        for (InputBinding binding : bindings) {
            loadConfig(binding);
        }
        configLoaded = true;
    }

    public static void setupSettings() {
        ScreenMainControl screen = LEDCubeManager.getInstance().getScreenMainControl();
        final GUITabbed tabbed = screen.controlsTabbed;
        tabbed.clear();
        List<String> categories = new ArrayList<>();
        for (InputBinding binding : bindings) {
            if (!categories.contains(binding.getCategory())) {
                categories.add(binding.getCategory());
            }
        }
        final List<GUIContainer> boxes = new ArrayList<>();
        for (String category : categories) {
            GUIScrollBox box = new GUIScrollBox(new Color(255, 0, 0));
            box.setScrollXMode(GUIScrollBox.ScrollMode.DISABLED);
            box.setScrollYMode(GUIScrollBox.ScrollMode.AUTOMATIC);
            boxes.add(box);
            tabbed.addTab(category, box);
            int boxWidth = (int)box.getContainerBox().getWidth();
            float position = 10;
            int labelWidth = 0;
            for (InputBinding binding : bindings) {
                int width = screen.font.getWidth(binding.getName());
{'fraction_non_alphanumeric': 0.1055427660704799, 'fraction_numerical': 0.0028333628475296618, 'mean_word_length': 2.9579537491240364, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561126', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1575, 'n_words': 334}