<commit_before>package com.github.czyzby.lml.vis.parser.impl.tag;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.action.ActorConsumer;
import com.github.czyzby.lml.parser.impl.attribute.table.OneColumnLmlAttribute;
import com.github.czyzby.lml.parser.impl.tag.AbstractActorLmlTag;
import com.github.czyzby.lml.parser.tag.LmlActorBuilder;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.github.czyzby.lml.util.LmlUserObject;
import com.github.czyzby.lml.util.LmlUtilities;
import com.github.czyzby.lml.vis.ui.VisTabTable;
import com.github.czyzby.lml.vis.ui.reflected.action.TabShowingAction;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.tabbedpane.Tab;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPane;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPaneAdapter;

/** Handles {@link TabbedPane}. Allows to use table attributes: settings will be applied to tabbed pane's main table.
 * Its children, though, should not have any cell attributes; in fact, it is prepared only to handle tab children - see
 * {@link TabLmlTag}. Cannot parse plain text between tags. Note that tabbed pane tag cannot handle
 * {@link OneColumnLmlAttribute} properly. Tabbed pane is not actually an actor - if you want to inject the pane by its
 * ID, use {@link Table} instead and extract {@link TabbedPane} instance with {@link #getTabbedPane(Table)}. Mapped to
 * "tabbedPane", "tabs".
 *
 * @author MJ */
public class TabbedPaneLmlTag extends AbstractActorLmlTag {
    private TabbedPane tabbedPane;
    private boolean attachDefaultListener = true;
    private ActorConsumer<Action, Tab> showActionProvider;
    private ActorConsumer<Action, Tab> hideActionProvider;

    public TabbedPaneLmlTag(final LmlParser parser, final LmlTag parentTag, final String rawTagData) {
        super(parser, parentTag, rawTagData);
    }

    @Override
    protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) {
        tabbedPane = new TabbedPane(builder.getStyleName());
        final Table mainTable = tabbedPane.getTable();
        // TabbedPane will be accessible through LmlUserObject#getData(). This disables oneColumn attribute, though.
        LmlUtilities.getLmlUserObject(mainTable).setData(tabbedPane);
        if (tabbedPane.getTabsPane().isHorizontal()) {
            mainTable.row();
        }
        // This will be the content table:
        mainTable.add(new VisTable()).grow().row();
        // There might be an expand+fill image in the second cell. We need to correct that:
        normalizeSecondCell(mainTable);
        return mainTable;
    }

    /** @param table main table of the {@link TabbedPane}. If LML meta-data was not cleared, it will contain a reference
     *            of its {@link TabbedPane} parent.<commit_msg>Fixed TabbedPane tag.<commit_after>package com.github.czyzby.lml.vis.parser.impl.tag;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.action.ActorConsumer;
import com.github.czyzby.lml.parser.impl.attribute.table.OneColumnLmlAttribute;
import com.github.czyzby.lml.parser.impl.tag.AbstractActorLmlTag;
import com.github.czyzby.lml.parser.tag.LmlActorBuilder;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.github.czyzby.lml.util.LmlUserObject;
import com.github.czyzby.lml.util.LmlUtilities;
import com.github.czyzby.lml.vis.ui.VisTabTable;
import com.github.czyzby.lml.vis.ui.reflected.action.TabShowingAction;
import com.kotcrab.vis.ui.layout.HorizontalFlowGroup;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.tabbedpane.Tab;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPane;
import com.kotcrab.vis.ui.widget.tabbedpane.TabbedPaneAdapter;

/** Handles {@link TabbedPane}. Allows to use table attributes: settings will be applied to tabbed pane's main table.
 * Its children, though, should not have any cell attributes; in fact, it is prepared only to handle tab children - see
 * {@link TabLmlTag}. Cannot parse plain text between tags. Note that tabbed pane tag cannot handle
 * {@link OneColumnLmlAttribute} properly. Tabbed pane is not actually an actor - if you want to inject the pane by its
 * ID, use {@link Table} instead and extract {@link TabbedPane} instance with {@link #getTabbedPane(Table)}. Mapped to
 * "tabbedPane", "tabs".
 *
 * @author MJ */
public class TabbedPaneLmlTag extends AbstractActorLmlTag {
    private TabbedPane tabbedPane;
    private boolean attachDefaultListener = true;
    private ActorConsumer<Action, Tab> showActionProvider;
    private ActorConsumer<Action, Tab> hideActionProvider;

    public TabbedPaneLmlTag(final LmlParser parser, final LmlTag parentTag, final String rawTagData) {
        super(parser, parentTag, rawTagData);
    }

    @Override
    protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) {
        tabbedPane = new TabbedPane(builder.getStyleName());
        final Table mainTable = tabbedPane.getTable();
        // TabbedPane will be accessible through LmlUserObject#getData(). This disables oneColumn attribute, though.
        LmlUtilities.getLmlUserObject(mainTable).setData(tabbedPane);
        if (tabbedPane.getTabsPane().isHorizontal()
                || tabbedPane.getTabsPane().getActor() instanceof HorizontalFlowGroup) {
            mainTable.row();
        }
        // This will be the content table:
        mainTable.add(new VisTable()).grow().row();
        // There might be an expand+fill image in the second cell. We need to correct that:
        normalizeSecondCell(mainTable);
        return mainTable;
    }

    /** @param table main table of the {@link TabbedPane}. If LML meta-data was not cleared, it will contain a reference
     *            of its {@link TabbedPane} parent.
{'fraction_non_alphanumeric': 0.10073148430356599, 'fraction_numerical': 0.001828710758914965, 'mean_word_length': 4.188142292490118, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2497427', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2071, 'n_words': 504}