1
/*******************************************************************************
2
* Copyright (c) 2011, 2013 Ericsson
4
* All rights reserved. This program and the accompanying materials are
5
* made available under the terms of the Eclipse Public License v1.0 which
6
* accompanies this distribution, and is available at
7
* http://www.eclipse.org/legal/epl-v10.html
10
* Vincent Perot - Add percentages to the label provider
11
*******************************************************************************/
13
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
15
import java.text.NumberFormat;
16
import java.util.Locale;
18
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider.StatsColumn;
21
* Class that format data for cells in the statistics view.
23
* @author Vincent Perot
26
public final class TmfStatisticsFormatter {
29
* Formatter for the column data
31
private static final NumberFormat FORMATTER = NumberFormat.getNumberInstance(Locale.getDefault());
33
TmfStatisticsFormatter() {
34
// Nothing to construct.
38
* Generate the string for display in a cell.
43
* Configuration between total and partial.
44
* @return The formatted string ready for display.
46
public static String toColumnData(TmfStatisticsTreeNode node, StatsColumn config) {
53
eventValue = node.getValues().getTotal();
57
eventValue = node.getValues().getPartial();
60
// Other values are illegal.
63
throw new IllegalArgumentException();
66
return FORMATTER.format(eventValue);
70
* Format the percentage according to user settings.
73
* the percentage to format
74
* @return The formated percentage as a string.
76
public static String toPercentageText(double percentage) {
78
// The cast to long is needed because the formatter cannot truncate the number.
79
double truncPercentage = ((long) (1000.0 * percentage)) / 10.0;
81
String percentageString = String.format("%s%s%s", " ", FORMATTER.format(truncPercentage), " % "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
82
return percentageString;
b'\\ No newline at end of file'