Example usage for org.jfree.chart ChartUtilities saveChartAsPNG

List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities saveChartAsPNG.

Prototype

public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height) throws IOException 

Source Link

Document

Saves a chart to the specified file in PNG format.

Usage

From source file:com.zimbra.perf.chart.ChartUtil.java

private void writeChart(JFreeChart chart, ChartSettings cs) throws IOException {
    String filename = cs.getOutfile();
    System.out.println("Writing " + filename);
    File file = new File(mDestDir, filename);
    if (cs.getImageType() == ImageType.PNG) {
        ChartUtilities.saveChartAsPNG(file, chart, cs.getWidth(), cs.getHeight());
    } else {//from   www.  ja v  a2 s  . c  o m
        ChartUtilities.saveChartAsJPEG(file, 90, chart, cs.getWidth(), cs.getHeight());
    }
}

From source file:org.fhaes.jsea.JSEAStatsFunctions.java

public void savePDFReport(String filename) {

    Document document = new Document();
    try {/*from  w  w w  . ja v a  2 s.c om*/

        // if you want to save a pdf file using bigbuffer do it here
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        document.add(new Paragraph(para1.get(0)));
        printTableAct.get(0).setWidthPercentage(90);
        printTableAct.get(0).setSpacingBefore(20f);
        printTableAct.get(0).setSpacingAfter(20f);
        document.add(printTableAct.get(0));
        // document.newPage();
        document.add(new Paragraph(para2.get(0)));
        printTableSim.get(0).setWidthPercentage(90);
        printTableSim.get(0).setSpacingBefore(20f);
        printTableSim.get(0).setSpacingAfter(20f);
        document.add(printTableSim.get(0));

        // the charts are being saved from an array list to the files
        for (int i = 0; i < chartList.size(); i++) {
            try {

                File f2 = File.createTempFile("chart" + i, ".png");
                ChartUtilities.saveChartAsPNG(f2, chartList.get(i).getChart(), 800, 500);
                Image image = Image.getInstance(f2.getAbsolutePath());
                float fWidth = 0.6f * 800;
                float fHeight = 0.6f * 500;
                image.scaleAbsolute(fWidth, fHeight);
                document.add(image);
                f2.delete();

            } catch (IOException ex) {
                System.err.println(ex.getLocalizedMessage());
            }
        }
    } catch (Exception e) {

    }

    document.close();

}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 * //from  w  ww . j a  v a  2 s. com
 * @throws IOException
 *             if there is an I/O error.
 */
public void doSaveAs() throws IOException {

    JFileChooser fileChooser = new JFileChooser();
    ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"),
            ".png");
    fileChooser.addChoosableFileFilter(filter);

    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
    }
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 * //from w  ww  .  j a v a  2  s  . c o  m
 * @throws IOException
 *             if there is an I/O error.
 */

@Override
public void doSaveAs() throws IOException {

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
    ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"),
            ".png");
    fileChooser.addChoosableFileFilter(filter);

    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
    }

}

From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java

@Action
public void savePNGAction() {
    if (chart != null) {
        JFileChooser chooser = new JFileChooser();
        FileFilter filter = new FileFilter() {

            @Override/*  w w w .  j ava  2 s.co m*/
            public boolean accept(File f) {
                return f.isDirectory() || f.getName().toLowerCase().endsWith("png"); //NOI18N
            }

            @Override
            public String getDescription() {
                return java.util.ResourceBundle
                        .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                        .getString("PNG GRAPHICS FILES");
            }
        };
        chooser.setFileFilter(filter);
        int result = chooser.showDialog(this,
                java.util.ResourceBundle
                        .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                        .getString("CHOOSE FILENAME"));
        if (result == JFileChooser.APPROVE_OPTION) {
            try {
                File file = chooser.getSelectedFile();
                if (!file.getName().toLowerCase().endsWith("png")) { //NOI18N
                    file = new File(file.getAbsolutePath() + ".png"); //NOI18N
                }
                ChartUtilities.saveChartAsPNG(file, chart, pyramidPanelHolder.getWidth(),
                        pyramidPanelHolder.getHeight());
            } catch (IOException ex) {
                Logger.getLogger(PDSEditorInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:org.nuclos.client.ui.collect.Chart.java

private void actionCommandSave() {
    try {/*from ww w.ja  v  a  2s. c  o  m*/
        JFileChooser fileChooser = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter(
                SpringLocaleDelegate.getInstance().getMessage("filenameextensionfilter.1", "Bildformate")
                        + " (*.svg, *.png, *.jpg, *.jpeg)",
                "svg", "png", "jpg", "jpeg"); // @todo i18n
        fileChooser.addChoosableFileFilter(filter);

        int option = fileChooser.showSaveDialog(this);
        if (option == JFileChooser.APPROVE_OPTION) {
            String filename = fileChooser.getSelectedFile().getPath();
            if (fileChooser.getSelectedFile().getName().lastIndexOf(".") == -1) {
                filename = filename + ".png";
            }

            if (filename.toLowerCase().endsWith(".png"))
                ChartUtilities.saveChartAsPNG(new File(filename), getChartPanel().getChart(),
                        getChartPanel().getWidth(), getChartPanel().getHeight());
            else if (filename.toLowerCase().endsWith(".jpg") || filename.toLowerCase().endsWith(".jpeg"))
                ChartUtilities.saveChartAsJPEG(new File(filename), getChartPanel().getChart(),
                        getChartPanel().getWidth(), getChartPanel().getHeight());
            else if (filename.toLowerCase().endsWith(".svg")) {
                // Get a DOMImplementation and create an XML document
                DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
                Document document = domImpl.createDocument(null, "svg", null);

                // Create an instance of the SVG Generator
                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

                // draw the chart in the SVG generator
                JFreeChart chart = getChartPanel().getChart();
                chart.draw(svgGenerator, getChartPanel().getBounds());

                // Write svg file
                OutputStream outputStream = new FileOutputStream(filename);
                Writer out = new OutputStreamWriter(outputStream, "UTF-8");
                svgGenerator.stream(out, true /* use css */);
                outputStream.flush();
                outputStream.close();
            }
        }
    } catch (Exception e) {
        throw new NuclosFatalException(e.getMessage());
    }
}

From source file:atlas.kingj.roi.FrmMain.java

private boolean WriteSpreadsheet(File file) throws Exception {
    //boolean success = true;
    // TODO: check first if image files present, and what data available. Display message on sheet if no data, or error message in form.
    //try {/*w w  w.ja v  a 2  s  .  com*/
    // New workbook
    WritableWorkbook workbook = null;

    boolean errors = false;

    workbook = Workbook.createWorkbook(file);

    // New sheets
    WritableSheet sheetMach = workbook.createSheet("Machines", 0);
    WritableSheet sheetJobs = workbook.createSheet("Jobs", 1);
    WritableSheet sheetRes = workbook.createSheet("Productivity Results", 2);
    WritableSheet sheetRoi = workbook.createSheet("ROI Results", 3);

    // All static images
    File imgLogo = new File("sheet_imgs/logo.png");
    File imgER610 = new File("sheet_imgs/er610.png");
    File imgSR9DS = new File("sheet_imgs/sr9ds.png");
    File imgSR9DT = new File("sheet_imgs/sr9dt.png");
    File imgSR800 = new File("sheet_imgs/sr800.png");
    File imgCustom = new File("sheet_imgs/custom.png");

    // TODO
    // All temp image holders
    File fs = null;
    File fresa = new File(Consts.SETTINGS_DIR + "/tempresa.png");
    File fresb = new File(Consts.SETTINGS_DIR + "/tempresb.png");
    File fresc = new File(Consts.SETTINGS_DIR + "/tempresc.png");
    File fresd = new File(Consts.SETTINGS_DIR + "/tempresd.png");
    File froia = new File(Consts.SETTINGS_DIR + "/temproia.png");
    File froib = new File(Consts.SETTINGS_DIR + "/temproib.png");
    File froic = new File(Consts.SETTINGS_DIR + "/temproic.png");
    File froid = new File(Consts.SETTINGS_DIR + "/temproid.png");
    String tmpSched = Consts.SETTINGS_DIR + "/imgSched.png";
    File[] brkdns = new File[(results != null ? results.getSize() : 0)];
    for (int i = 0; i < brkdns.length; ++i)
        brkdns[i] = new File(Consts.SETTINGS_DIR + "/tmpBrkdn" + i + ".png");

    // All fonts
    WritableFont fontStandard = new WritableFont(WritableFont.ARIAL, 10);
    WritableCellFormat fontStandardFormat = new WritableCellFormat(fontStandard);
    WritableFont fontError = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.RED);
    WritableCellFormat fontErrorFormat = new WritableCellFormat(fontError);
    WritableFont fontTitle = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD);
    WritableCellFormat fontTitleFormat = new WritableCellFormat(fontTitle);
    WritableFont fontPageTitle = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.GREEN);
    WritableCellFormat fontPageTitleFormat = new WritableCellFormat(fontPageTitle);
    WritableFont fontCategory = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
    WritableCellFormat fontCategoryFormat = new WritableCellFormat(fontCategory);
    WritableFont fontData = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.DARK_BLUE);
    WritableCellFormat fontDataFormat = new WritableCellFormat(fontData);
    fontDataFormat.setAlignment(Alignment.LEFT);
    WritableFont fontDataBold = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.DARK_BLUE);
    WritableCellFormat fontDataBoldFormat = new WritableCellFormat(fontDataBold);
    WritableFont fontNumber = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.DARK_BLUE);
    WritableCellFormat fontNumberFormat = new WritableCellFormat(fontNumber);
    fontNumberFormat.setAlignment(Alignment.LEFT);
    //TODO: dark blue 2?
    WritableFont fontDataCategory = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.GRAY_50);
    WritableCellFormat fontDataCategoryFormat = new WritableCellFormat(fontDataCategory);
    fontDataCategoryFormat.setAlignment(Alignment.RIGHT);
    WritableFont fontFootnote = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.GRAY_50);
    WritableCellFormat fontFootnoteFormat = new WritableCellFormat(fontFootnote);
    WritableFont fontJobHead = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, Colour.DARK_BLUE);
    WritableCellFormat fontJobHeadFormat = new WritableCellFormat(fontJobHead);

    // Precompute dimensions
    Machine[] machines = new Machine[listModel.getSize()];
    for (int i = 0; i < listModel.getSize(); ++i)
        machines[i] = (Machine) listModel.get(i);
    Job[] jobs = new Job[jobModel.getSize()];
    for (int i = 0; i < jobModel.getSize(); ++i)
        jobs[i] = (Job) jobModel.get(i);

    int PAGE1_WIDTH = 3 + 3 * machines.length;
    int PAGE1_HEIGHT = 38;
    int PAGE2_WIDTH1 = 3 + 3 * jobs.length;
    int PAGE2_HEIGHT1 = 24;
    int PAGE2_WIDTH2 = 6;
    int PAGE2_HEIGHT2 = 10;
    int PAGE2_WIDTH3 = 12;
    int PAGE2_HEIGHT3 = 22 + Math.max(0, environment.getSchedule().getSize() - 17);
    if (environment.getSchedule() == null || environment.getSchedule().getSize() < 1) {
        PAGE2_WIDTH3 = 4;
        PAGE2_HEIGHT3 = 5;
    }
    int PAGE3_WIDTH = Math.max(19, 3 + 4 * ((results == null ? 0 : results.getSize())));
    int PAGE3_HEIGHT = 45;
    int PAGE4_WIDTH = Math.max(19, 3 + 3 * ((RoiResults == null ? 0 : RoiResults.getSize())));
    int PAGE4_HEIGHT = 68;

    // Add headers
    if (imgLogo.exists()) {
        sheetMach.addImage(new WritableImage(0, 0, 3, 5, imgLogo));
        sheetJobs.addImage(new WritableImage(0, 0, 3, 5, imgLogo));
        sheetRes.addImage(new WritableImage(0, 0, 3, 5, imgLogo));
        sheetRoi.addImage(new WritableImage(0, 0, 3, 5, imgLogo));
    }

    // NUMBERING IS FROM 0!!
    sheetMach.addCell(new Label(4, 1, "Titan Production Calculator", fontTitleFormat));
    sheetJobs.addCell(new Label(4, 1, "Titan Production Calculator", fontTitleFormat));
    sheetRes.addCell(new Label(4, 1, "Titan Production Calculator", fontTitleFormat));
    sheetRoi.addCell(new Label(4, 1, "Titan Production Calculator", fontTitleFormat));

    sheetMach.addCell(new Label(4, 3, "Spreadsheet generated on " + now(), fontStandardFormat));
    sheetJobs.addCell(new Label(4, 3, "Spreadsheet generated on " + now(), fontStandardFormat));
    sheetRes.addCell(new Label(4, 3, "Spreadsheet generated on " + now(), fontStandardFormat));
    sheetRoi.addCell(new Label(4, 3, "Spreadsheet generated on " + now(), fontStandardFormat));

    // Set borders
    SheetRangeImpl r1 = new SheetRangeImpl(sheetMach, 0, 6, PAGE1_WIDTH - 1, PAGE1_HEIGHT + 6 - 1);
    SheetRangeImpl r2a = new SheetRangeImpl(sheetJobs, 0, 6, PAGE2_WIDTH1 - 1, PAGE2_HEIGHT1 + 6 - 1);
    SheetRangeImpl r2b = new SheetRangeImpl(sheetJobs, 0, 32 + PAGE2_HEIGHT3, PAGE2_WIDTH2 - 1,
            PAGE2_HEIGHT2 + PAGE2_HEIGHT3 + 31 - 1);
    SheetRangeImpl r2c = new SheetRangeImpl(sheetJobs, 0, 31, PAGE2_WIDTH3 - 1, PAGE2_HEIGHT3 + 31 - 1);
    SheetRangeImpl r3 = new SheetRangeImpl(sheetRes, 0, 6, PAGE3_WIDTH - 1, PAGE3_HEIGHT + 6 - 1);
    SheetRangeImpl r4 = new SheetRangeImpl(sheetRes, 0, 6, PAGE4_WIDTH - 1, PAGE4_HEIGHT + 6 - 1);
    // TODO: this probably means border cells can't have text in...

    // No data warnings, else build sheet
    if (machines.length < 1) {
        sheetMach.addCell(new Label(1, 7, "No machines were configured", fontErrorFormat));
    } else {

        sheetMach.addCell(new Label(1, 7, "Machines", fontPageTitleFormat));
        sheetMach.addCell(new Label(1, 9, "Model", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 13, "Description", fontCategoryFormat));

        sheetMach.addCell(new Label(1, 15, "Speed", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 16, "Knife Control", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 17, "Core Positioning", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 18, "Unloader", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 19, "Unwind Drive", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 20, "Rewind Ctrl Loop", fontCategoryFormat));

        sheetMach.addCell(new Label(1, 22, "Splice Table", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 23, "Alignment Guide", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 24, "Roll Conditioning", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 25, "Turret Support", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 26, "Autostripping", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 27, "Flag Detection", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 28, "Auto Cut-off", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 29, "Auto Tape Core", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 30, "Auto Tape Tail", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 31, "850mm Rewind", fontCategoryFormat));

        sheetMach.addCell(new Label(1, 33, "Duplex Rewind", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 34, "Turret Rewind", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 35, "Braked Unwind", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 36, "Splice Table", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 37, "Auto Cross Cut", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 38, "Auto Tape", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 39, "Core Positioning", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 40, "Reel Stripping", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 41, "Unload Boom", fontCategoryFormat));
        sheetMach.addCell(new Label(1, 42, "Rewind Type", fontCategoryFormat));

        sheetMach.addCell(new Label(0, 15, "Variants:", fontDataCategoryFormat));
        sheetMach.addCell(new Label(0, 22, "Titan:", fontDataCategoryFormat));
        sheetMach.addCell(new Label(0, 33, "Custom:", fontDataCategoryFormat));

        for (int i = 0; i < machines.length; ++i) {
            Machine m = machines[i];

            int x = 3 + 3 * i;

            // add model logo
            switch (m.model) {
            case ER610:
                sheetMach.addImage(new WritableImage(x, 9, 2, 3, imgER610));
                break;
            case SR9DS:
                sheetMach.addImage(new WritableImage(x, 9, 2, 3, imgSR9DS));
                break;
            case SR9DT:
                sheetMach.addImage(new WritableImage(x, 9, 2, 3, imgSR9DT));
                break;
            case SR800:
                sheetMach.addImage(new WritableImage(x, 9, 2, 3, imgSR800));
                break;
            case CUSTOM:
                sheetMach.addImage(new WritableImage(x, 9, 2, 3, imgCustom));
                break;
            }

            // description
            sheetMach.addCell(new Label(x, 13, m.name, fontDataFormat));

            if (!m.isCustom()) {

                // variants
                sheetMach.addCell(new Number(x, 15, (int) m.speed.orig_speed, fontNumberFormat));
                sheetMach.addCell(new Label(x, 16, m.knives.toString().toUpperCase(), fontDataFormat));
                sheetMach.addCell(new Label(x, 17, m.corepos.toString(), fontDataFormat));
                sheetMach.addCell(new Label(x, 18, m.unloader.toString(), fontDataFormat));
                sheetMach.addCell(new Label(x, 19, m.unwind.toString(), fontDataFormat));
                sheetMach.addCell(new Label(x, 20, m.rewind.toString(), fontDataFormat));

                // options
                if (m.splice_table)
                    sheetMach.addCell(new Label(x, 22, "X", fontDataBoldFormat));
                if (m.alignment)
                    sheetMach.addCell(new Label(x, 23, "X", fontDataBoldFormat));
                if (m.roll_cond)
                    sheetMach.addCell(new Label(x, 24, "X", fontDataBoldFormat));
                if (m.turret)
                    sheetMach.addCell(new Label(x, 25, "X", fontDataBoldFormat));
                if (m.autostrip)
                    sheetMach.addCell(new Label(x, 26, "X", fontDataBoldFormat));
                if (m.flags)
                    sheetMach.addCell(new Label(x, 27, "X", fontDataBoldFormat));
                if (m.cutoff)
                    sheetMach.addCell(new Label(x, 28, "X", fontDataBoldFormat));
                if (m.tapecore)
                    sheetMach.addCell(new Label(x, 29, "X", fontDataBoldFormat));
                if (m.tapetail)
                    sheetMach.addCell(new Label(x, 30, "X", fontDataBoldFormat));
                if (m.extrarewind)
                    sheetMach.addCell(new Label(x, 31, "X", fontDataBoldFormat));

            } else {
                // Custom machine
                //  duplexrewind turret  brakedunwind  splicetab autocut  autotape  corepos  autostrip unloadboom
                sheetMach.addCell(new Number(x, 15, (int) (60 * m.getSpeed(0.)), fontNumberFormat));
                sheetMach.addCell(new Label(x, 16, "n/a", fontDataFormat));
                sheetMach.addCell(new Label(x, 17, "See below", fontDataFormat));
                sheetMach.addCell(new Label(x, 18, "n/a", fontDataFormat));
                sheetMach.addCell(new Label(x, 19, "n/a", fontDataFormat));
                sheetMach.addCell(new Label(x, 20, "n/a", fontDataFormat));

                if (m.getCustomMachine().options[0])
                    sheetMach.addCell(new Label(x, 33, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[1])
                    sheetMach.addCell(new Label(x, 34, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[2])
                    sheetMach.addCell(new Label(x, 35, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[3])
                    sheetMach.addCell(new Label(x, 36, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[4])
                    sheetMach.addCell(new Label(x, 37, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[5])
                    sheetMach.addCell(new Label(x, 38, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[6])
                    sheetMach.addCell(new Label(x, 39, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[7])
                    sheetMach.addCell(new Label(x, 40, "X", fontDataBoldFormat));
                if (m.getCustomMachine().options[8])
                    sheetMach.addCell(new Label(x, 41, "X", fontDataBoldFormat));

                sheetMach
                        .addCell(new Label(x, 42, m.getCustomMachine().rewind_type.toString(), fontDataFormat));

            }

            sheetMach.addCell(new Label(0, PAGE1_HEIGHT + 6 + 1, "X = option present", fontFootnoteFormat));
            sheetMach.addCell(new Label(PAGE1_WIDTH - 4, PAGE1_HEIGHT + 6 + 1,
                    "Calculations are approximations only", fontFootnoteFormat));

        }

        DrawBorder(sheetMach, r1, BorderLineStyle.THICK);

    }
    if (jobs.length < 1) {
        sheetJobs.addCell(new Label(1, 7, "No jobs were configured", fontErrorFormat));
    } else {
        //DrawBorder(sheetJobs, r2a, BorderLineStyle.THIN);
        //DrawBorder(sheetJobs, r2, BorderLineStyle.THICK);
        //PopulateSheet(2);

        sheetJobs.addCell(new Label(1, 7, "Jobs", fontPageTitleFormat));

        sheetJobs.addCell(new Label(1, 9, "Description", fontCategoryFormat));

        sheetJobs.addCell(new Label(1, 11, "Name", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 12, "Thickness", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 13, "Density", fontCategoryFormat));

        sheetJobs.addCell(new Label(1, 15, "Web Width", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 16, "Unwind Core", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 17, "Avg. Flags", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 18, "Unwind Size", fontCategoryFormat));

        sheetJobs.addCell(new Label(1, 20, "Reel Count", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 21, "Slit Width", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 22, "Knife Type", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 23, "Trim", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 24, "Rewind Core", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 25, "Speed Limit", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 26, "Rewind Output", fontCategoryFormat));

        sheetJobs.addCell(new Label(1, 28, "Job Size", fontCategoryFormat));

        sheetJobs.addCell(new Label(0, 11, "Material:", fontDataCategoryFormat));
        sheetJobs.addCell(new Label(0, 15, "Unwind:", fontDataCategoryFormat));
        sheetJobs.addCell(new Label(0, 20, "Rewind:", fontDataCategoryFormat));
        sheetJobs.addCell(new Label(0, 28, "Totals:", fontDataCategoryFormat));

        for (int i = 0; i < jobs.length; ++i) {
            Job j = jobs[i];
            int x = 3 * i + 3;
            sheetJobs.addCell(new Label(x, 9, j.getName(), fontJobHeadFormat));

            sheetJobs.addCell(new Label(x, 11, j.getMaterial().name, fontDataFormat));
            sheetJobs.addCell(new Number(x, 12,
                    (metric ? j.getMaterial().thickness : Core.MicroToMil(j.getMaterial().thickness)),
                    fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 12, "microns", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 12, "mils", fontDataFormat));
            sheetJobs.addCell(new Number(x, 13, j.getMaterial().density, fontDataFormat));
            sheetJobs.addCell(new Label(x + 1, 13, "cc", fontDataFormat));

            sheetJobs.addCell(new Number(x, 15, (metric ? j.getWebWidth() : Core.MMToIn(j.getWebWidth())),
                    fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 15, "mm", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 15, "in", fontDataFormat));
            sheetJobs
                    .addCell(new Number(x, 16,
                            (metric ? j.getUnwindCore() - Consts.UNWIND_CORE_THICKNESS
                                    : Core.MMToIn(j.getUnwindCore() - Consts.UNWIND_CORE_THICKNESS)),
                            fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 16, "mm", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 16, "in", fontDataFormat));
            sheetJobs.addCell(new Number(x, 17, j.getFlagRate(), fontDataFormat));

            if (j.getUnwindType() == 0)
                sheetJobs.addCell(new Number(x, 18,
                        (metric ? j.getUnwindLengthSI() : Core.MToFt(j.getUnwindLengthSI())), fontDataFormat));
            else if (j.getUnwindType() == 1)
                sheetJobs.addCell(new Number(x, 18,
                        (metric ? j.getUnwindWeightSI() : Core.KgToTon(j.getUnwindWeightSI())),
                        fontDataFormat));
            else if (j.getUnwindType() == 2)
                sheetJobs.addCell(new Number(x, 18,
                        (metric ? j.getUnwindDiam() : Core.MMToIn(j.getUnwindDiam())), fontDataFormat));
            if (metric) {
                if (j.getUnwindType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 18, "m", fontDataFormat));
                else if (j.getUnwindType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 18, "kg", fontDataFormat));
                else if (j.getUnwindType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 18, "mm diam", fontDataFormat));
            } else {
                if (j.getUnwindType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 18, "ft", fontDataFormat));
                else if (j.getUnwindType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 18, "tons", fontDataFormat));
                else if (j.getUnwindType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 18, "in diam", fontDataFormat));
            }
            sheetJobs.addCell(new Number(x, 20, j.getSlits(), fontDataFormat));
            sheetJobs.addCell(new Number(x, 21, (metric ? j.getSlitWidth() : Core.MMToIn(j.getSlitWidth())),
                    fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 21, "mm", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 21, "in", fontDataFormat));
            sheetJobs.addCell(new Label(x, 22, j.getKnifeType().toString(), fontDataFormat));
            sheetJobs.addCell(new Number(x, 23,
                    (metric ? Math.max(0, j.getWebWidth() - j.getSlits() * j.getSlitWidth())
                            : Core.MMToIn(Math.max(0, j.getWebWidth() - j.getSlits() * j.getSlitWidth()))),
                    fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 23, "mm", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 23, "in", fontDataFormat));
            sheetJobs
                    .addCell(new Number(x, 24,
                            (metric ? j.getRewindCore() - Consts.REWIND_CORE_THICKNESS
                                    : Core.MMToIn(j.getRewindCore() - Consts.REWIND_CORE_THICKNESS)),
                            fontDataFormat));
            if (metric)
                sheetJobs.addCell(new Label(x + 1, 24, "mm", fontDataFormat));
            else
                sheetJobs.addCell(new Label(x + 1, 24, "in", fontDataFormat));

            if (j.isSpeedLimited()) {
                sheetJobs.addCell(new Number(x, 25,
                        (metric ? j.getSpeedLimitSI() * 60 : Core.MToFt(j.getSpeedLimitSI() * 60)),
                        fontDataFormat));
                sheetJobs.addCell(new Label(x + 1, 25, "m/min", fontDataFormat));
            } else
                sheetJobs.addCell(new Label(x, 25, "NO", fontDataFormat));

            if (j.getRewindType() == 0)
                sheetJobs.addCell(new Number(x, 26,
                        (metric ? j.getRewindLengthSI() : Core.MToFt(j.getRewindLengthSI())), fontDataFormat));
            else if (j.getRewindType() == 1)
                sheetJobs.addCell(new Number(x, 26,
                        (metric ? j.getRewindWeightSI() : Core.KgToLbs(j.getRewindWeightSI())),
                        fontDataFormat));
            else if (j.getRewindType() == 2)
                sheetJobs.addCell(new Number(x, 26,
                        (metric ? j.getRewindDiam() : Core.MMToIn(j.getRewindDiam())), fontDataFormat));

            if (metric) {
                if (j.getRewindType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 26, "m", fontDataFormat));
                else if (j.getRewindType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 26, "kg/set", fontDataFormat));
                else if (j.getRewindType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 26, "mm diam", fontDataFormat));
            } else {
                if (j.getRewindType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 26, "ft", fontDataFormat));
                else if (j.getRewindType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 26, "lbs/set", fontDataFormat));
                else if (j.getRewindType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 26, "in diam", fontDataFormat));
            }

            if (j.getTotalType() == 0)
                sheetJobs.addCell(new Number(x, 28,
                        (metric ? j.getTotLength() : Core.MToFt(j.getTotLengthSI())), fontDataFormat));
            else if (j.getTotalType() == 1)
                sheetJobs.addCell(new Number(x, 28,
                        (metric ? j.getTotWeightSI() : Core.KgToTon(j.getTotWeightSI())), fontDataFormat));
            else if (j.getTotalType() == 2)
                sheetJobs.addCell(new Number(x, 28,
                        (metric ? j.getTotWeightSI() / 1000 : Core.TonneToTon(j.getTotWeightSI() / 1000)),
                        fontDataFormat));
            if (metric) {
                if (j.getTotalType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 28, "km", fontDataFormat));
                else if (j.getTotalType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 28, "kg", fontDataFormat));
                else if (j.getTotalType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 28, "tonnes", fontDataFormat));
            } else {
                if (j.getTotalType() == 0)
                    sheetJobs.addCell(new Label(x + 1, 28, "ft", fontDataFormat));
                else if (j.getTotalType() == 1)
                    sheetJobs.addCell(new Label(x + 1, 28, "tons", fontDataFormat));
                else if (j.getTotalType() == 2)
                    sheetJobs.addCell(new Label(x + 1, 28, "tons", fontDataFormat));
            }
        }

        // environment data
        sheetJobs.addCell(new Label(1, 33 + PAGE2_HEIGHT3, "Environment", fontPageTitleFormat));

        sheetJobs.addCell(new Label(1, 35 + PAGE2_HEIGHT3, "Shift Length", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 36 + PAGE2_HEIGHT3, "Shifts per Day", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 37 + PAGE2_HEIGHT3, "Day Length", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 39 + PAGE2_HEIGHT3, "Days per Year", fontCategoryFormat));
        sheetJobs.addCell(new Label(1, 40 + PAGE2_HEIGHT3, "Year Length", fontCategoryFormat));
        sheetJobs.addCell(new Label(4, 35 + PAGE2_HEIGHT3, "hrs", fontDataFormat));
        sheetJobs.addCell(new Label(4, 37 + PAGE2_HEIGHT3, "hrs", fontDataFormat));
        sheetJobs.addCell(new Label(4, 40 + PAGE2_HEIGHT3, "hrs", fontDataFormat));

        sheetJobs.addCell(
                new Number(3, 35 + PAGE2_HEIGHT3, Math.max(0, environment.HrsPerShift), fontDataFormat));
        sheetJobs.addCell(new Number(3, 36 + PAGE2_HEIGHT3,
                Math.max(0, roundTwoDecimals(environment.HrsPerDay / environment.HrsPerShift)),
                fontDataFormat));
        sheetJobs
                .addCell(new Number(3, 37 + PAGE2_HEIGHT3, Math.max(0, environment.HrsPerDay), fontDataFormat));
        sheetJobs.addCell(new Number(3, 39 + PAGE2_HEIGHT3,
                Math.max(0, roundTwoDecimals(environment.HrsPerYear / environment.HrsPerDay)), fontDataFormat));
        sheetJobs.addCell(
                new Number(3, 40 + PAGE2_HEIGHT3, Math.max(0, environment.HrsPerYear), fontDataFormat));

        // schedule data
        if (environment.getSchedule() == null || environment.getSchedule().getSize() < 1) {
            sheetJobs.addCell(new Label(1, 32, "Schedule", fontPageTitleFormat));
            sheetJobs.addCell(new Label(1, 34, "No schedule found", fontErrorFormat));
        } else {
            sheetJobs.addCell(new Label(1, 32, "Schedule", fontPageTitleFormat));
            sheetJobs.addCell(new Label(10, 34, "Order: ", fontFootnoteFormat));
            for (int i = 0; i < environment.getSchedule().getSize(); ++i) {
                sheetJobs.addCell(
                        new Label(10, 35 + i, environment.getSchedule().getJob(i).getName(), fontDataFormat));
            }

            ScheduleChart ch = new ScheduleChart(environment.getSchedule());
            JFreeChart sched = ch.getChart();

            fs = new File(tmpSched);
            if (sched != null) {
                try {
                    ChartUtilities.saveChartAsPNG(fs, sched, 600, 360);
                    sheetJobs.addImage(new WritableImage(1, 34, 8, 18, new File(tmpSched)));
                } catch (Exception e1) {
                    sheetJobs.addCell(new Label(1, 34, "No schedule chart found"));
                }

            }
        }

        sheetJobs.addCell(new Label(0, PAGE2_HEIGHT1 + PAGE2_HEIGHT2 + PAGE2_HEIGHT3 + 8,
                "Calculations are approximations only", fontFootnoteFormat));

        DrawBorder(sheetJobs, r2a, BorderLineStyle.THICK);
        DrawBorder(sheetJobs, r2b, BorderLineStyle.THICK);
        DrawBorder(sheetJobs, r2c, BorderLineStyle.THICK);
    }
    if (results == null || results.getSize() < 1) {
        sheetRes.addCell(new Label(1, 7, "No results were available", fontErrorFormat));
    } else {
        DrawBorder(sheetRes, r3, BorderLineStyle.THICK);

        sheetRes.addCell(new Label(1, 7, "Productivity Results", fontPageTitleFormat));

        sheetRes.addCell(new Label(1, 9, "Machine", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 14, "Average rate", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 15, "Schedule run time", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 16, "Time running %", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 17, "Length / year", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 18, "Weight / year", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 20, "Productivity", fontCategoryFormat));
        sheetRes.addCell(new Label(1, 21, "breakdown", fontCategoryFormat));

        for (int i = 0; i < results.getSize(); ++i) {
            Result r = results.get(i);

            int x = 3 + 4 * i;

            // add model logo
            switch (r.getModelType()) {
            case ER610:
                sheetRes.addImage(new WritableImage(x, 9, 2, 3, imgER610));
                break;
            case SR9DS:
                sheetRes.addImage(new WritableImage(x, 9, 2, 3, imgSR9DS));
                break;
            case SR9DT:
                sheetRes.addImage(new WritableImage(x, 9, 2, 3, imgSR9DT));
                break;
            case SR800:
                sheetRes.addImage(new WritableImage(x, 9, 2, 3, imgSR800));
                break;
            case CUSTOM:
                sheetRes.addImage(new WritableImage(x, 9, 2, 3, imgCustom));
                break;
            }

            // description
            sheetRes.addCell(new Label(x, 12, r.getName(), fontDataFormat));

            if (metric) {
                sheetRes.addCell(new Number(x, 14, (int) r.MtPerHour, fontNumberFormat));
                sheetRes.addCell(new Label(x + 1, 14, "m/hr", fontDataFormat));
            } else {
                sheetRes.addCell(new Number(x, 14, (int) Core.MToFt(r.MtPerHour), fontNumberFormat));
                sheetRes.addCell(new Label(x + 1, 14, "ft/hr", fontDataFormat));
            }
            sheetRes.addCell(new Number(x, 15, roundTwoDecimals(r.ScheduleTime), fontNumberFormat));
            sheetRes.addCell(new Label(x + 1, 15, "hours", fontDataFormat));
            sheetRes.addCell(
                    new Number(x, 16, (int) r.getResult(ResultType.EFF, ResultTime.HOUR), fontNumberFormat));
            sheetRes.addCell(new Label(x + 1, 16, "%", fontDataFormat));
            if (metric) {
                sheetRes.addCell(new Number(x, 17, (int) r.getResult(ResultType.LENGTH, ResultTime.YEAR) / 1000,
                        fontNumberFormat));
                sheetRes.addCell(new Number(x, 18, (int) r.getResult(ResultType.WEIGHT, ResultTime.YEAR) / 1000,
                        fontNumberFormat));
                sheetRes.addCell(new Label(x + 1, 17, "km", fontDataFormat));
                sheetRes.addCell(new Label(x + 1, 18, "tonnes", fontDataFormat));
            } else {
                sheetRes.addCell(new Number(x, 17,
                        (int) Core.KmToMi(r.getResult(ResultType.LENGTH, ResultTime.YEAR) / 1000),
                        fontNumberFormat));
                sheetRes.addCell(new Number(x, 18,
                        (int) Core.TonneToTon(r.getResult(ResultType.WEIGHT, ResultTime.YEAR) / 1000),
                        fontNumberFormat));
                sheetRes.addCell(new Label(x + 1, 17, "mi", fontDataFormat));
                sheetRes.addCell(new Label(x + 1, 18, "tons", fontDataFormat));
            }

            JFreeChart tmp = null;
            try {
                if (results.getBreakdownCharts()[i] != null)
                    tmp = (JFreeChart) results.getBreakdownCharts()[i].clone();
            } catch (CloneNotSupportedException e) {
                errors = true;
            }
            try {
                ChartUtilities.saveChartAsPNG(brkdns[i], tmp, 300, 180);
                sheetRes.addImage(new WritableImage(x, 20, 3, 7, brkdns[i]));
            } catch (Exception e) {
                sheetRes.addCell(new Label(x, 20, "No breakdown chart found"));
            }

        }

        //results
        JFreeChart a = null, b = null;
        try {
            if (results.getRateGraph() != null)
                a = (JFreeChart) results.getRateGraph().clone();
            if (results.getProdWGraph() != null)
                b = (JFreeChart) results.getProdWGraph().clone();
            /*if(results.getRateGraph()!=null)
               c = (JFreeChart) results.getRateGraph().clone();
            if(results.getRateGraph()!=null)
               d = (JFreeChart) results.getRateGraph().clone();*/
        } catch (CloneNotSupportedException e1) {
            errors = true;
        }

        sheetRes.addCell(new Label(1, 30, "Graphical Results:", fontJobHeadFormat));

        try {
            ChartUtilities.saveChartAsPNG(fresa, a, 600, 360);
            sheetRes.addImage(new WritableImage(1, 32, 8, 18, fresa));
        } catch (Exception e1) {
            sheetRes.addCell(new Label(1, 32, "No rate chart found"));
        }
        try {
            ChartUtilities.saveChartAsPNG(fresb, b, 600, 360);
            sheetRes.addImage(new WritableImage(10, 32, 8, 18, fresb));
        } catch (Exception e1) {
            sheetRes.addCell(new Label(10, 32, "No production chart found"));
        }

        sheetRes.addCell(new Label(PAGE3_WIDTH - 4, PAGE3_HEIGHT + 6 + 1,
                "Calculations are approximations only", fontFootnoteFormat));

    }

    if (RoiResults == null || RoiResults.getSize() < 1) {
        sheetRoi.addCell(new Label(1, 7, "No results were available", fontErrorFormat));
    } else {
        DrawBorder(sheetRoi, r4, BorderLineStyle.THICK);

        sheetRoi.addCell(new Label(1, 7, "Return on Investment Analysis", fontPageTitleFormat));

        sheetRoi.addCell(new Label(1, 9, "Input Data", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 14, "Machine", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 19, "Average Power", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 20, "Energy / Year", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 21, "Annual Downtime", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 22, "Labour Cost", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 23, "Parts Costs", fontCategoryFormat));

        sheetRoi.addCell(new Label(1, 25, "Value Added", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 26, "Energy Cost", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 27, "Production Loss", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 28, "Parts+Labour Costs", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 29, "Total Maintenance", fontCategoryFormat));
        sheetRoi.addCell(new Label(1, 30, "Waste Reduced", fontCategoryFormat));
        sheetRoi.addCell(new Label(2, 31, "=", fontCategoryFormat));

        sheetRoi.addCell(new Label(3, 9, "Selling Price:", fontCategoryFormat));
        sheetRoi.addCell(new Label(3, 10, "Energy Cost:", fontCategoryFormat));
        sheetRoi.addCell(new Label(3, 11, "Waste per splice saved with flag camera:", fontCategoryFormat));
        sheetRoi.addCell(new Label(3, 12, "Waste per mother saved with alignment guide:", fontCategoryFormat));
        sheetRoi.addCell(new Label(7, 9, "Contribution:", fontCategoryFormat));
        sheetRoi.addCell(new Label(10, 9, "Value Added:", fontCategoryFormat));
        sheetRoi.addCell(
                new Label(5, 9, "" + formatDecimal(RoiData.sellingprice) + " / tonne", fontDataFormat));
        sheetRoi.addCell(new Label(5, 10, "" + formatDecimal(RoiData.energycost) + " / kWh", fontDataFormat));
        sheetRoi.addCell(new Label(8, 11, "" + formatDecimal(RoiData.wastesavedflag), fontDataFormat));
        sheetRoi.addCell(new Label(8, 12, "" + formatDecimal(RoiData.wastesavedguide), fontDataFormat));
        sheetRoi.addCell(new Label(9, 9, formatDecimal(RoiData.contribution * 100) + "%", fontDataFormat));
        sheetRoi.addCell(new Label(12, 9, "" + formatDecimal(RoiData.value) + " / tonne", fontDataFormat));

        for (int i = 0; i < results.getSize(); ++i) {
            Result r = results.get(i);
            ResultROI roi = RoiResults.get(i);

            int x = 3 + 3 * i;

            // add model logo
            switch (r.getModelType()) {
            case ER610:
                sheetRoi.addImage(new WritableImage(x, 14, 2, 3, imgER610));
                break;
            case SR9DS:
                sheetRoi.addImage(new WritableImage(x, 14, 2, 3, imgSR9DS));
                break;
            case SR9DT:
                sheetRoi.addImage(new WritableImage(x, 14, 2, 3, imgSR9DT));
                break;
            case SR800:
                sheetRoi.addImage(new WritableImage(x, 14, 2, 3, imgSR800));
                break;
            case CUSTOM:
                sheetRoi.addImage(new WritableImage(x, 14, 2, 3, imgCustom));
                break;
            }

            // description
            sheetRoi.addCell(new Label(x, 17, r.getName(), fontDataFormat));

            //todo: units type, write units, values
            sheetRoi.addCell(new Number(x, 19,
                    roundTwoDecimals(RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear
                            / environment.HrsPerYear),
                    fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 19, "kW", fontDataFormat));
            sheetRoi.addCell(new Number(x, 20,
                    roundTwoDecimals(
                            RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear / 1000),
                    fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 20, "MWh", fontDataFormat));
            sheetRoi.addCell(new Number(x, 21,
                    roundTwoDecimals(RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours),
                    fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 21, "hrs", fontDataFormat));
            sheetRoi.addCell(new Label(x, 22,
                    "" + formatDecimal(
                            RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).labourhourly),
                    fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 22, "/ hour", fontDataFormat));
            sheetRoi.addCell(new Label(x, 23,
                    "" + formatDecimal(RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).parts),
                    fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 23, "/ year", fontDataFormat));

            sheetRoi.addCell(new Number(x, 25, roundTwoDecimals(roi.value), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 25, " / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 26, roundTwoDecimals(roi.energycost), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 26, " / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 27, roundTwoDecimals(roi.prodloss), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 27, " / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 28, roundTwoDecimals(roi.partcosts), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 28, " / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 29, roundTwoDecimals(roi.maintcost), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 29, " / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 30, roundTwoDecimals(roi.wastesave), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 30, "m / yr", fontDataFormat));
            sheetRoi.addCell(new Number(x, 31, roundTwoDecimals(roi.wasteval), fontNumberFormat));
            sheetRoi.addCell(new Label(x + 1, 31, " / yr", fontDataFormat));

        }

        //results
        JFreeChart a = null, b = null, c = null, d = null;
        try {
            if (RoiResults.getProdGraph() != null)
                a = (JFreeChart) RoiResults.getProdGraph().clone();
            if (RoiResults.getEnergyGraph() != null)
                b = (JFreeChart) RoiResults.getEnergyGraph().clone();
            if (RoiResults.getMaintGraph() != null)
                c = (JFreeChart) RoiResults.getMaintGraph().clone();
            if (RoiResults.getWasteGraph() != null)
                d = (JFreeChart) RoiResults.getWasteGraph().clone();
        } catch (CloneNotSupportedException e1) {
            errors = true;
        }

        sheetRoi.addCell(new Label(1, 34, "Graphical Results:", fontJobHeadFormat));

        try {
            ChartUtilities.saveChartAsPNG(froia, a, 600, 360);
            sheetRoi.addImage(new WritableImage(1, 36, 8, 18, froia));
        } catch (Exception e1) {
            sheetRoi.addCell(new Label(1, 36, "No productivity chart found"));
        }
        try {
            ChartUtilities.saveChartAsPNG(froib, b, 600, 360);
            sheetRoi.addImage(new WritableImage(10, 36, 8, 18, froib));
        } catch (Exception e1) {
            sheetRoi.addCell(new Label(10, 36, "No energy chart found"));
        }
        try {
            ChartUtilities.saveChartAsPNG(froic, c, 600, 360);
            sheetRoi.addImage(new WritableImage(1, 55, 8, 18, froic));
        } catch (Exception e1) {
            sheetRoi.addCell(new Label(1, 55, "No maintenance chart found"));
        }
        try {
            ChartUtilities.saveChartAsPNG(froid, d, 600, 360);
            sheetRoi.addImage(new WritableImage(10, 55, 8, 18, froid));
        } catch (Exception e1) {
            sheetRoi.addCell(new Label(10, 55, "No waste chart found"));
        }

        sheetRoi.addCell(new Label(PAGE4_WIDTH - 4, PAGE4_HEIGHT + 6 + 1,
                "Calculations are approximations only", fontFootnoteFormat));
    }

    // All sheets and cells added. Now write out the workbook 
    workbook.write();
    workbook.close();

    // Delete temp files (graphs)
    DeleteFile(fs);
    DeleteFile(fresa);
    DeleteFile(fresb);
    DeleteFile(fresc);
    DeleteFile(fresd);
    DeleteFile(froia);
    DeleteFile(froib);
    DeleteFile(froic);
    DeleteFile(froid);
    for (int i = 0; i < brkdns.length; ++i)
        DeleteFile(brkdns[i]);
    // TODO more...

    //} catch (RowsExceededException e){
    ///TODO show error...
    //   success = false;
    //} catch (WriteException e){
    //   success = false;
    //} catch (IOException e) {
    //   success = false;
    //} catch (Exception e){
    //   success = false;
    //}
    // TODO errors=true indicates success but with errors
    //return success;

    return !errors;
}