Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getInstance.

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.CombinedCategoryBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");

    // recover the datasets
    DefaultCategoryDataset datasetBarFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-bar");
    DefaultCategoryDataset datasetBarSecondAxis = (DefaultCategoryDataset) datasets.getDatasets().get("2-bar");
    DefaultCategoryDataset datasetLineFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-line");
    DefaultCategoryDataset datasetLineSecondAxis = (DefaultCategoryDataset) datasets.getDatasets()
            .get("2-line");

    // create the two subplots
    CategoryPlot subPlot1 = new CategoryPlot();
    CategoryPlot subPlot2 = new CategoryPlot();
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    subPlot1.setDataset(0, datasetBarFirstAxis);
    subPlot2.setDataset(0, datasetBarSecondAxis);

    subPlot1.setDataset(1, datasetLineFirstAxis);
    subPlot2.setDataset(1, datasetLineSecondAxis);

    // localize numbers on y axis
    NumberFormat nf = (NumberFormat) NumberFormat.getNumberInstance(locale);

    // Range Axis 1
    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis//  w w  w  .j a  v a 2s  .c o m
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);
    subPlot1.setRangeAxis(rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Range Axis 2
    NumberAxis rangeAxis2 = new NumberAxis(secondAxisLabel);
    rangeAxis2.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2.setUpperMargin(0.10);
    rangeAxis2.setNumberFormatOverride(nf);
    subPlot2.setRangeAxis(rangeAxis2);
    if (rangeIntegerValues == true) {
        rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Category Axis
    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    plot.setDomainAxis(domainAxis);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // Add subplots to main plot
    plot.add(subPlot1, 1);
    plot.add(subPlot2, 2);

    MyStandardCategoryItemLabelGenerator generator = null;

    // value labels and additional values are mutually exclusive
    if (showValueLabels == true)
        additionalLabels = false;

    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
    }

    //      Create Renderers!
    CategoryItemRenderer barRenderer1 = new BarRenderer();
    CategoryItemRenderer barRenderer2 = new BarRenderer();
    LineAndShapeRenderer lineRenderer1 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;
    LineAndShapeRenderer lineRenderer2 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;

    subPlot1.setRenderer(0, barRenderer1);
    subPlot2.setRenderer(0, barRenderer2);

    if (useLinesRenderers == true) {
        subPlot1.setRenderer(1, lineRenderer1);
        subPlot2.setRenderer(1, lineRenderer2);

        // no shapes for line_no_shapes  series
        for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that
            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineFirstAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer1.setSeriesShapesVisible(index, false);
            }
        }
        for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that

            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineSecondAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer2.setSeriesShapesVisible(index, false);
            }
        }

    }

    // add tooltip if enabled
    if (enableToolTips) {
        MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                seriesTooltip, categoriesTooltip, seriesCaptions);
        barRenderer1.setToolTipGenerator(generatorToolTip);
        barRenderer2.setToolTipGenerator(generatorToolTip);
        if (useLinesRenderers) {
            lineRenderer1.setToolTipGenerator(generatorToolTip);
            lineRenderer2.setToolTipGenerator(generatorToolTip);
        }
    }

    subPlot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    subPlot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // COnfigure renderers: I do in extensive way so will be easier to add customization in the future

    if (maxBarWidth != null) {
        ((BarRenderer) barRenderer1).setMaximumBarWidth(maxBarWidth.doubleValue());
        ((BarRenderer) barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    // Values or addition Labels for first BAR Renderer
    if (showValueLabels) {
        barRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer1.setBaseItemLabelsVisible(true);
        barRenderer1.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer2.setBaseItemLabelsVisible(true);
        barRenderer2.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

    } else if (additionalLabels) {
        barRenderer1.setBaseItemLabelGenerator(generator);
        barRenderer2.setBaseItemLabelGenerator(generator);

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

    }

    // Values or addition Labels for line Renderers if requested
    if (useLinesRenderers == true) {
        if (showValueLabels) {
            lineRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer1.setBaseItemLabelsVisible(true);
            lineRenderer1.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer1.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer1.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer2.setBaseItemLabelsVisible(true);
            lineRenderer2.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer2.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        } else if (additionalLabels) {
            lineRenderer1.setBaseItemLabelGenerator(generator);
            lineRenderer2.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }
            lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

        }
    }

    // Bar Dataset Colors!
    if (colorMap != null) {
        int idx = -1;
        for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarFirstAxis.getRowIndex(labelName);
            } else
                index = datasetBarFirstAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer1.setSeriesPaint(index, color);
            }
        }

        for (Iterator iterator = datasetBarSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarSecondAxis.getRowIndex(labelName);
            } else
                index = datasetBarSecondAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer2.setSeriesPaint(index, color);
            }
        }
    }

    // LINE Dataset Colors!
    if (useLinesRenderers == true) {
        if (colorMap != null) {
            int idx = -1;
            for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineFirstAxis.getRowIndex(labelName);
                } else
                    index = datasetLineFirstAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer1.setSeriesPaint(index, color);
                }
            }

            for (Iterator iterator = datasetLineSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineSecondAxis.getRowIndex(labelName);
                } else
                    index = datasetLineSecondAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer2.setSeriesPaint(index, color);
                }
            }
        }
    }

    //defines url for drill
    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    logger.debug("Calling Url Generation");

    MyCategoryUrlGenerator mycatUrl = null;
    if (super.rootUrl != null) {
        logger.debug("Set MycatUrl");
        mycatUrl = new MyCategoryUrlGenerator(super.rootUrl);

        mycatUrl.setDocument_composition(document_composition);
        mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
        mycatUrl.setSerieUrlLabel(super.serieUrlname);
        mycatUrl.setDrillDocTitle(drillDocTitle);
        mycatUrl.setTarget(target);
    }
    if (mycatUrl != null) {
        barRenderer1.setItemURLGenerator(mycatUrl);
        barRenderer2.setItemURLGenerator(mycatUrl);
        if (useLinesRenderers) {
            lineRenderer1.setItemURLGenerator(mycatUrl);
            lineRenderer2.setItemURLGenerator(mycatUrl);
        }

    }

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.setBackgroundPaint(Color.white);

    //      I want to re order the legend
    LegendItemCollection legends = plot.getLegendItems();
    // legend Temp 
    HashMap<String, LegendItem> legendTemp = new HashMap<String, LegendItem>();
    Vector<String> alreadyInserted = new Vector<String>();
    for (int i = 0; i < legends.getItemCount(); i++) {
        LegendItem item = legends.get(i);
        String label = item.getLabel();
        legendTemp.put(label, item);
    }
    LegendItemCollection newLegend = new LegendItemCollection();
    // force the order of the ones specified
    for (Iterator iterator = seriesOrder.iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (legendTemp.keySet().contains(serie)) {
            newLegend.add(legendTemp.get(serie));
            alreadyInserted.add(serie);
        }
    }
    // check that there are no serie not specified, otherwise add them
    for (Iterator iterator = legendTemp.keySet().iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (!alreadyInserted.contains(serie)) {
            newLegend.add(legendTemp.get(serie));
        }
    }

    plot.setFixedLegendItems(newLegend);

    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");

    return chart;

}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenModalDetailForm.java

public void initialiseDetailForm() {
    idTxtFld = new TextField<String>("biospecimen.id");
    biospecimenUidTxtFld = new TextField<String>("biospecimen.biospecimenUid");
    biospecimenUidTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override/*from ww  w. j a  va  2s  .  c o  m*/
        protected void onUpdate(AjaxRequestTarget target) {
            // Check BiospecimenUID is unique
            String biospecimenUid = (getComponent().getDefaultModelObject().toString() != null
                    ? getComponent().getDefaultModelObject().toString()
                    : new String());
            Biospecimen biospecimen = iLimsService.getBiospecimenByUid(biospecimenUid,
                    cpModel.getObject().getBiospecimen().getStudy());
            if (biospecimen != null && biospecimen.getId() != null) {
                error("Biospecimen UID must be unique. Please try again.");
                target.focusComponent(getComponent());
            }
            target.add(feedbackPanel);
        }
    });

    parentUidTxtFld = new TextField<String>("biospecimen.parentUid");
    commentsTxtAreaFld = new TextArea<String>("biospecimen.comments");
    sampleDateTxtFld = new DateTextField("biospecimen.sampleDate", au.org.theark.core.Constants.DD_MM_YYYY);
    useCollectionDate = new AjaxLink<Date>("useCollectionDate") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            BioCollection selectedBioCollection = cpModel.getObject().getBioCollection();
            cpModel.getObject().getBiospecimen().setSampleDate(selectedBioCollection.getCollectionDate());
            target.add(sampleDateTxtFld);
        }
    };

    sampleTimeTxtFld = new TimeField("biospecimen.sampleTime") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onBeforeRender() {
            this.getDateTextField().setVisibilityAllowed(false);
            super.onBeforeRender();
        }

        @Override
        protected void convertInput() {
            // Slight change to not default to today's date
            Date modelObject = (Date) getDefaultModelObject();
            getDateTextField().setConvertedInput(modelObject != null ? modelObject : null);
            super.convertInput();
        }
    };

    processedDateTxtFld = new DateTextField("biospecimen.processedDate",
            au.org.theark.core.Constants.DD_MM_YYYY);
    processedTimeTxtFld = new TimeField("biospecimen.processedTime") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onBeforeRender() {
            this.getDateTextField().setVisibilityAllowed(false);
            super.onBeforeRender();
        }

        @Override
        protected void convertInput() {
            // Slight change to not default to today's date
            Date modelObject = (Date) getDefaultModelObject();
            getDateTextField().setConvertedInput(modelObject != null ? modelObject : null);
            super.convertInput();
        }
    };

    ArkDatePicker sampleDatePicker = new ArkDatePicker();
    sampleDatePicker.bind(sampleDateTxtFld);
    sampleDateTxtFld.add(sampleDatePicker);

    ArkDatePicker processedDatePicker = new ArkDatePicker();
    processedDatePicker.bind(processedDateTxtFld);
    processedDateTxtFld.add(processedDatePicker);

    quantityTxtFld = new TextField<Double>("biospecimen.quantity") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            DoubleConverter doubleConverter = new DoubleConverter();
            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMinimumFractionDigits(1);
            numberFormat.setMaximumFractionDigits(10);
            doubleConverter.setNumberFormat(getLocale(), numberFormat);
            return (IConverter<C>) doubleConverter;
        }
    };
    parentQuantityTxtFld = new TextField<Double>("parentBiospecimen.quantity") {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            DoubleConverter doubleConverter = new DoubleConverter();
            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMinimumFractionDigits(1);
            numberFormat.setMaximumFractionDigits(10);
            doubleConverter.setNumberFormat(getLocale(), numberFormat);
            return (IConverter<C>) doubleConverter;
        }
    };
    parentQuantityTxtFld.setVisible(cpModel.getObject().getBiospecimenProcessing()
            .equalsIgnoreCase(au.org.theark.lims.web.Constants.BIOSPECIMEN_PROCESSING_PROCESSING));
    parentQuantityTxtFld.setOutputMarkupId(true);

    quantityTxtFld.setEnabled(false);
    bioTransactionQuantityTxtFld = new TextField<Double>("bioTransaction.quantity") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            DoubleConverter doubleConverter = new DoubleConverter();
            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMinimumFractionDigits(1);
            numberFormat.setMaximumFractionDigits(10);
            doubleConverter.setNumberFormat(getLocale(), numberFormat);
            return (IConverter<C>) doubleConverter;
        }
    };
    bioTransactionQuantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(amountLbl);
        }
    });

    concentrationTxtFld = new TextField<Number>("biospecimen.concentration");
    concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(amountLbl);
        }
    });
    amountLbl = new Label("biospecimen.amount", new Model<Number>() {
        private static final long serialVersionUID = 1L;

        @Override
        public Number getObject() {
            Number concentration = ((concentrationTxtFld.getModelObject() == null) ? 0
                    : concentrationTxtFld.getModelObject());
            Number quantity = null;
            if (bioTransactionQuantityTxtFld.isVisible()) {
                quantity = ((bioTransactionQuantityTxtFld.getModelObject() == null) ? 0
                        : bioTransactionQuantityTxtFld.getModelObject());
            } else {
                quantity = ((quantityTxtFld.getModelObject() == null) ? 0 : quantityTxtFld.getModelObject());
            }
            Number amount = (concentration.doubleValue() * quantity.doubleValue());
            return amount;
        }
    });
    amountLbl.setOutputMarkupPlaceholderTag(true);

    setQuantityLabel();
    initSampleTypeDdc();
    initBioCollectionDdc();
    initUnitDdc();
    initTreatmentTypeDdc();
    initGradeDdc();
    initStoredInDdc();
    initAnticoagDdc();
    initStatusDdc();
    initQualityDdc();
    initBiospecimenProtocol();
    purity = new TextField<Number>("biospecimen.purity");

    barcodedChkBox = new CheckBox("biospecimen.barcoded");
    barcodedChkBox.setVisible(true);
    barcodedChkBox.setEnabled(false);

    initialiseBarcodeImage();

    initialiseBiospecimenCFDataEntry();
    initialiseBioTransactionListPanel();
    initialiseBiospecimenLocationPanel();
    initialiseBiospecimenButtonsPanel();
    initDeleteModelWindow();

    attachValidators();
    addComponents();

    // Focus on Sample Type
    sampleTypeDdc.add(new ArkDefaultFormFocusBehavior());
}

From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java

private void showCaloriesBurnt() {
    try {/* w w w  . j  a v a 2  s  .co  m*/
        Number numWeight = NumberFormat.getInstance().parse(weightString);
        weightInt = numWeight.floatValue();
        float caloriesBurntInt = (((showElapsedTime()) * weightInt) * 8);
        caloriesBurntInt = caloriesBurntInt / 1000;
        NumberFormat formatter = NumberFormat.getNumberInstance();
        formatter.setMinimumFractionDigits(4);
        formatter.setMaximumFractionDigits(4);
        String finalBurn = formatter.format(caloriesBurntInt);
        mCaloriesBurnt.setText(finalBurn);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void upvoteStory() {
    if (designerNewsPrefs.isLoggedIn()) {
        if (!upvoteStory.isActivated()) {
            upvoteStory.setActivated(true);
            designerNewsApi.upvoteStory(story.id, "", new Callback<StoryResponse>() {
                @Override/*  www . j a  va  2s  . c  om*/
                public void success(StoryResponse storyResponse, Response response) {
                    final int newUpvoteCount = storyResponse.story.vote_count;
                    upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, newUpvoteCount,
                            NumberFormat.getInstance().format(newUpvoteCount)));
                }

                @Override
                public void failure(RetrofitError error) {
                }
            });
        } else {
            upvoteStory.setActivated(false);
            // TODO delete upvote. Not available in v1 API.
        }

    } else {
        needsLogin(upvoteStory, RC_LOGIN_UPVOTE);
    }
}

From source file:nattable.ColorNatInstance.java

/**
 * Format: Double to a specified number of decimal places
 *//*w w w  .  j a v  a  2s .  c  om*/
private static IDisplayConverter getDoubleDisplayConverter(final int decimalPlaces) {
    return new DisplayConverter() {
        NumberFormat numberFormatter = NumberFormat.getInstance();

        public Object canonicalToDisplayValue(Object canonicalValue) {
            if (canonicalValue == null) {
                return "";
            }
            numberFormatter.setMaximumFractionDigits(decimalPlaces);
            numberFormatter.setMinimumFractionDigits(decimalPlaces);
            return numberFormatter.format(Double.valueOf(canonicalValue.toString()));
        }

        public Object displayToCanonicalValue(Object displayValue) {
            try {
                return numberFormatter.parse((String) displayValue);
            } catch (ParseException e) {
                return null;
            }
        }

    };
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void upvoteStory() {
    if (designerNewsPrefs.isLoggedIn()) {
        if (!upvoteStory.isActivated()) {
            upvoteStory.setActivated(true);
            final Call<Story> upvoteStory = designerNewsPrefs.getApi().upvoteStory(story.id);
            upvoteStory.enqueue(new Callback<Story>() {
                @Override//ww  w.jav a 2  s . c o  m
                public void onResponse(Call<Story> call, Response<Story> response) {
                    final int newUpvoteCount = response.body().vote_count;
                    DesignerNewsStory.this.upvoteStory
                            .setText(getResources().getQuantityString(R.plurals.upvotes, newUpvoteCount,
                                    NumberFormat.getInstance().format(newUpvoteCount)));
                }

                @Override
                public void onFailure(Call<Story> call, Throwable t) {
                }
            });
        } else {
            upvoteStory.setActivated(false);
            // TODO delete upvote. Not available in v1 API.
        }

    } else {
        needsLogin(upvoteStory, RC_LOGIN_UPVOTE);
    }
}

From source file:com.autentia.tnt.bean.admin.ProjectBean.java

public String getWorkedHours() {
    long total = project.getWorkedHours();
    String totalWorked = "0";

    if (total != 0) {
        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(2);
        totalWorked = format.format(total / 60); // Convertimos a horas
    }/*from  www  . ja  v  a 2s .  c o  m*/

    return totalWorked;
}

From source file:hudson.plugins.plot.Plot.java

/**
 * Generates the plot and stores it in the plot instance variable.
 *
 * @param forceGenerate//from w ww.j  a va2  s .  c  om
 *            if true, force the plot to be re-generated even if the on-disk
 *            data hasn't changed
 */
private void generatePlot(boolean forceGenerate) {
    class Label implements Comparable<Label> {
        final private Integer buildNum;
        final private String buildDate;
        final private String text;

        public Label(String buildNum, String buildTime, String text) {
            this.buildNum = Integer.parseInt(buildNum);
            synchronized (DATE_FORMAT) {
                this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime)));
            }
            this.text = text;
        }

        public Label(String buildNum, String buildTime) {
            this(buildNum, buildTime, null);
        }

        public int compareTo(Label that) {
            return this.buildNum - that.buildNum;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof Label && ((Label) o).buildNum.equals(buildNum);
        }

        @Override
        public int hashCode() {
            return buildNum.hashCode();
        }

        public String numDateString() {
            return "#" + buildNum + " (" + buildDate + ")";
        }

        @Override
        public String toString() {
            return text != null ? text : numDateString();
        }
    }
    // LOGGER.info("Determining if we should generate plot " +
    // getCsvFileName());
    File csvFile = new File(project.getRootDir(), getCsvFileName());
    if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) {
        // data hasn't changed so don't regenerate the plot
        return;
    }
    if (rawPlotData == null || csvFile.lastModified() > csvLastModification) {
        // data has changed or has not been loaded so load it now
        loadPlotData();
    }
    // LOGGER.info("Generating plot " + getCsvFileName());
    csvLastModification = csvFile.lastModified();
    PlotCategoryDataset dataset = new PlotCategoryDataset();
    for (String[] record : rawPlotData) {
        // record: series y-value, series label, build number, build date,
        // url
        int buildNum;
        try {
            buildNum = Integer.valueOf(record[2]);
            if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) {
                continue; // skip this record
            }
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            continue; // skip this record all together
        }
        Number value = null;
        try {
            value = Integer.valueOf(record[0]);
        } catch (NumberFormatException nfe) {
            try {
                value = Double.valueOf(record[0]);
            } catch (NumberFormatException nfe2) {
                LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2);
                continue; // skip this record all together
            }
        }
        String series = record[1];
        Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum))
                : new Label(record[2], record[3]);
        String url = null;
        if (record.length >= 5)
            url = record[4];
        dataset.setValue(value, url, series, xlabel);
    }

    String urlNumBuilds = getURLNumBuilds();
    int numBuilds;
    if (StringUtils.isBlank(urlNumBuilds)) {
        numBuilds = Integer.MAX_VALUE;
    } else {
        try {
            numBuilds = Integer.parseInt(urlNumBuilds);
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            numBuilds = Integer.MAX_VALUE;
        }
    }

    dataset.clipDataset(numBuilds);
    plot = createChart(dataset);
    CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot();
    categoryPlot.setDomainGridlinePaint(Color.black);
    categoryPlot.setRangeGridlinePaint(Color.black);
    categoryPlot.setDrawingSupplier(Plot.supplier);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build());
    categoryPlot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.03);
    domainAxis.setCategoryMargin(0.0);
    for (Object category : dataset.getColumnKeys()) {
        Label label = (Label) category;
        if (label.text != null) {
            domainAxis.addCategoryLabelToolTip(label, label.numDateString());
        } else {
            domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum));
        }
    }
    // Replace the range axis by a logarithmic axis if the option is
    // selected
    if (isLogarithmic()) {
        LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis());
        logAxis.setExpTickLabelsFlag(true);
        categoryPlot.setRangeAxis(logAxis);
    }

    // optionally exclude zero as default y-axis value
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();
    if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) {
        if (hasYaxisMinimum()) {
            ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum());
        }
        if (hasYaxisMaximum()) {
            ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum());
        }
        ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero());
    }

    AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer();
    int numColors = dataset.getRowCount();
    for (int i = 0; i < numColors; i++) {
        renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f)));
    }
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}",
            NumberFormat.getInstance()));
    renderer.setBaseItemURLGenerator(new PointURLGenerator());
    if (renderer instanceof LineAndShapeRenderer) {
        String s = getUrlStyle();
        LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer;
        if ("lineSimple".equalsIgnoreCase(s)) {
            lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary
        } else {
            lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary
        }
    }
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private void storyUpvoted(int newUpvoteCount) {
    upvoteStory.setText(getResources().getQuantityString(io.plaidapp.R.plurals.upvotes, newUpvoteCount,
            NumberFormat.getInstance().format(newUpvoteCount)));
}

From source file:canreg.client.analysis.AgeSpecificCasesTableBuilder.java

@Override
public LinkedList<String> buildTable(String registryLabel, String reportFileName, int startYear, int endYear,
        Object[][] incidenceData, PopulationDataset[] populations, PopulationDataset[] standardPopulations,
        LinkedList<ConfigFields> configList, String[] engineParameters, FileTypes fileType)
        throws NotCompatibleDataException {

    LinkedList<String> generatedFiles = new LinkedList<String>();

    String footerString = java.util.ResourceBundle
            .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
            .getString("TABLE BUILT ")
            + new Date()
            + java.util.ResourceBundle
                    .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
                    .getString(" BY CANREG5.");

    String notesString = "";

    if (populations[0].getFilter().length() > 0) {
        notesString = java.util.ResourceBundle
                .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
                .getString("FILTER USED:") + " " + populations[0].getFilter();
    }/*from   w w w .  j a va 2 s.c  o m*/

    double tableFontSize = 7.5;
    String font = "Times";

    int[] years = { startYear, endYear };

    //      double RegPop[][];
    double totalCases[][];

    String sexLabel[] = null;
    String tableLabel[] = null;
    String icdLabel[] = null;

    LinkedList cancerGroupsLocal[] = null;

    boolean showSeeNotesNote = true;

    char Childc[][] = new char[2][3];

    double casesPerHundredThousand[][][];

    double cumRate64[][];
    double cumRate74[][];

    tableLabel = ConfigFieldsReader.findConfig("table_label", configList);
    // sexLabel = ConfigFieldsReader.findConfig("sex_label", configList);
    sexLabel = new String[] {
            java.util.ResourceBundle.getBundle("canreg/client/analysis/resources/AbstractEditorialTableBuilder")
                    .getString("MALE"),
            java.util.ResourceBundle.getBundle("canreg/client/analysis/resources/AbstractEditorialTableBuilder")
                    .getString("FEMALE") };

    icdLabel = ConfigFieldsReader.findConfig("ICD_groups_labels", configList);
    icd10GroupDescriptions = ConfigFieldsReader.findConfig("ICD10_groups", configList);

    cancerGroupsLocal = EditorialTableTools.generateICD10Groups(icd10GroupDescriptions);

    allCancerGroupsIndex = EditorialTableTools.getICD10index("ALL", icd10GroupDescriptions);

    leukemiaNOSCancerGroupIndex = EditorialTableTools.getICD10index(950, cancerGroupsLocal);

    skinCancerGroupIndex = EditorialTableTools.getICD10index("C44", icd10GroupDescriptions);

    bladderCancerGroupIndex = EditorialTableTools.getICD10index("C67", icd10GroupDescriptions);

    mesotheliomaCancerGroupIndex = EditorialTableTools.getICD10index("C45", icd10GroupDescriptions);

    kaposiSarkomaCancerGroupIndex = EditorialTableTools.getICD10index("C46", icd10GroupDescriptions);

    myeloproliferativeDisordersCancerGroupIndex = EditorialTableTools.getICD10index("MPD",
            icd10GroupDescriptions);

    myelodysplasticSyndromesCancerGroupIndex = EditorialTableTools.getICD10index("MDS", icd10GroupDescriptions);

    allCancerGroupsButSkinIndex = EditorialTableTools.getICD10index("ALLbC44", icd10GroupDescriptions);

    leukemiaNOSCancerGroupIndex = EditorialTableTools.getICD10index(950, cancerGroupsLocal);

    brainAndCentralNervousSystemCancerGroupIndex = EditorialTableTools.getICD10index("C70-72",
            icd10GroupDescriptions);

    ovaryCancerGroupIndex = EditorialTableTools.getICD10index(569, cancerGroupsLocal);

    otherCancerGroupsIndex = EditorialTableTools.getICD10index("O&U", icd10GroupDescriptions);

    numberOfCancerGroups = cancerGroupsLocal.length;

    lineBreaks = parseLineBreaks(ConfigFieldsReader.findConfig("line_breaks", configList));

    numberOfYears = years[1] - years[0] + 1;

    minimumCasesLimit = minimumCasesPerYearLimit * numberOfYears;

    noOldData = true;

    casesPerHundredThousand = new double[numberOfSexes][numberOfAgeGroups][numberOfCancerGroups];

    casesArray = new double[numberOfCancerGroups][numberOfSexes][numberOfAgeGroups];

    // cumRate64 = new double[numberOfSexes][numberOfCancerGroups];
    // cumRate74 = new double[numberOfSexes][numberOfCancerGroups];
    populationArray = new double[numberOfSexes][numberOfAgeGroups];
    foundAgeGroups = new boolean[numberOfAgeGroups];

    if (areThesePopulationDatasetsCompatible(populations)) {
        for (PopulationDataset population : populations) {
            population.addPopulationDataToArrayForTableBuilder(populationArray, foundAgeGroups,
                    new AgeGroupStructure(5, 85, 1));
        }
    } else {
        throw new NotCompatibleDataException();
    }

    populationString = populations[0].getPopulationDatasetName();

    int lastCommaPlace = populationString.lastIndexOf(",");

    if (lastCommaPlace != -1) {
        populationString = populationString.substring(0, lastCommaPlace);
    }

    if (populations[0].getFilter().length() > 0) {
        notesString = java.util.ResourceBundle
                .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
                .getString("FILTER USED:") + populations[0].getFilter();
    }

    standardPopulationArray = new double[numberOfSexes][numberOfAgeGroups];

    for (PopulationDataset stdPopulation : standardPopulations) {
        stdPopulation.addPopulationDataToArrayForTableBuilder(standardPopulationArray, null,
                new AgeGroupStructure(5, 85, 1));
    }

    // standardize population array
    for (int sexNumber = 0; sexNumber < numberOfSexes; sexNumber++) {
        for (int ageGroupNumber = 0; ageGroupNumber < numberOfAgeGroups; ageGroupNumber++) {
            standardPopulationArray[sexNumber][ageGroupNumber] = (standardPopulationArray[sexNumber][ageGroupNumber]
                    / standardPopulationArray[sexNumber][numberOfAgeGroups - 1]) * 100000;
        }
    }

    highestPopulationAgeGroup = findHighestAgeGroup(foundAgeGroups);
    lowestPopulationAgeGroup = findLowestAgeGroup(foundAgeGroups);

    int records = 0;
    // generate statistics

    String sexString;
    String icdString;
    String yearString;
    String ageString;
    String basisString;

    int sex, icdNumber, year, icdIndex, yearIndex, ageGroup, ageInt, basis, cases;

    if (incidenceData != null) {
        for (Object[] line : incidenceData) {
            try {
                // Set default
                icdIndex = -1;
                cases = 0;

                // Unknown sex group = 3
                sex = 3;
                // Extract data
                sexString = (String) line[SEX_COLUMN];
                sex = Integer.parseInt(sexString.trim());

                // sex = 3 is unknown sex
                if (sex > 2) {
                    sex = 3;
                }

                // morphologyString = (String) line[MORPHOLOGY_COLUMN];

                /*
                if (morphologyString.length() > 0) {
                int morphology = Integer.parseInt(morphologyString);
                if (morphology == 9140) {
                String behaviourString = getContentOfField(
                incidenceFieldDescriptionList,
                "behaviour", line).trim();
                if (behaviourString.equals("3")) {
                icdIndex = kaposiSarkomaCancerGroupIndex;
                }
                        
                } else if ((int)(morphology/10) == 905) {
                String behaviourString = getContentOfField(incidenceFieldDescriptionList,
                "behaviour", line).trim();
                if (behaviourString.equals("3")) {
                icdIndex = mesotheliomaCancerGroupIndex;
                }
                }
                }
                 */
                if (icdIndex < 0) {
                    icdString = (String) line[ICD10_COLUMN];
                    if (icdString.length() > 0 && icdString.trim().substring(0, 1).equals("C")) {
                        icdString = icdString.trim().substring(1);
                        icdNumber = Integer.parseInt(icdString);
                        if (icdString.length() < 3) {
                            icdNumber = icdNumber * 10;
                        }
                        icdIndex = EditorialTableTools.getICD10index(icdNumber, cancerGroupsLocal);
                        if (icdIndex == -1) {
                            icdIndex = -1;
                        }
                    } else if (icdString.length() > 0 && icdString.trim().substring(0, 1).equals("D")) {
                        icdIndex = DONT_COUNT; // set don't count as default
                        icdString = icdString.trim().substring(1);
                        icdNumber = Integer.parseInt(icdString);
                        if (icdString.length() < 3) {
                            icdNumber = icdNumber * 10;
                        }
                        if (icdNumber == 90 || icdNumber == 414) {
                            icdIndex = bladderCancerGroupIndex;
                        } else if (((int) (icdNumber / 10)) == 45 || ((int) (icdNumber / 10)) == 47) {
                            icdIndex = myeloproliferativeDisordersCancerGroupIndex;
                        } else if (((int) (icdNumber / 10)) == 46) {
                            icdIndex = myelodysplasticSyndromesCancerGroupIndex;
                        }
                    }
                }

                yearString = line[YEAR_COLUMN].toString();
                year = Integer.parseInt(yearString);
                yearIndex = year - years[0];
                ageString = line[AGE_COLUMN].toString();
                ageInt = Integer.parseInt(ageString);

                if (ageInt == unknownAgeInt) {
                    ageGroup = unknownAgeGroupIndex;
                } else {
                    ageGroup = populations[yearIndex].getAgeGroupIndex(ageInt);
                    // Adjust age group
                    if (populations[yearIndex].getAgeGroupStructure().getSizeOfFirstGroup() != 1) {
                        ageGroup += 1;
                    }
                }

                // Extract cases
                cases = (Integer) line[CASES_COLUMN];

                if (icdIndex != DONT_COUNT && year <= years[1] && year >= years[0]) {

                    // Basis of diagnosis
                    basisString = line[BASIS_DIAGNOSIS_COLUMN].toString();
                    if (basisString != null) {
                        basis = Integer.parseInt(basisString.trim());
                    } else {
                        basis = -1;
                    }

                    if (sex <= numberOfSexes && icdIndex >= 0 && icdIndex <= cancerGroupsLocal.length) {

                        casesArray[icdIndex][sex - 1][ageGroup] += cases;

                    } else if (otherCancerGroupsIndex >= 0) {
                        casesArray[otherCancerGroupsIndex][sex - 1][ageGroup] += cases;
                    }
                    if (allCancerGroupsIndex >= 0) {
                        casesArray[allCancerGroupsIndex][sex - 1][ageGroup] += cases;
                    }
                    if (allCancerGroupsButSkinIndex >= 0 && skinCancerGroupIndex >= 0
                            && icdIndex != skinCancerGroupIndex) {
                        casesArray[allCancerGroupsButSkinIndex][sex - 1][ageGroup] += cases;
                    }
                    records += cases;
                    if (records % recordsPerFeedback == 0) {
                        System.out.println(java.util.ResourceBundle
                                .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
                                .getString("PROCESSING RECORD NUMBER: ") + records);
                    }
                }
            } catch (NumberFormatException nfe) {
                Logger.getLogger(AgeSpecificCasesTableBuilder.class.getName()).log(Level.WARNING, null, nfe);
            }
            // Read next line
        }
    }
    System.out.println(java.util.ResourceBundle
            .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder").getString("PROCESSED ")
            + records
            + java.util.ResourceBundle
                    .getBundle("canreg/client/analysis/resources/AgeSpecificCasesTableBuilder")
                    .getString(" RECORDS."));

    // Total casesPerHundredThousand
    totalCases = new double[numberOfSexes][numberOfCancerGroups];
    // Crude rate
    // crudeRate = new double[numberOfSexes][numberOfCancerGroups];

    for (int sexNumber = 0; sexNumber < 2; sexNumber++) {

        // The age groups
        ageLabel[lowestPopulationAgeGroup] = "0-";

        for (int icdGroup = 0; icdGroup < numberOfCancerGroups; icdGroup++) {
            if (icdLabel[icdGroup].substring(0 + sexNumber, 1 + sexNumber).equalsIgnoreCase("1")) {
                // The age groups

                double previousAgeGroupCases = 0;
                double previousAgeGroupPopulation = 0;
                double previousAgeGroupWstdPopulation = 0;

                double lastAgeGroupCases = 0;
                double lastAgeGroupPopulation = 0;
                double lastAgeGroupWstdPopulation = 0;

                for (int ageGroupNumber = 1; ageGroupNumber < unknownAgeGroupIndex; ageGroupNumber++) {
                    if (ageGroupNumber == 1) {
                        for (int ag = lowestIncidenceAgeGroup; ag < ageGroupNumber; ag++) {
                            previousAgeGroupCases += casesArray[icdGroup][sexNumber][ag];
                            previousAgeGroupPopulation += populationArray[sexNumber][ag];
                            previousAgeGroupWstdPopulation += standardPopulationArray[sexNumber][ag];
                        }
                    }
                    if (foundAgeGroups[ageGroupNumber] && ageGroupNumber < highestPopulationAgeGroup) {
                        casesPerHundredThousand[sexNumber][ageGroupNumber][icdGroup] = 100000
                                * (casesArray[icdGroup][sexNumber][ageGroupNumber] + previousAgeGroupCases)
                                / (populationArray[sexNumber][ageGroupNumber] + previousAgeGroupPopulation);

                        previousAgeGroupCases = 0;
                        previousAgeGroupPopulation = 0;
                        previousAgeGroupWstdPopulation = 0;

                    } else {
                        previousAgeGroupCases += casesArray[icdGroup][sexNumber][ageGroupNumber];
                        previousAgeGroupPopulation += populationArray[sexNumber][ageGroupNumber];
                        previousAgeGroupWstdPopulation += standardPopulationArray[sexNumber][ageGroupNumber];
                    }
                }
                // We calculate the "leftovers" from the last age group
                if (previousAgeGroupPopulation > 0) {
                    casesPerHundredThousand[sexNumber][highestPopulationAgeGroup][icdGroup] = 100000
                            * (previousAgeGroupCases) / (previousAgeGroupPopulation);

                }

                previousAgeGroupCases = 0;
                previousAgeGroupPopulation = 0;
                previousAgeGroupWstdPopulation = 0;

            }
        }
    }

    // ASR, vASR, MV, MI, DCO
    for (int sexNumber = 0; sexNumber < numberOfSexes; sexNumber++) {
        for (int icdGroup = 0; icdGroup < numberOfCancerGroups; icdGroup++) {

            double previousAgeGroupCases = 0;
            double previousAgeGroupPopulation = 0;
            double previousAgeGroupWstdPopulation = 0;

            double lastAgeGroupCases = 0;
            double lastAgeGroupPopulation = 0;
            double lastAgeGroupWstdPopulation = 0;

            totalCases[sexNumber][icdGroup] += casesArray[icdGroup][sexNumber][0];

            for (int ageGroupNumber = 1; ageGroupNumber < unknownAgeGroupIndex; ageGroupNumber++) {
                if (ageGroupNumber == 1) {
                    for (int ag = lowestIncidenceAgeGroup; ag < ageGroupNumber; ag++) {
                        previousAgeGroupCases += casesArray[icdGroup][sexNumber][ag];
                        previousAgeGroupPopulation += populationArray[sexNumber][ag];
                        previousAgeGroupWstdPopulation += standardPopulationArray[sexNumber][ag];
                    }
                }
                if (foundAgeGroups[ageGroupNumber] && ageGroupNumber < highestPopulationAgeGroup
                        && (previousAgeGroupPopulation + populationArray[sexNumber][ageGroupNumber] > 0)) {
                    double asr = calculateASR(
                            (previousAgeGroupCases + casesArray[icdGroup][sexNumber][ageGroupNumber]),
                            (previousAgeGroupPopulation + populationArray[sexNumber][ageGroupNumber]),
                            (previousAgeGroupWstdPopulation
                                    + standardPopulationArray[sexNumber][ageGroupNumber]));

                    previousAgeGroupCases = 0;
                    previousAgeGroupPopulation = 0;
                    previousAgeGroupWstdPopulation = 0;

                } else if (ageGroupNumber < highestPopulationAgeGroup) {
                    previousAgeGroupCases += casesArray[icdGroup][sexNumber][ageGroupNumber];
                    previousAgeGroupPopulation += populationArray[sexNumber][ageGroupNumber];
                    previousAgeGroupWstdPopulation += standardPopulationArray[sexNumber][ageGroupNumber];

                } else {
                    lastAgeGroupCases += casesArray[icdGroup][sexNumber][ageGroupNumber];
                    lastAgeGroupPopulation += populationArray[sexNumber][ageGroupNumber];
                    lastAgeGroupWstdPopulation += standardPopulationArray[sexNumber][ageGroupNumber];
                }

                totalCases[sexNumber][icdGroup] += casesArray[icdGroup][sexNumber][ageGroupNumber];
            }

            // We calculate the "leftovers" from the last age group
            if (lastAgeGroupPopulation > 0) {
                double asr = calculateASR(lastAgeGroupCases, lastAgeGroupPopulation,
                        lastAgeGroupWstdPopulation);

            }

            // and take the unknown age group into account
            totalCases[sexNumber][icdGroup] += casesArray[icdGroup][sexNumber][unknownAgeGroupIndex];

            if (totalCases[sexNumber][icdGroup] > 0) {

                /* We don't use confidence intervals so this was removed 16.07.07
                double[] asrlul = calculateASRluL(ASR[sex][icdGroup],
                variL[sex][icdGroup], wstdPop[allAgeGroupsIndex]);
                        
                ASRluL[sex][icdGroup][0] = asrlul[0];
                ASRluL[sex][icdGroup][1] = asrlul[1];
                 */
                // Cum. Rates
                if (highestPopulationAgeGroup > 13) {
                    for (int k = 1; k <= 13; k++) {
                        // cumRate64[sexNumber][icdGroup] += casesPerHundredThousand[sexNumber][k][icdGroup] * cumPop18[k] / 1000.0;
                    }
                }
                if (highestPopulationAgeGroup > 15) {
                    for (int k = 1; k <= 15; k++) {
                        // cumRate74[sexNumber][icdGroup] += casesPerHundredThousand[sexNumber][k][icdGroup] * cumPop18[k] / 1000.0;
                    }
                }

                /*                    if (!isSpecialized) {
                cumRate64[sex][allCancerGroupsIndex] += cumRate64[sex][icdGroup];
                cumRate74[sex][allCancerGroupsIndex] += cumRate74[sex][icdGroup];
                if (icdGroup!=skinCancerGroupIndex) {
                cumRate64[sex][allCancerGroupsIndex] += cumRate64[sex][icdGroup];
                cumRate74[sex][allCancerGroupsIndex] += cumRate74[sex][icdGroup];
                }
                }
                 */
            }
        }
    }

    // Adjust the age labels
    ageLabel[1] = "0-";
    ageLabel[highestPopulationAgeGroup] = ageLabel[highestPopulationAgeGroup].substring(0,
            ageLabel[highestPopulationAgeGroup].length() - 1) + "+";

    // Write it out
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(1);
    nf.setMinimumFractionDigits(1);

    Writer reportFileWriter;

    if (fileType.equals(FileTypes.csv)) {
        // write tab separated stuff here
        CSVPrinter csvOut;
        for (int sexNumber = 0; sexNumber < numberOfSexes - 1; sexNumber++) {
            try {
                String tabReportFileName = "";
                try {
                    tabReportFileName = reportFileName + sexLabel[sexNumber] + ".csv";
                    System.out.println(java.util.ResourceBundle.getBundle(
                            "canreg/client/analysis/resources/AgeSpecificCasesPerHundredThousandTableBuilder")
                            .getString("WRITING TO ") + tabReportFileName);
                    reportFileWriter = new OutputStreamWriter(new FileOutputStream(tabReportFileName), "UTF-8");
                } catch (IOException ioe) {
                    System.out.println(java.util.ResourceBundle.getBundle(
                            "canreg/client/analysis/resources/AgeSpecificCasesPerHundredThousandTableBuilder")
                            .getString("ERROR IN REPORTFILE: ") + tabReportFileName);
                    reportFileWriter = new OutputStreamWriter(System.out);
                }
                // reportStream = new PrintStream(tabReportFileName);
                // write the header line
                // reportStream = new PrintStream(tabReportFileName);
                // write the header line
                LinkedList<String> headers = new LinkedList<String>();
                headers.add("SITE");
                headers.add("ALL AGES");
                headers.add("AGE UNK");
                // add age groups

                for (int age = 1; age <= highestPopulationAgeGroup; age++) {
                    headers.add(ageLabel[age]);
                }

                // headers.add("CRUDE RATE");
                headers.add("(%)");
                //                    headers.add("CUM 0-64");
                //                    headers.add("CUM 0-74");
                //                    headers.add("ASR");
                headers.add("ICD (10th)");

                CSVFormat format = CSVFormat.DEFAULT.withDelimiter(',')
                        .withHeader(headers.toArray(new String[0]));

                csvOut = new CSVPrinter(reportFileWriter, format);

                LinkedList<String> line = new LinkedList<String>();

                // write the data
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        line.add(icdLabel[j].substring(3));
                        line.add(formatNumber(totalCases[sexNumber][j], 0));
                        line.add(formatNumber(casesArray[j][sexNumber][unknownAgeGroupIndex], 0));
                        for (int age = 1; age <= highestPopulationAgeGroup; age++) {
                            if (casesArray[j][sexNumber][age] > 0) {
                                line.add(formatNumber(casesArray[j][sexNumber][age], 0));
                            } else {
                                line.add("0");
                            }
                        }
                        // line.add(formatNumber(crudeRate[sexNumber][j], 2));
                        line.add(formatNumber(100 * totalCases[sexNumber][j]
                                / totalCases[sexNumber][allCancerGroupsButSkinIndex]));
                        // line.add(formatNumber(cumRate64[sexNumber][j], 2));
                        // line.add(formatNumber(cumRate74[sexNumber][j], 2));
                        // line.add(formatNumber(ASR[sexNumber][j]));
                        line.add(icd10GroupDescriptions[j]);
                        csvOut.printRecord(line);
                        line.clear();
                    }
                }

                try {
                    csvOut.flush();
                    csvOut.close();
                } catch (IOException ex) {
                    Logger.getLogger(AgeSpecificCasesPerHundredThousandTableBuilder.class.getName())
                            .log(Level.SEVERE, null, ex);
                }
                generatedFiles.add(tabReportFileName);
            } catch (IOException ex) {
                Logger.getLogger(AgeSpecificCasesTableBuilder.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } else {

        // Make PS-file
        for (int sexNumber = 0; sexNumber < numberOfSexes - 1; sexNumber++) {
            String psFileName = reportFileName + "-" + sexLabel[sexNumber] + ".ps";
            generatedFiles.add(psFileName);
            try {
                Writer fw = new OutputStreamWriter(new FileOutputStream(psFileName), "UTF-8");

                nf.setMaximumFractionDigits(1);
                nf.setMinimumFractionDigits(1);

                fw.write("/RLT {rlineto} def\n");
                fw.write("/LT {lineto} def\n");
                fw.write("/MT {moveto} def\n");
                fw.write("/SCF {scalefont} def\n");
                fw.write("/SF {setfont} def\n");
                fw.write("/SG {setgray} def\n");
                fw.write("/FF {findfont} def\n");
                fw.write("/SLW {setlinewidth} def\n");
                fw.write("/CP {closepath} def\n");
                fw.write("/Mainfont\n");
                fw.write("/Helvetica-Bold FF " + (int) (tableFontSize * 2 - 3) + " SCF def\n");
                fw.write("/Titlefont\n");
                fw.write("/Helvetica FF " + tableFontSize + " SCF def\n");
                fw.write("/Tablefont\n");
                fw.write("/" + font + " FF " + tableFontSize + " SCF def\n");
                fw.write("/ASRfont\n");
                fw.write("/" + font + "-Bold FF " + tableFontSize + " SCF def\n");
                fw.write("/ICDfont\n");
                fw.write("/" + font + "-Italic FF " + tableFontSize + " SCF def\n");
                fw.write("/ASRitalicsfont\n");
                fw.write("/" + font + "-Italic-Bold FF " + tableFontSize + " SCF def\n");
                fw.write("/col 735 def\n");
                fw.write("/RS {dup stringwidth pop col exch sub 0 rmoveto show} def\n");
                fw.write("/CS {dup stringwidth pop 810 exch sub 2 div 0 rmoveto show} def\n");
                fw.write("/nstr 1 string def\n");
                fw.write("/prtchar {nstr 0 3 -1 roll put nstr show} def\n");
                fw.write("newpath\n");
                fw.write("90 rotate -20 -570 translate\n"); //  Landscape
                fw.write("Mainfont SF\n");
                fw.write("0 535 MT (" + registryLabel + ") CS\n");
                fw.write("Titlefont SF\n");
                fw.write("0 525 MT (" + populationString + ") CS\n");
                fw.write("0 513 MT (" + tableLabel[0] + " - " + sexLabel[sexNumber] + ") CS\n");
                //                                                                                              draw the grey frame
                fw.write("0.85 SG 27 510 translate\n");
                fw.write("0 -5 MT 785 -5 LT 785 -27 LT 0 -27 LT  CP fill\n");
                fw.write("0 -510 translate 0.95 SG\n");
                double k = 475;

                for (int icd = 0; icd < numberOfCancerGroups; icd++) {
                    if ((icd + 1) < numberOfCancerGroups && icdLabel[icd + 1].charAt(sexNumber) == '1') {
                        int lines = (isLineBreak(icd));
                        if (lines > 0) {
                            k -= 2;
                            fw.write("0 " + (k - 2) + " MT 785 " + (k - 2) + " LT 785 "
                                    + (k - 2 - (lines * (tableFontSize))) + " LT 0 "
                                    + (k - 2 - (lines * (tableFontSize))) + " LT CP fill\n");
                        } else if (lines < 0) {
                            k -= 2;
                        }
                        k -= tableFontSize;
                    }
                }

                /*
                for (int j = 0; j < numberOfCancerGroups; j++) {
                if (icdLabel[j].charAt(sex) == '1') {
                        
                int lines = (isLineBreak(j));
                if (lines > 0) {
                k -= 2;
                        
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - lines * tableFontSize) + " LT 0 " + (k - lines * tableFontSize) +
                " LT CP fill\n");
                        
                } else if (lines > 0)
                k -= 2;
                k -= lines * tableFontSize;
                        
                        
                        
                        
                if (IsLineBreak(j)) {
                k -= 2;
                }
                //  draw the grey frames
                if (j == 8) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 35) + " LT 0 " + (k - 35) +
                " LT CP fill\n");
                } else if (j == 34) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 26) + " LT 0 " + (k - 26) +
                " LT CP fill\n");
                } else if (j == 16 || j == 22 || j == 40) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 18) + " LT 0 " + (k - 18) +
                " LT CP fill\n");
                } else if (j == 27) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 42) + " LT 0 " + (k - 42) +
                " LT CP fill\n");
                } else if (j == 47) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 34) + " LT 0 " + (k - 34) +
                " LT CP fill\n");
                } else if (j == 53) {
                fw.write(
                "0 " + (k + tableFontSize) + " MT 774 " + (k + tableFontSize) +
                " LT 774 " + (k - 12) + " LT 0 " + (k - 12) +
                " LT CP fill\n");
                }
                k -= (tableFontSize);
                }
                        
                }
                 */
                fw.write("0 SG\n");

                fw.write("ICDfont SF\n");
                fw.write(" 740 496 MT (ICD) show\n");
                fw.write(" 740 487 MT ((10th)) show\n");
                k = 475;
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        if (isLineBreak(j - 1) != 0) {
                            k -= 2;
                        }
                        if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                || j == bladderCancerGroupIndex || j == myelodysplasticSyndromesCancerGroupIndex
                                || j == myeloproliferativeDisordersCancerGroupIndex
                                || j == brainAndCentralNervousSystemCancerGroupIndex) {
                            fw.write("ICDfont SF\n");
                        } else {
                            fw.write("ICDfont SF\n");
                        }

                        fw.write("745 " + k + " MT (" + icd10GroupDescriptions[j] + ") show\n");
                        k -= (tableFontSize);
                    }
                }

                fw.write("/col col 20 sub def\n");
                fw.write("0 491 MT ((%)) RS\n");
                k = 475;
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        if (isLineBreak(j - 1) != 0) {
                            k -= 2;
                        }

                        if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                || j == bladderCancerGroupIndex || j == myelodysplasticSyndromesCancerGroupIndex
                                || j == myeloproliferativeDisordersCancerGroupIndex
                                || j == brainAndCentralNervousSystemCancerGroupIndex) {
                            fw.write("ICDfont SF\n");
                        } else {
                            fw.write("Tablefont SF\n");
                        }

                        if (j != allCancerGroupsIndex && allCancerGroupsButSkinIndex >= 0) {
                            fw.write(
                                    "0 " + k + " MT ("
                                            + formatNumber(100 * totalCases[sexNumber][j]
                                                    / totalCases[sexNumber][allCancerGroupsButSkinIndex])
                                            + ") RS\n");
                        }
                        k -= (tableFontSize);
                    }
                }

                fw.write("/col 119 def\n");
                fw.write("0 496 MT (ALL) RS\n");
                fw.write("0 487 MT (AGES) RS\n");
                k = 475;
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        if (isLineBreak(j - 1) != 0) {
                            k -= 2;
                        }
                        if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                || j == bladderCancerGroupIndex || j == myelodysplasticSyndromesCancerGroupIndex
                                || j == myeloproliferativeDisordersCancerGroupIndex
                                || j == brainAndCentralNervousSystemCancerGroupIndex) {
                            fw.write("ICDfont SF\n");
                        } else {
                            fw.write("Tablefont SF\n");
                        }

                        fw.write("0 " + k + " MT (" + formatNumber(totalCases[sexNumber][j], 0) + ") RS\n");
                        k -= (tableFontSize);
                    }
                }
                fw.write("/col col 20 add def\n");
                fw.write("0 496 MT (AGE) RS\n");
                fw.write("0 487 MT (UNK) RS\n");
                k = 475;
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        if (isLineBreak(j - 1) != 0) {
                            k -= 2;
                        }
                        if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                || j == bladderCancerGroupIndex || j == myelodysplasticSyndromesCancerGroupIndex
                                || j == myeloproliferativeDisordersCancerGroupIndex
                                || j == brainAndCentralNervousSystemCancerGroupIndex) {
                            fw.write("ICDfont SF\n");
                        } else {
                            fw.write("Tablefont SF\n");
                        }

                        fw.write("0 " + k + " MT ("
                                + formatNumber(casesArray[j][sexNumber][unknownAgeGroupIndex], 0) + ") RS\n");
                        k -= (tableFontSize);
                    }
                }

                if (highestPopulationAgeGroup == numberOfAgeGroups - 4) {
                    fw.write("/col 145 def\n");
                } else if (highestPopulationAgeGroup == numberOfAgeGroups - 5) {
                    fw.write("/col 176 def\n");
                } else if (highestPopulationAgeGroup == numberOfAgeGroups - 6) {
                    fw.write("/col 208 def\n");
                } else {
                    fw.write("/col 145 def\n");
                }

                for (int age = 1; age <= highestPopulationAgeGroup; age++) {
                    fw.write("/col col 26 add def\n");
                    fw.write("0 491 MT (" + ageLabel[age] + ") RS\n");
                    // fw.write("/col col 5 sub def\n");
                    k = 475;
                    for (int j = 0; j < numberOfCancerGroups; j++) {
                        if (icdLabel[j].charAt(sexNumber) == '1') {
                            if (isLineBreak(j - 1) != 0) {
                                k -= 2;
                            }

                            if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                    || j == bladderCancerGroupIndex
                                    || j == myelodysplasticSyndromesCancerGroupIndex
                                    || j == myeloproliferativeDisordersCancerGroupIndex
                                    || j == brainAndCentralNervousSystemCancerGroupIndex) {
                                fw.write("ICDfont SF\n");
                            } else {
                                fw.write("Tablefont SF\n");
                            }

                            if (casesArray[j][sexNumber][age] > 0) {
                                fw.write("0 " + k + " MT (" + formatNumber(casesArray[j][sexNumber][age], 0)
                                        + ") RS\n");
                            } else {
                                fw.write("0 " + k + " MT (    -  ) RS\n");
                            }
                            k -= (tableFontSize);
                        }
                    }
                }
                fw.write("3 492 MT ( S I T E) show\n");
                k = 475;
                for (int j = 0; j < numberOfCancerGroups; j++) {
                    if (icdLabel[j].charAt(sexNumber) == '1') {
                        if (isLineBreak(j - 1) != 0) {
                            k -= 2;
                        }
                        if (j == skinCancerGroupIndex || j == ovaryCancerGroupIndex
                                || j == bladderCancerGroupIndex || j == myelodysplasticSyndromesCancerGroupIndex
                                || j == myeloproliferativeDisordersCancerGroupIndex
                                || j == brainAndCentralNervousSystemCancerGroupIndex) {
                            fw.write("ICDfont SF\n");
                        } else {
                            fw.write("Tablefont SF\n");
                        }

                        fw.write("3 " + k + " MT (" + icdLabel[j].substring(3) + ") show\n");
                        k -= (tableFontSize);
                    }
                }
                if (showSeeNotesNote) {
                    fw.write("3 0 MT (" + notesString + ") show\n");
                }

                // Write the footer
                fw.write("0 0 MT (" + footerString + ") CS\n");

                fw.write("showpage\n");
                System.out.println("Wrote " + psFileName + ".");
                fw.close();
            } catch (IOException ioe) {
                System.out.println(ioe);
            }
        }
    }

    if (fileType == FileTypes.pdf) {
        LinkedList<String> newlyGeneratedFiles = new LinkedList<String>();
        for (String fileN : generatedFiles) {
            PsToPdfConverter pstopdf = new PsToPdfConverter(gspath);
            newlyGeneratedFiles.add(pstopdf.convert(fileN));
            // delete the ps file
            File file = new File(fileN);
            file.delete();
        }
        generatedFiles = newlyGeneratedFiles;
    }

    System.out.println("Fini!");

    return generatedFiles;
}