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

lphystudio.core.narrative.DataModelToHTML Maven / Gradle / Ivy

The newest version!
package lphystudio.core.narrative;

import lphy.core.parser.LPhyParserAction;
import lphy.core.parser.LPhyParserDictionary;
import lphystudio.core.codecolorizer.ColorizerStyles;
import lphystudio.core.codecolorizer.DataModelCodeColorizer;
import lphystudio.core.codecolorizer.TextElement;
import lphystudio.core.theme.ThemeColours;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;

import javax.swing.*;
import javax.swing.text.Style;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class DataModelToHTML extends DataModelCodeColorizer {
    // CURRENT MODEL STATE

    static Color randomVarColor = ThemeColours.getRandomVarColor();
    static Color constantColor = ThemeColours.getConstantColor();
    static Color keywordColor = ThemeColours.getDefaultColor();
    static Color argumentNameColor = ThemeColours.getArgumentNameColor().darker();
    static Color functionColor = ThemeColours.getFunctionColor();
    static Color distributionColor = ThemeColours.getGenDistColor();

    List elements = new ArrayList<>();

    private final String fontSize;

    // allow to set font size to html \n");
            }
            elements.add(builder.toString());
        }
    }

    private String span(String text, Color color) {
        StringBuilder builder = new StringBuilder();
        builder.append("");
        builder.append(text);
        builder.append("");
        return builder.toString();
    }

    private String hexCode(Color color) {
        return String.format("#%06x", color.getRGB() & 0x00FFFFFF);
    }

    public String getHTML() {
        StringBuilder html = new StringBuilder();
        for (String element : elements) {
            html.append(element);
        }
        return html.toString();
    }

    public Object parse(String CASentence) {
//        System.out.println("Parsing " + CASentence + " to HTML");

        // Traverse parse tree
        AbstractParseTreeVisitor visitor = new DataModelASTVisitor();

        // containing either or both a data and model block;
        return LPhyParserAction.parse(CASentence, visitor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy