<commit_before>package com.valkryst.VTerminal.builder.component;

import com.valkryst.VJSON.VJSONParser;
import com.valkryst.VTerminal.component.Button;
import com.valkryst.VTerminal.misc.ColorFunctions;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.awt.Color;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=true)
public class ButtonBuilder extends ComponentBuilder<Button> implements VJSONParser {
    /** The text to display on the button. */
    @NonNull private String text;

    /** The background color for when the button is in the normal state. */
    @NonNull private Color backgroundColor_normal;
    /** The foreground color for when the button is in the normal state. */
    @NonNull private Color foregroundColor_normal;

    /** The background color for when the button is in the hover state. */
    @NonNull private Color backgroundColor_hover;
    /** The foreground color for when the button is in the hover state. */
    @NonNull private Color foregroundColor_hover;

    /** The background color for when the button is in the pressed state. */
    @NonNull private Color backgroundColor_pressed;
    /** The foreground color for when the button is in the pressed state. */
    @NonNull private Color foregroundColor_pressed;

    /** The function to run when the button is clicked. */
    private Runnable onClickFunction;

    @Override
    public Button build() {
        checkState();

        super.width = text.length();
        super.height = 1;

        return new Button(this);
    }

    /** Resets the builder to it's default state. */
    public void reset() {
        super.reset();

        text = "";

        backgroundColor_normal = new Color(45, 45, 45, 255);
        foregroundColor_normal = new Color(0xFF2DBEFF, true);

        backgroundColor_hover = new Color(0xFF2DFF63, true);
        foregroundColor_hover = ColorFunctions.shade(backgroundColor_hover, 0.5);

        backgroundColor_pressed = ColorFunctions.shade(backgroundColor_hover, 0.25);
        foregroundColor_pressed = ColorFunctions.shade(foregroundColor_hover, 0.25);

        onClickFunction = () -> {};
    }

    @Override
    public void parse(final @NonNull JSONObject jsonObject) {
        reset();
        super.parse(jsonObject);


        final String text = (String) jsonObject.get("text");


        if (text != null) {
            this.text = text;
        }


        try {
            this.backgroundColor_normal = getColor((JSONArray) jsonObject.get("backgroundColor_normal"));
        } catch (final NullPointerException ignored) {}

        try {
            this.foregroundColor_normal = getColor((JSONArray) jsonObject.get("foregroundColor_normal"));
        } catch (final NullPointerException ignored) {}



        try {
            this.backgroundColor_hover = getColor((JSONArray) jsonObject.get("backgroundColor_hover"));<commit_msg>Updates parse function to make use of the new getString function of VJSON.<commit_after>package com.valkryst.VTerminal.builder.component;

import com.valkryst.VJSON.VJSONParser;
import com.valkryst.VTerminal.component.Button;
import com.valkryst.VTerminal.misc.ColorFunctions;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.awt.Color;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=true)
public class ButtonBuilder extends ComponentBuilder<Button> implements VJSONParser {
    /** The text to display on the button. */
    @NonNull private String text;

    /** The background color for when the button is in the normal state. */
    @NonNull private Color backgroundColor_normal;
    /** The foreground color for when the button is in the normal state. */
    @NonNull private Color foregroundColor_normal;

    /** The background color for when the button is in the hover state. */
    @NonNull private Color backgroundColor_hover;
    /** The foreground color for when the button is in the hover state. */
    @NonNull private Color foregroundColor_hover;

    /** The background color for when the button is in the pressed state. */
    @NonNull private Color backgroundColor_pressed;
    /** The foreground color for when the button is in the pressed state. */
    @NonNull private Color foregroundColor_pressed;

    /** The function to run when the button is clicked. */
    private Runnable onClickFunction;

    @Override
    public Button build() {
        checkState();

        super.width = text.length();
        super.height = 1;

        return new Button(this);
    }

    /** Resets the builder to it's default state. */
    public void reset() {
        super.reset();

        text = "";

        backgroundColor_normal = new Color(45, 45, 45, 255);
        foregroundColor_normal = new Color(0xFF2DBEFF, true);

        backgroundColor_hover = new Color(0xFF2DFF63, true);
        foregroundColor_hover = ColorFunctions.shade(backgroundColor_hover, 0.5);

        backgroundColor_pressed = ColorFunctions.shade(backgroundColor_hover, 0.25);
        foregroundColor_pressed = ColorFunctions.shade(foregroundColor_hover, 0.25);

        onClickFunction = () -> {};
    }

    @Override
    public void parse(final @NonNull JSONObject jsonObject) {
        reset();
        super.parse(jsonObject);


        final String text = getString(jsonObject, "text");


        if (text != null) {
            this.text = text;
        }


        try {
            this.backgroundColor_normal = getColor((JSONArray) jsonObject.get("backgroundColor_normal"));
        } catch (final NullPointerException ignored) {}

        try {
            this.foregroundColor_normal = getColor((JSONArray) jsonObject.get("foregroundColor_normal"));
        } catch (final NullPointerException ignored) {}



        try {
            this.backgroundColor_hover = getColor((JSONArray) jsonObject.get("backgroundColor_hover"));
{'fraction_non_alphanumeric': 0.09078968970612379, 'fraction_numerical': 0.007880479395829913, 'mean_word_length': 3.1984838042729153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '980660', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1598, 'n_words': 487}