<commit_before>package ui.components.pickers;

import backend.resource.TurboLabel;

import com.sun.javafx.tk.FontLoader;
import com.sun.javafx.tk.Toolkit;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;

/**
 * This class is to represent a label in LabelPickerDialog
 *
 * It contains attributes such as selected, highlighted, removed and faded in order
 * to produce the appropriate styled node through getNode()
 */
public class PickerLabel extends TurboLabel {

    private boolean isSelected;
    private boolean isHighlighted;
    private boolean isRemoved;
    private boolean isFaded;
    private final boolean canDisplayFullName;

    public PickerLabel(TurboLabel label, boolean canDisplayFullName) {
        super(label.getRepoId(), label.getColour(), label.getFullName());
        isSelected = false;
        isHighlighted = false;
        isRemoved = false;
        isFaded = false;
        this.canDisplayFullName = canDisplayFullName;
    }

    @Override
    public Node getNode() {
        // actual name for labels at the top, add tick for selected labels
        Label label = new Label((canDisplayFullName ? getFullName() : getShortName()));
        label.getStyleClass().add("labels");
        if (isRemoved) label.getStyleClass().add("labels-removed"); // add strikethrough
        String style = getStyle() + (isHighlighted ? " -fx-border-color: black;" : ""); // add highlight border
        style += (isFaded ? " -fx-opacity: 40%;" : ""); // change opacity if needed
        label.setStyle(style);

        FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
        double width = (double) fontLoader.computeStringWidth(label.getText(), label.getFont());
        label.setPrefWidth(width + 30);
        label.setText(label.getText() + (!canDisplayFullName && isSelected ? " ✓" : ""));

        if (isInGroup()) {
            Tooltip groupTooltip = new Tooltip(getGroupName());
            label.setTooltip(groupTooltip);
        }
        return label;
    }

    public boolean isSelected() {
        return isSelected;<commit_msg>Moves setText before setting width to ensure all texts are displayed properly<commit_after>package ui.components.pickers;

import backend.resource.TurboLabel;

import com.sun.javafx.tk.FontLoader;
import com.sun.javafx.tk.Toolkit;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;

/**
 * This class is to represent a label in LabelPickerDialog
 *
 * It contains attributes such as selected, highlighted, removed and faded in order
 * to produce the appropriate styled node through getNode()
 */
public class PickerLabel extends TurboLabel {

    private boolean isSelected;
    private boolean isHighlighted;
    private boolean isRemoved;
    private boolean isFaded;
    private final boolean canDisplayFullName;

    public PickerLabel(TurboLabel label, boolean canDisplayFullName) {
        super(label.getRepoId(), label.getColour(), label.getFullName());
        isSelected = false;
        isHighlighted = false;
        isRemoved = false;
        isFaded = false;
        this.canDisplayFullName = canDisplayFullName;
    }

    @Override
    public Node getNode() {
        // actual name for labels at the top, add tick for selected labels
        Label label = new Label((canDisplayFullName ? getFullName() : getShortName()));
        label.getStyleClass().add("labels");
        if (isRemoved) label.getStyleClass().add("labels-removed"); // add strikethrough
        String style = getStyle() + (isHighlighted ? " -fx-border-color: black;" : ""); // add highlight border
        style += (isFaded ? " -fx-opacity: 40%;" : ""); // change opacity if needed
        label.setStyle(style);
        label.setText(label.getText() + (!canDisplayFullName && isSelected ? " ✓" : ""));

        FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
        double width = (double) fontLoader.computeStringWidth(label.getText(), label.getFont());
        label.setPrefWidth(width + 30);

        if (isInGroup()) {
            Tooltip groupTooltip = new Tooltip(getGroupName());
            label.setTooltip(groupTooltip);
        }
        return label;
    }

    public boolean isSelected() {
        return isSelected;
{'fraction_non_alphanumeric': 0.10790697674418605, 'fraction_numerical': 0.0018604651162790699, 'mean_word_length': 3.1920077972709553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3744633', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1162, 'n_words': 322}