All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lphystudio.core.logger.TreeTextArea Maven / Gradle / Ivy

The newest version!
package lphystudio.core.logger;

import lphy.base.evolution.tree.TimeTree;
import lphy.core.logger.ValueFormatResolver;
import lphy.core.logger.ValueFormatter;
import lphy.core.model.Value;
import lphy.core.simulator.SimulatorListener;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Log tree to GUI,
 */
public class TreeTextArea extends JTextArea implements SimulatorListener {

    int numReplicates = 1000;

    public TreeTextArea() { }

    public void clear() {
        setText("");
    }

//    List> treeVariables;

    @Override
    public void start(Object... configs) {
        for (int i = 0; i < configs.length; i++) {
            if (configs[0] instanceof Integer numReplicates)
                this.numReplicates = numReplicates;
        }
    }

    @Override
    public void replicate(int index, List values) {
        List treeValuePerRep = getTreeValues(values);

        if (index == 0) {
            setText("sample");
            for (Value treV : treeValuePerRep) {
                List valueFormatterList = ValueFormatResolver
                        .createFormatter(TreeTextFormatter.class, treV);
                for (ValueFormatter valueFormatter : valueFormatterList) {
                    append("\t" + valueFormatter.header());
                }
            }
            append("\n");
        }

        append(index+"");
        for (Value treV : treeValuePerRep) {
            List valueFormatterList = ValueFormatResolver
                    .createFormatter(TreeTextFormatter.class, treV);
            for (ValueFormatter valueFormatter : valueFormatterList) {
                append("\t" + valueFormatter.format(treV.value()));
            }
        }
        append("\n");
    }

    @Override
    public void complete() {

    }

    // can be TimeTree or SimpleATimeTreelignment[]
    private List getTreeValues(List variables) {
        List values = new ArrayList<>();
        for (Value v : variables) {
            if (v.value() instanceof TimeTree || v.value() instanceof TimeTree[]) {
                values.add(v);
            }
        }
        values.sort(Comparator.comparing(Value::getId));
        return values;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy