<commit_before>/*
 * Copyright <NAME>
 */
package flatgui.core.engine.ui;

import clojure.lang.Var;
import flatgui.core.FGHostStateEvent;
import flatgui.core.awt.AbstractHostComponent;
import flatgui.core.engine.*;
import flatgui.core.engine.Container;
import flatgui.core.websocket.FGWebInteropUtil;
import flatgui.run.FGRunUtil;

import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.NoninvertibleTransformException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.*;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author <NAME>
 */
public class FGAWTAppContainer extends FGAppContainer<FGWebInteropUtil>
{
    private HostComponent hostComponent_;

    public FGAWTAppContainer(Map<Object, Object> container)
    {
        this(container, DFLT_UNIT_SIZE_PX);
    }

    public FGAWTAppContainer(Map<Object, Object> container, int unitSizePx)
    {
        super(container.get(ClojureContainerParser.getIdKey()).toString(), container, new FGWebInteropUtil(unitSizePx), new FGClojureResultCollector(unitSizePx), unitSizePx);
    }

    public static FGAWTAppContainer loadSourceCreateAndInit(InputStream source, String containerNs, String containerVarName)
    {
        String sourceCode = new Scanner(source).useDelimiter("\\Z").next();

        System.out.println(clojure.lang.RT.byteCast(1));
        clojure.lang.Compiler.load(new StringReader(sourceCode));

        return createAndInit(containerNs, containerVarName);
    }

    public static FGAWTAppContainer createAndInit(String containerNs, String containerVarName)
    {
        Var containerVar = FGRunUtil.getVar(containerNs, containerVarName);
        return createAndInit(containerVar);
    }

    public static FGAWTAppContainer createAndInit(Var containerVar)
    {
        Map<Object, Object> container = (Map<Object, Object>) containerVar.get();

        FGAWTAppContainer appContainer = new FGAWTAppContainer(container);
        appContainer.initialize();

        return appContainer;
    }

    public final Component getComponent()
    {
        if (!EventQueue.isDispatchThread())
        {
            throw new IllegalStateException("this method should be called only on EDT");
        }
        if (hostComponent_ == null)
        {
            hostComponent_ = new HostComponent();
        }
        return hostComponent_;
    }

    public final void paintAllFromRoot(Consumer<List<Object>> primitivePainter) throws NoninvertibleTransformException
    {
        Container.IContainerAccessor containerAccessor = getContainer().getContainerAccessor();
        Container.IPropertyValueAccessor propertyValueAccessor = getContainer().getPropertyValueAccessor();
        getResultCollector().paintComponentWithChildren(
                primitivePainter,
                containerAccessor,
                propertyValueAccessor,
                Integer.valueOf(0));
    }

<commit_msg>Re-implement core to gain performance and simplify code #44 - awt container: draw external reason evolve results<commit_after>/*
 * Copyright <NAME>
 */
package flatgui.core.engine.ui;

import clojure.lang.Var;
import flatgui.core.FGHostStateEvent;
import flatgui.core.awt.AbstractHostComponent;
import flatgui.core.engine.*;
import flatgui.core.engine.Container;
import flatgui.core.websocket.FGWebInteropUtil;
import flatgui.run.FGRunUtil;

import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.NoninvertibleTransformException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.*;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

/**
 * @author <NAME>
 */
public class FGAWTAppContainer extends FGAppContainer<FGWebInteropUtil>
{
    private HostComponent hostComponent_;

    public FGAWTAppContainer(Map<Object, Object> container)
    {
        this(container, DFLT_UNIT_SIZE_PX);
    }

    public FGAWTAppContainer(Map<Object, Object> container, int unitSizePx)
    {
        super(container.get(ClojureContainerParser.getIdKey()).toString(), container, new FGWebInteropUtil(unitSizePx), new FGClojureResultCollector(unitSizePx), unitSizePx);
    }

    public static FGAWTAppContainer loadSourceCreateAndInit(InputStream source, String containerNs, String containerVarName)
    {
        String sourceCode = new Scanner(source).useDelimiter("\\Z").next();

        System.out.println(clojure.lang.RT.byteCast(1));
        clojure.lang.Compiler.load(new StringReader(sourceCode));

        return createAndInit(containerNs, containerVarName);
    }

    public static FGAWTAppContainer createAndInit(String containerNs, String containerVarName)
    {
        Var containerVar = FGRunUtil.getVar(containerNs, containerVarName);
        return createAndInit(containerVar);
    }

    public static FGAWTAppContainer createAndInit(Var containerVar)
    {
        Map<Object, Object> container = (Map<Object, Object>) containerVar.get();

        FGAWTAppContainer appContainer = new FGAWTAppContainer(container);
        appContainer.initialize();

        return appContainer;
    }

    public final Component getComponent()
    {
        if (!EventQueue.isDispatchThread())
        {
            throw new IllegalStateException("this method should be called only on EDT");
        }
        if (hostComponent_ == null)
        {
            hostComponent_ = new HostComponent();
        }
        return hostComponent_;
    }

    public final void paintAllFromRoot(Consumer<List<Object>> primitivePainter) throws NoninvertibleTransformException
    {
        Container.IContainerAccessor containerAccessor = getContainer().getContainerAccessor();
        Container.IPropertyValueAccessor propertyValueAccessor = getContainer().getPropertyValueAccessor();
        getResultCollector().paintComponentWithChildren(
                primitivePainter,
                containerAccessor,
                propertyValueAccessor,
                Integer.valueOf(0));
    }

    @Override
    public void evolve(List<Object> targetPath, Object evolveReason)
    {
        try
        {
            getEvolverExecutorService().submit(() -> getContainer().evolve(targetPath, evolveReason)).get();
            hostComponent_.repaint();
        }
        catch (InterruptedException | ExecutionException e)
        {
            e.printStackTrace();
        }
    }

{'fraction_non_alphanumeric': 0.09141445336627547, 'fraction_numerical': 0.0009264978381717109, 'mean_word_length': 3.558057705840957, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, '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': '1367366', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1734, 'n_words': 350}