Skip to main content

Hyper Beans 1: Hyper Style

Posted by evanx on December 19, 2006 at 6:21 AM EST

We wanna style our documents and reports using neutral Java objects, to generate output artifacts eg. HTML with CSS, and/or other formats, eg. PDF and Excel (for reports). We model our style objects after CSS, eg. font-family, font-weight, text-decoration, et al.


Code Snippet

We implement style objects for generating this series of articles, and also Gooey Beans, using quitehyper.

public class GooeyBeansStyleManager extends QStyleManager {
    QStyle javaStyle = createStyle("javaStyle");
    QStyle paragraphStyle = createStyle("paragraphStyle");
    QStyle sectionStyle = createStyle("sectionStyle");
    QStyle subsectionStyle = createStyle("subsectionStyle");
    ...
    List<QFontFamily> courier = Arrays.asList(newCourierFontFamily, 
            courierFontFamily, monospacedFontFamily);

    List<QFontFamily> verdana = Arrays.asList(verdanaFontFamily, 
            helveticaFontFamily, arialFontFamily, sansserifFontFamily);
    
    public GooeyArticleStyleManager() {
        javaStyle.setFontFamily(courier);
        javaStyle.setFontSize(11);
        javaStyle.setBorder(dashedLine, 1);
        javaStyle.setBorderColor(lightgrayColor);
        javaStyle.setPadding(4, leftLocation);
        javaStyle.setWidth(800);
        javaStyle.setBackgroundColor(0xf4f4f4);
        paragraphStyle.setFontFamily(verdana);
        paragraphStyle.setFontSize(10);
        sectionStyle.setFontFamily(verdana);
        sectionStyle.setFontWeight(boldFontWeight);
        sectionStyle.setFontStyle(italicFontStyle);
        ...
    }
    ...
}

where we statically import style enums and constants, eg. lightgrayColor, dashedLine, boldFontWeight, et al.


Related Topics >>