Example usage for java.text NumberFormat getPercentInstance

List of usage examples for java.text NumberFormat getPercentInstance

Introduction

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

Prototype

public static NumberFormat getPercentInstance(Locale inLocale) 

Source Link

Document

Returns a percentage format for the specified locale.

Usage

From source file:com.ibk.ltw.domain.Product.java

public String getVatAsText() {
    BigDecimal vatInPercent = new BigDecimal(getVatInPerThousand()).movePointLeft(3);
    NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.US);
    percentFormat.setMaximumFractionDigits(1);
    percentFormat.setRoundingMode(RoundingMode.HALF_DOWN);
    return percentFormat.format(vatInPercent);
}

From source file:org.chromium.chrome.browser.download.SystemDownloadNotifier.java

@Override
public void notifyDownloadProgress(DownloadInfo downloadInfo, long startTime) {
    // getPercentCompleted returns -1 if download time is indeterminate.
    boolean indeterminate = downloadInfo.getPercentCompleted() == -1;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mApplicationContext)
            .setContentTitle(downloadInfo.getFileName()).setSmallIcon(android.R.drawable.stat_sys_download)
            .setOngoing(true).setLocalOnly(true).setAutoCancel(true)
            .setProgress(100, downloadInfo.getPercentCompleted(), indeterminate);

    if (!indeterminate) {
        NumberFormat formatter = NumberFormat.getPercentInstance(Locale.getDefault());
        String percentText = formatter.format(downloadInfo.getPercentCompleted() / 100.0);
        String duration = LocalizationUtils.getDurationString(downloadInfo.getTimeRemainingInMillis());
        builder.setContentText(duration).setContentInfo(percentText);
    }/*from w  ww  .j  av a  2  s .  c o  m*/
    if (startTime > 0)
        builder.setWhen(startTime);

    updateNotification(downloadInfo.getDownloadId(), builder.build());
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.CloverTimeChartStrategy.java

public XYItemLabelGenerator getLabelGenerator() {
    StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, this.timePeriod.getDateFormat(),
            NumberFormat.getPercentInstance(Locale.getDefault()));
    return labelgenerator;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *//*from  w  w w  .ja va 2  s.c om*/
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:org.optaplanner.benchmark.impl.statistic.improvingsteppercentage.ImprovingStepPercentageProblemStatistic.java

private XYPlot createPlot(Class<? extends Move> moveClass) {
    Locale locale = problemBenchmark.getPlannerBenchmark().getBenchmarkReport().getLocale();
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Percentage that improve the score");
    yAxis.setNumberFormatOverride(NumberFormat.getPercentInstance(locale));
    yAxis.setRange(0.0, 1.0);//from w  w w.j  a  v  a  2  s.  c  o  m
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}

From source file:richtercloud.document.scanner.gui.OCRPanel.java

/**
 * Creates new form OCRResultPanel//from  w  ww .  j  a va2s.  co m
 * @param reflectionFormPanelMap A map with references to the
 * {@link ReflectionFormPanel} for each entity class which is manipulated by
 * the context menu items
 */
public OCRPanel(Set<Class<?>> entityClasses, Map<Class<?>, ReflectionFormPanel<?>> reflectionFormPanelMap,
        Map<Class<? extends JComponent>, ValueSetter<?, ?>> valueSetterMapping, EntityManager entityManager,
        MessageHandler messageHandler, ReflectionFormBuilder reflectionFormBuilder,
        DocumentScannerConf documentScannerConf) {
    this.initComponents();
    if (messageHandler == null) {
        throw new IllegalArgumentException("messageHandler mustn't be null");
    }
    this.messageHandler = messageHandler;
    if (documentScannerConf == null) {
        throw new IllegalArgumentException("documentScannerConf mustn't be " + "null");
    }
    this.documentScannerConf = documentScannerConf;
    List<Class<?>> entityClassesSort = EntityPanel.sortEntityClasses(entityClasses);
    for (Class<?> entityClass : entityClassesSort) {
        ReflectionFormPanel<?> reflectionFormPanel = reflectionFormPanelMap.get(entityClass);
        if (reflectionFormPanel == null) {
            throw new IllegalArgumentException(
                    String.format("entityClass %s has no %s mapped in reflectionFormPanelMap", entityClass,
                            ReflectionFormPanel.class));
        }
        String className;
        ClassInfo classInfo = entityClass.getAnnotation(ClassInfo.class);
        if (classInfo != null) {
            className = classInfo.name();
        } else {
            className = entityClass.getSimpleName();
        }
        JMenu entityClassMenu = new JMenu(className);
        List<Field> relevantFields = reflectionFormBuilder.getFieldRetriever()
                .retrieveRelevantFields(entityClass);
        for (Field relevantField : relevantFields) {
            String fieldName;
            FieldInfo fieldInfo = relevantField.getAnnotation(FieldInfo.class);
            if (fieldInfo != null) {
                fieldName = fieldInfo.name();
            } else {
                fieldName = relevantField.getName();
            }
            JMenuItem relevantFieldMenuItem = new JMenuItem(fieldName);
            relevantFieldMenuItem.addActionListener(
                    new FieldActionListener(reflectionFormPanel, relevantField, valueSetterMapping));
            entityClassMenu.add(relevantFieldMenuItem);
        }
        this.oCRResultPopupPasteIntoMenu.add(entityClassMenu);
    }
    Map<String, Pair<NumberFormat, Set<Locale>>> numberFormats = new HashMap<>();
    Map<String, Pair<NumberFormat, Set<Locale>>> percentFormats = new HashMap<>();
    Map<String, Pair<NumberFormat, Set<Locale>>> currencyFormats = new HashMap<>();
    Iterator<Locale> localeIterator = new ArrayList<>(Arrays.asList(Locale.getAvailableLocales())).iterator();
    Locale firstLocale = localeIterator.next();
    String numberString = NumberFormat.getNumberInstance(firstLocale).format(FORMAT_VALUE);
    String percentString = NumberFormat.getPercentInstance(firstLocale).format(FORMAT_VALUE);
    String currencyString = NumberFormat.getCurrencyInstance(firstLocale).format(FORMAT_VALUE);
    numberFormats.put(numberString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getNumberInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    percentFormats.put(percentString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getPercentInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    currencyFormats.put(currencyString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getCurrencyInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    while (localeIterator.hasNext()) {
        Locale locale = localeIterator.next();
        numberString = NumberFormat.getNumberInstance(locale).format(FORMAT_VALUE);
        percentString = NumberFormat.getPercentInstance(locale).format(FORMAT_VALUE);
        currencyString = NumberFormat.getCurrencyInstance(locale).format(FORMAT_VALUE);
        Pair<NumberFormat, Set<Locale>> numberFormatsPair = numberFormats.get(numberString);
        if (numberFormatsPair == null) {
            numberFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getNumberInstance(locale), new HashSet<Locale>());
            numberFormats.put(numberString, numberFormatsPair);
        }
        Set<Locale> numberFormatsLocales = numberFormatsPair.getValue();
        numberFormatsLocales.add(locale);
        Pair<NumberFormat, Set<Locale>> percentFormatsPair = percentFormats.get(percentString);
        if (percentFormatsPair == null) {
            percentFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getPercentInstance(locale), new HashSet<Locale>());
            percentFormats.put(percentString, percentFormatsPair);
        }
        Set<Locale> percentFormatsLocales = percentFormatsPair.getValue();
        percentFormatsLocales.add(locale);
        Pair<NumberFormat, Set<Locale>> currencyFormatsPair = currencyFormats.get(currencyString);
        if (currencyFormatsPair == null) {
            currencyFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getCurrencyInstance(locale), new HashSet<Locale>());
            currencyFormats.put(currencyString, currencyFormatsPair);
        }
        Set<Locale> currencyFormatsLocales = currencyFormatsPair.getValue();
        currencyFormatsLocales.add(locale);
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> numberFormat : numberFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(numberFormat.getValue().getKey());
        numberFormatPopup.add(menuItem);
        numberFormatPopupButtonGroup.add(menuItem);
        if (numberFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> percentFormat : percentFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(percentFormat.getValue().getKey());
        percentFormatPopup.add(menuItem);
        percentFormatPopupButtonGroup.add(menuItem);
        if (percentFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> currencyFormat : currencyFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(currencyFormat.getValue().getKey());
        currencyFormatPopup.add(menuItem);
        currencyFormatPopupButtonGroup.add(menuItem);
        if (currencyFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.RadarChartExpression.java

private void initializeGrid(final DefaultCategoryDataset defaultDataset) {

    if (gridintervall < 0) {
        final double gridIntervalIncrement = -gridintervall;
        if ((100.0 / gridIntervalIncrement) > 5000) {
            return;
        }/*from  www  .j  av  a  2s. c  om*/

        //insert the gridlines (fake data sets)
        double gridline = gridIntervalIncrement;
        final int columns = defaultDataset.getColumnCount();
        final double maxdata = computeMaxValue(defaultDataset);

        final NumberFormat format = NumberFormat
                .getPercentInstance(getRuntime().getResourceBundleFactory().getLocale());
        while (gridline <= 100) {
            final double gridScaled = maxdata * gridline / 100.0;
            final String gridLineText = format.format(gridline / 100.0);
            final GridCategoryItem rowKey = new GridCategoryItem(gridLineText);
            for (int i = 0; i < columns; i++) {
                defaultDataset.addValue(gridScaled, rowKey, defaultDataset.getColumnKey(i));
            }
            gridline = gridline + gridIntervalIncrement;
        }
    } else if (gridintervall > 0) {
        final int columns = defaultDataset.getColumnCount();
        final double maxdata = computeMaxValue(defaultDataset);
        final double gridIntervalIncrement = gridintervall;
        if ((maxdata / gridIntervalIncrement) > 5000) {
            return;
        }

        final NumberFormat format = NumberFormat
                .getNumberInstance(getRuntime().getResourceBundleFactory().getLocale());
        double gridline = 0;
        while (gridline < maxdata) {
            gridline = gridline + gridIntervalIncrement;
            final String gridLineText = format.format(gridline);
            final GridCategoryItem rowKey = new GridCategoryItem(gridLineText);
            for (int i = 0; i < columns; i++) {
                defaultDataset.addValue(gridline, rowKey, defaultDataset.getColumnKey(i));
            }
        }

    }
}

From source file:org.apache.cocoon.template.instruction.FormatNumber.java

private NumberFormat createFormatter(Locale loc, String type) throws Exception {
    NumberFormat formatter = null;
    if ((type == null) || NUMBER.equalsIgnoreCase(type)) {
        formatter = NumberFormat.getNumberInstance(loc);
    } else if (CURRENCY.equalsIgnoreCase(type)) {
        formatter = NumberFormat.getCurrencyInstance(loc);
    } else if (PERCENT.equalsIgnoreCase(type)) {
        formatter = NumberFormat.getPercentInstance(loc);
    } else {//from www.j a  va2  s  .  c o  m
        throw new IllegalArgumentException(
                "Invalid type: \"" + type + "\": should be \"number\" or \"currency\" or \"percent\"");
    }
    return formatter;
}

From source file:org.sakaiproject.poll.tool.producers.ResultsProducer.java

public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) {

    PollViewParameters ecvp = (PollViewParameters) viewparams;

    String strId = ecvp.id;/*from  w  w w .  ja  v a  2 s  . co  m*/
    LOG.debug("got id of " + strId);
    Poll poll = pollListManager.getPollById(Long.valueOf(strId));

    if (!pollListManager.isAllowedViewResults(poll, externalLogic.getCurrentUserId())) {
        tml.addMessage(
                new TargettedMessage("poll.noviewresult", new Object[] {}, TargettedMessage.SEVERITY_ERROR));
        return;

    }

    String locale = localegetter.get().toString();
    Map<String, String> langMap = new HashMap<String, String>();
    langMap.put("lang", locale);
    langMap.put("xml:lang", locale);

    UIOutput.make(tofill, "polls-html", null).decorate(new UIFreeAttributeDecorator(langMap));

    //get the number of votes
    int voters = pollVoteManager.getDisctinctVotersForPoll(poll);
    //Object[] args = new Object[] { Integer.valueOf(voters).toString()};
    if (poll.getMaxOptions() > 1)
        UIOutput.make(tofill, "poll-size",
                messageLocator.getMessage("results_poll_size", Integer.valueOf(voters).toString()));

    LOG.debug(voters + " have voted on this poll");

    UIOutput.make(tofill, "question", poll.getText());
    LOG.debug("got poll " + poll.getText());
    List<Option> pollOptions = poll.getPollOptions();

    LOG.debug("got a list of " + pollOptions.size() + " options");
    //Append an option for no votes
    if (poll.getMinOptions() == 0) {
        Option noVote = new Option(Long.valueOf(0));
        noVote.setOptionText(messageLocator.getMessage("result_novote"));
        noVote.setPollId(poll.getPollId());
        pollOptions.add(noVote);
    }

    List<Vote> votes = pollVoteManager.getAllVotesForPoll(poll);
    int totalVotes = votes.size();
    LOG.debug("got " + totalVotes + " votes");
    List<CollatedVote> collation = new ArrayList<CollatedVote>();

    for (int i = 0; i < pollOptions.size(); i++) {
        CollatedVote collatedVote = new CollatedVote();
        Option option = (Option) pollOptions.get(i);
        LOG.debug("collating option " + option.getOptionId());
        collatedVote.setoptionId(option.getOptionId());
        collatedVote.setOptionText(option.getOptionText());
        collatedVote.setDeleted(option.getDeleted());
        for (int q = 0; q < votes.size(); q++) {
            Vote vote = (Vote) votes.get(q);
            if (vote.getPollOption().equals(option.getOptionId())) {
                LOG.debug("got a vote for option " + option.getOptionId());
                collatedVote.incrementVotes();

            }

        }
        collation.add(collatedVote);

    }

    UILink title = UILink.make(tofill, "answers-title", messageLocator.getMessage("results_answers_title"),
            "#");
    title.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_title_tooltip")));
    UILink count = UILink.make(tofill, "answers-count", messageLocator.getMessage("results_answers_numbering"),
            "#");
    count.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_numbering_tooltip")));
    UILink avotes = UILink.make(tofill, "answers-votes", messageLocator.getMessage("results_answers_votes"),
            "#");
    avotes.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_votes_tooltip")));
    UILink apercent = UILink.make(tofill, "answers-percent", "%", "#");
    apercent.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_percent_tooltip")));
    UIBranchContainer adefault = UIBranchContainer.make(tofill, "answers-default:");
    adefault.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_default_tooltip")));

    //output the votes
    Map<Long, String> chartTextData = new LinkedHashMap<Long, String>();
    Map<Long, String> chartValueData = new LinkedHashMap<Long, String>();
    NumberFormat nf = NumberFormat.getPercentInstance(localegetter.get());
    for (int i = 0; i < collation.size(); i++) {
        CollatedVote cv = (CollatedVote) collation.get(i);
        UIBranchContainer resultRow = UIBranchContainer.make(tofill, "answer-row:",
                cv.getoptionId().toString());

        String optionText = cv.getOptionText();
        if (cv.getDeleted()) {
            optionText += messageLocator.getMessage("deleted_option_tag_html");
        }

        UIVerbatim.make(resultRow, "answer-option", optionText);
        UIOutput.make(resultRow, "answer-count", Integer.valueOf(i + 1).toString());
        UIOutput.make(resultRow, "answer-numVotes", Long.valueOf(cv.getVotes()).toString());

        LOG.debug("about to do the calc: (" + cv.getVotes() + "/" + totalVotes + ")*100");
        double percent = (double) 0;
        if (totalVotes > 0 && poll.getMaxOptions() == 1)
            percent = ((double) cv.getVotes() / (double) totalVotes); //*(double)100;
        else if (totalVotes > 0 && poll.getMaxOptions() > 1)
            percent = ((double) cv.getVotes() / (double) voters); //*(double)100;
        else
            percent = (double) 0;

        //setup chartdata, use percentages for the values
        //also, remove the &nbsp; from the beginning of the label, POLL-139
        //we use the same number formatter which adds a % to the end of the data, remove that as well.
        chartTextData.put(cv.getoptionId(), StringUtils.removeStart(optionText, "&nbsp;"));
        chartValueData.put(cv.getoptionId(), StringUtils.removeEnd(nf.format(percent), "%"));

        LOG.debug("result is " + percent);
        UIOutput.make(resultRow, "answer-percVotes", nf.format(percent));

    }
    UIOutput.make(tofill, "votes-total", Integer.valueOf(totalVotes).toString());
    if (totalVotes > 0 && poll.getMaxOptions() == 1)
        UIOutput.make(tofill, "total-percent", "100%");

    /** CHART **/
    if (externalLogic.isResultsChartEnabled() && totalVotes > 0) {

        //chart selector label
        UIOutput.make(tofill, "chart-type-label", messageLocator.getMessage("results_chart_type"));

        //chart selector - no binding, JQuery handles it.
        String[] chartTypes = new String[] { "bar", "pie" };
        UISelect min = UISelect.make(tofill, "chart-type", chartTypes, "null", "bar");

        //setup bar chart
        //data separator is |
        StringBuilder sbBar = new StringBuilder();
        sbBar.append("https://chart.googleapis.com/chart?");
        sbBar.append("cht=bvg&");
        sbBar.append("chxt=y&");
        sbBar.append("chs=500x400&");
        sbBar.append("chd=t:" + StringUtils.join(chartValueData.values(), '|') + "&");
        sbBar.append("chdl=" + StringUtils.join(chartTextData.values(), '|') + "&");
        sbBar.append(
                "chco=FF0000,00FF00,0000FF,FFFF00,00FFFF,FF00FF,C0C0C0,800080,000080,808000,800000,FF00FF,008080,800000,008000");

        UILink barChart = UILink.make(tofill, "poll-chart-bar", sbBar.toString());
        LOG.debug("bar chart URL:" + sbBar.toString());

        //setup pie chart
        //data separator is ,
        StringBuilder sbPie = new StringBuilder();
        sbPie.append("https://chart.googleapis.com/chart?");
        sbPie.append("cht=p&");
        sbPie.append("chs=500x400&");
        sbPie.append("chd=t:" + StringUtils.join(chartValueData.values(), ',') + "&");
        sbPie.append("chl=" + StringUtils.join(chartTextData.values(), '|') + "&");
        sbPie.append(
                "chco=FF0000,00FF00,0000FF,FFFF00,00FFFF,FF00FF,C0C0C0,800080,000080,808000,800000,FF00FF,008080,800000,008000");

        UILink pieChart = UILink.make(tofill, "poll-chart-pie", sbPie.toString());
        LOG.debug("pie chart URL:" + sbPie.toString());

        //refresh link
        UIInternalLink resultsLink = UIInternalLink.make(tofill, "results-refresh",
                messageLocator.getMessage("action_refresh_results"),
                new PollViewParameters(ResultsProducer.VIEW_ID, poll.getPollId().toString()));
        resultsLink.decorators = new DecoratorList(new UITooltipDecorator(
                messageLocator.getMessage("action_refresh_results") + ":" + poll.getText()));
    }

    //the cancel button
    UIForm form = UIForm.make(tofill, "actform");
    UICommand cancel = UICommand.make(form, "cancel", messageLocator.getMessage("results_cancel"),
            "#{pollToolBean.cancel}");
    cancel.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_cancel_tooltip")));

    externalLogic.postEvent("poll.viewResult",
            "poll/site/" + externalLogic.getCurrentLocationId() + "/poll/" + poll.getPollId(), false);

}

From source file:net.sf.morph.transform.converters.TextToNumberConverter.java

/**
 * {@inheritDoc}/*from  w ww  .j a va 2s  .c  o m*/
 */
protected Object convertImpl(Class destinationClass, Object source, Locale locale) throws Exception {

    if (ObjectUtils.isEmpty(source)) {
        return null;
    }
    // convert the source to a String
    String string = (String) getTextConverter().convert(String.class, source, locale);

    //         // if a custom numberFormat has been specified, ues that for the
    //         // conversion
    //         if (numberFormat != null) {
    //            Number number;
    //            synchronized (numberFormat) {
    //               number = numberFormat.parse(string);
    //            }
    //
    //            // convert the number to the destination class requested
    //            return getNumberConverter().convert(destinationClass, number,
    //               locale);
    //         }

    StringBuffer charactersToParse =
            // remove characters that should be ignored, such as currency symbols
            // when currency handling is set to CURRENCY_IGNORE
            removeIgnoredCharacters(string, locale);

    // keep track of whether the conversion result needs to be negated
    // before it is returned
    boolean negate = handleParenthesesNegation(charactersToParse, locale);
    negate = negate || handleNegativeSignNegation(charactersToParse, locale);

    NumberFormat format = null;
    ParsePosition position = null;
    Number number = null;
    Object returnVal = null;
    String stringToParse = charactersToParse.toString();

    // could not get this to work for some reason
    //         // try to do the conversion assuming the source is a currency value
    //         format = NumberFormat.getCurrencyInstance(locale);
    //         position = new ParsePosition(0);
    //         number = format.parse(stringWithoutIgnoredSymbolsStr, position);
    //         if (isParseSuccessful(stringWithoutIgnoredSymbolsStr, position)) {
    //            // convert the number to the destination class requested
    //            returnVal = getNumberConverter().convert(destinationClass, number,
    //               locale);
    //            if (logger.isDebugEnabled()) {
    //               logger.debug("Successfully parsed '" + source + "' as a currency value of " + returnVal);
    //            }
    //            return returnVal;
    //         }
    //         else {
    //            if (logger.isDebugEnabled()) {
    //               logger.debug("Could not perform conversion of '" + source + "' by treating the source as a currency value");
    //            }
    //         }

    // try to do the conversion to decimal assuming the source is a
    // percentage
    if (getPercentageHandling() == PERCENTAGE_CONVERT_TO_DECIMAL) {
        format = NumberFormat.getPercentInstance(locale);
        position = new ParsePosition(0);
        number = format.parse(stringToParse, position);
        if (isParseSuccessful(stringToParse, position)) {
            // negate the number if needed
            returnVal = negateIfNecessary(number, negate, locale);
            // convert the number to the destination class requested
            returnVal = getNumberConverter().convert(destinationClass, returnVal, locale);
            if (logger.isDebugEnabled()) {
                logger.debug("Successfully parsed '" + source + "' as a percentage with value " + returnVal);
            }
            return returnVal;
        }
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Could not perform conversion of '" + source + "' by treating the source as a percentage");
        }
    }

    // try to do the conversion as a regular number
    format = NumberFormat.getInstance(locale);
    position = new ParsePosition(0);
    number = format.parse(stringToParse, position);
    if (isParseSuccessful(stringToParse, position)) {
        // negate the number if needed
        returnVal = negateIfNecessary(number, negate, locale);
        // convert the number to the destination class requested
        returnVal = getNumberConverter().convert(destinationClass, returnVal, locale);
        if (logger.isDebugEnabled()) {
            logger.debug("Successfully parsed '" + source + "' as a number or currency value of " + returnVal);
        }
        return returnVal;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Could not perform conversion of '" + source
                + "' by treating the source as a regular number or currency value");
    }

    //         // if the first character of the string is a currency symbol
    //         if (Character.getType(stringWithoutIgnoredSymbolsStr.charAt(0)) == Character.CURRENCY_SYMBOL) {
    //            // try doing the conversion as a regular number by stripping off the first character
    //            format = NumberFormat.getInstance(locale);
    //            position = new ParsePosition(1);
    //            number = format.parse(stringWithoutIgnoredSymbolsStr, position);
    //            if (isParseSuccessful(stringWithoutIgnoredSymbolsStr, position)) {
    //               // convert the number to the destination class requested
    //               return getNumberConverter().convert(destinationClass, number,
    //                  locale);
    //            }
    //            if (logger.isDebugEnabled()) {
    //               logger.debug("Could not perform conversion of '" + source + "' by stripping the first character and treating as a normal number");
    //            }
    //         }

    throw new TransformationException(destinationClass, source);
}