Search in sources :

Example 1 with SVGGraphics2D

use of org.jfree.graphics2d.svg.SVGGraphics2D in project kernel by cristal-ise.

the class LifecycleRendererTest method generateInstance_SVG.

@Test
public void generateInstance_SVG() throws Exception {
    String wfXML = FileStringUtility.url2String(LifecycleRendererTest.class.getResource("/LifeCycle.workflow"));
    Workflow wf = (Workflow) Gateway.getMarshaller().unmarshall(wfXML);
    LifecycleRenderer generator = new LifecycleRenderer(wf.search("workflow/domain").getChildrenGraphModel(), false);
    int zoomFactor = generator.getZoomFactor(500, 500);
    SVGGraphics2D svgG2D = new SVGGraphics2D(500, 500);
    svgG2D.scale((double) zoomFactor / 100, (double) zoomFactor / 100);
    generator.draw(svgG2D);
    SVGUtils.writeToSVG(new File("target/workflow.svg"), svgG2D.getSVGElement());
}
Also used : LifecycleRenderer(org.cristalise.kernel.lifecycle.renderer.LifecycleRenderer) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) File(java.io.File) Test(org.junit.Test)

Example 2 with SVGGraphics2D

use of org.jfree.graphics2d.svg.SVGGraphics2D in project kernel by cristal-ise.

the class LifecycleRendererTest method generateDef_SVG.

@Test
public void generateDef_SVG() throws Exception {
    String caDefXML = FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/CA/ManageModule.xml"));
    CompositeActivityDef caDef = (CompositeActivityDef) Gateway.getMarshaller().unmarshall(caDefXML);
    LifecycleRenderer generator = new LifecycleRenderer(caDef.getChildrenGraphModel(), true);
    int zoomFactor = generator.getZoomFactor(500, 500);
    SVGGraphics2D svgG2D = new SVGGraphics2D(500, 500);
    svgG2D.scale((double) zoomFactor / 100, (double) zoomFactor / 100);
    generator.draw(svgG2D);
    SVGUtils.writeToSVG(new File("target/ManageModule.svg"), svgG2D.getSVGElement());
}
Also used : LifecycleRenderer(org.cristalise.kernel.lifecycle.renderer.LifecycleRenderer) SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) File(java.io.File) Test(org.junit.Test)

Example 3 with SVGGraphics2D

use of org.jfree.graphics2d.svg.SVGGraphics2D in project MassBank-web by MassBank.

the class Contents method init.

public void init() throws ServletException {
    try {
        result = new SearchExecution(null).exec(new RecordIndexCount());
        // construct and show pie charts
        int MAX_DISP_DATA = 10;
        PieDataset siteGraphData = createDataset(result.mapSiteToRecordCount, MAX_DISP_DATA);
        PieDataset instGraphData = createDataset(result.mapInstrumentToRecordCount, MAX_DISP_DATA);
        PieDataset msGraphData = createDataset(result.mapMsTypeToRecordCount, MAX_DISP_DATA);
        int siteTopNum = (siteGraphData.getItemCount() < MAX_DISP_DATA) ? siteGraphData.getItemCount() : MAX_DISP_DATA;
        int instTopNum = (instGraphData.getItemCount() < MAX_DISP_DATA) ? instGraphData.getItemCount() : MAX_DISP_DATA;
        int msTopNum = (msGraphData.getItemCount() < MAX_DISP_DATA) ? msGraphData.getItemCount() : MAX_DISP_DATA;
        JFreeChart sitechart = drawDataset(siteGraphData, "Contributor top " + siteTopNum);
        JFreeChart instchart = drawDataset(instGraphData, "Instrument Type top " + instTopNum);
        JFreeChart mschart = drawDataset(msGraphData, "MS Type top " + msTopNum);
        SVGGraphics2D g2 = new SVGGraphics2D(900, 350);
        Rectangle r = new Rectangle(0, 0, 900, 350);
        sitechart.draw(g2, r);
        sitechartSVG = g2.getSVGElement();
        instchart.draw(g2, r);
        instchartSVG = g2.getSVGElement();
        mschart.draw(g2, r);
        mschartSVG = g2.getSVGElement();
        // get the current database timestamp
        timestamp = new DatabaseTimestamp();
    } catch (SQLException | ConfigurationException e) {
        logger.error(e.getMessage());
    }
}
Also used : RecordIndexCount(massbank.web.recordindex.RecordIndexCount) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) SQLException(java.sql.SQLException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) SearchExecution(massbank.web.SearchExecution) Rectangle(java.awt.Rectangle) SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) DatabaseTimestamp(massbank.db.DatabaseTimestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with SVGGraphics2D

use of org.jfree.graphics2d.svg.SVGGraphics2D in project mylizzie by aerisnju.

the class Lizzie method storeBoardByFile.

private static void storeBoardByFile(Path filePath) {
    BufferedImage bufferedImage = Lizzie.frame.getCachedImage();
    SVGGraphics2D svgGraphics2D = new SVGGraphics2D(bufferedImage.getWidth(), bufferedImage.getHeight());
    try {
        svgGraphics2D.drawImage(bufferedImage, 0, 0, null);
        String fileContent = svgGraphics2D.getSVGDocument();
        try (FileWriter writer = new FileWriter(filePath.toFile())) {
            writer.write(fileContent);
        } catch (Exception e) {
            if (StringUtils.isEmpty(e.getMessage())) {
                JOptionPane.showMessageDialog(frame, "Error: cannot save svg: " + e.getMessage(), "Lizzie", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(frame, "Error: cannot save svg", "Lizzie", JOptionPane.ERROR_MESSAGE);
            }
        }
    } finally {
        svgGraphics2D.dispose();
    }
}
Also used : SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) BufferedImage(java.awt.image.BufferedImage)

Aggregations

SVGGraphics2D (org.jfree.graphics2d.svg.SVGGraphics2D)4 File (java.io.File)2 LifecycleRenderer (org.cristalise.kernel.lifecycle.renderer.LifecycleRenderer)2 Test (org.junit.Test)2 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 SQLException (java.sql.SQLException)1 DatabaseTimestamp (massbank.db.DatabaseTimestamp)1 SearchExecution (massbank.web.SearchExecution)1 RecordIndexCount (massbank.web.recordindex.RecordIndexCount)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)1 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)1 JFreeChart (org.jfree.chart.JFreeChart)1 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)1 PieDataset (org.jfree.data.general.PieDataset)1