Search in sources :

Example 1 with Chapter

use of com.lowagie.text.Chapter in project vcell by virtualcell.

the class ITextWriter method writeBioModel.

public void writeBioModel(BioModel bioModel, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (bioModel == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing BioModel.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = bioModel.getName().trim();
        String userName = "Unknown";
        if (bioModel.getVersion() != null) {
            userName = bioModel.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("BioModel: " + name);
        document.open();
        // 
        Section introSection = null;
        int chapterNum = 1;
        if (preferences.includePhysio()) {
            Chapter physioChapter = new Chapter("Physiology For " + name, chapterNum++);
            introSection = physioChapter.addSection("General Info", physioChapter.numberDepth() + 1);
            String freeTextAnnotation = bioModel.getVCMetaData().getFreeTextAnnotation(bioModel);
            writeMetadata(introSection, name, freeTextAnnotation, userName, "BioModel");
            writeModel(physioChapter, bioModel.getModel());
            document.add(physioChapter);
        }
        if (preferences.includeApp()) {
            SimulationContext[] simContexts = bioModel.getSimulationContexts();
            if (simContexts.length > 0) {
                Chapter simContextsChapter = new Chapter("Applications For " + name, chapterNum++);
                if (introSection == null) {
                    introSection = simContextsChapter.addSection("General Info", simContextsChapter.numberDepth() + 1);
                    String freeTextAnnotation = bioModel.getVCMetaData().getFreeTextAnnotation(bioModel);
                    writeMetadata(introSection, name, freeTextAnnotation, userName, "BioModel");
                }
                for (int i = 0; i < simContexts.length; i++) {
                    writeSimulationContext(simContextsChapter, simContexts[i], preferences);
                }
                document.add(simContextsChapter);
            } else {
                System.err.println("Bad Request: No applications to publish for Biomodel: " + bioModel.getName());
            }
        }
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish BioModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) SimulationContext(cbit.vcell.mapping.SimulationContext) Section(com.lowagie.text.Section)

Example 2 with Chapter

use of com.lowagie.text.Chapter in project vcell by virtualcell.

the class ITextWriter method writeGeometry.

// for now, the preferences for a geometry is a dummy.
public void writeGeometry(Geometry geom, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (geom == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing Geometry.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = geom.getName().trim();
        String userName = "Unknown";
        if (geom.getVersion() != null) {
            userName = geom.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("Geometry: " + name);
        document.open();
        // 
        Section introSection = null;
        int chapterNum = 1;
        Chapter geomChapter = new Chapter("Geometry", chapterNum++);
        introSection = geomChapter.addSection("General Info", geomChapter.numberDepth() + 1);
        writeMetadata(introSection, name, geom.getDescription(), userName, "Geometry");
        // title?
        Section geomSection = geomChapter.addSection("Geometry", geomChapter.numberDepth() + 1);
        writeGeom(geomSection, geom, null);
        document.add(geomChapter);
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish BioModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) Section(com.lowagie.text.Section)

Example 3 with Chapter

use of com.lowagie.text.Chapter in project vcell by virtualcell.

the class ITextWriter method writeMathModel.

public void writeMathModel(MathModel mathModel, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (mathModel == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing MathModel.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = mathModel.getName().trim();
        String userName = "Unknown";
        if (mathModel.getVersion() != null) {
            userName = mathModel.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("MathModel: " + name);
        document.open();
        // 
        int chapterNum = 1;
        Section introSection = null;
        if (preferences.includeMathDesc()) {
            MathDescription mathDesc = mathModel.getMathDescription();
            Chapter mathDescChapter = new Chapter("Math Description", chapterNum++);
            introSection = mathDescChapter.addSection("General Info", mathDescChapter.numberDepth() + 1);
            writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
            writeMathDescAsText(mathDescChapter, mathDesc);
            document.add(mathDescChapter);
        }
        if (preferences.includeSim()) {
            // unlike biomodels, simulations are chapters, not chapter sections.
            Simulation[] sims = mathModel.getSimulations();
            if (sims != null) {
                Chapter simChapter = new Chapter("Simulations", chapterNum++);
                if (introSection == null) {
                    introSection = simChapter.addSection("General Info", simChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                for (int i = 0; i < sims.length; i++) {
                    writeSimulation(simChapter, sims[i]);
                }
                document.add(simChapter);
            } else {
                System.err.println("Bad Request: No simulations to publish for Mathmodel: " + name);
            }
        }
        if (preferences.includeGeom()) {
            // unlike biomodels, geometry is a chapter, not a chapter section.
            Geometry geom = mathModel.getMathDescription().getGeometry();
            if (geom != null) {
                Chapter geomChapter = new Chapter("Geometry", chapterNum++);
                if (introSection == null) {
                    introSection = geomChapter.addSection("General Info", geomChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                writeGeom(geomChapter, geom, null);
                document.add(geomChapter);
            } else {
                System.err.println("Bad Request: No geometry to publish for Mathmodel: " + name);
            }
        }
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish MathModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) Section(com.lowagie.text.Section)

Aggregations

Chapter (com.lowagie.text.Chapter)3 DocumentException (com.lowagie.text.DocumentException)3 Section (com.lowagie.text.Section)3 Geometry (cbit.vcell.geometry.Geometry)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathDescription (cbit.vcell.math.MathDescription)1 Simulation (cbit.vcell.solver.Simulation)1