List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat
public static NumberFormat getFormat(String pattern)
NumberFormat
instance for the default locale using the specified pattern and the default currencyCode. From source file:org.rhq.coregui.client.bundle.tree.BundleTreeDataSource.java
License:Open Source License
private ListGridRecord copyValuesForKnownBundle(Object from, Integer bundleGroupId, Integer bundleId) { String parentID;/*from w ww. j av a 2 s. c o m*/ TreeNode node = new TreeNode(); String sortValue = ""; if (from instanceof BundleGroup) { BundleGroup bundleGroup = (BundleGroup) from; node.setIsFolder(true); node.setIcon("subsystems/bundle/BundleGroup_16.png"); node.setID(String.valueOf(bundleGroup.getId())); node.setName(StringUtility.escapeHtml(bundleGroup.getName())); if (bundleGroup.getId() == 0) { node.setEnabled(false); sortValue = "\uFFFDZZZZ"; // always show this as the last folder node in the tree } else { sortValue = bundleGroup.getName(); } } else if (from instanceof Bundle) { Bundle bundle = (Bundle) from; node.setIsFolder(true); node.setIcon("subsystems/bundle/Bundle_16.png"); node.setID(String.valueOf(bundleGroupId) + "_" + bundle.getId()); node.setParentID(String.valueOf(bundleGroupId)); node.setName(StringUtility.escapeHtml(bundle.getName())); sortValue = bundle.getName(); } else if (from instanceof BundleVersion) { BundleVersion version = (BundleVersion) from; node.setIsFolder(false); node.setIcon("subsystems/bundle/BundleVersion_16.png"); parentID = bundleGroupId.toString() + "_" + version.getBundle().getId() + "_versions"; node.setParentID(parentID); node.setID(parentID + '_' + version.getId()); node.setName(version.getVersion()); sortValue = NumberFormat.getFormat("000000").format(version.getVersionOrder()); } else if (from instanceof BundleDeployment) { BundleDeployment deployment = (BundleDeployment) from; node.setIsFolder(false); node.setIcon("subsystems/bundle/BundleDeployment_16.png"); parentID = bundleGroupId.toString() + "_" + bundleId + "_destinations_" + deployment.getDestination().getId(); node.setParentID(parentID); node.setID(bundleGroupId.toString() + "_" + bundleId + "_deployments_" + deployment.getId()); String name = StringUtility.escapeHtml(deployment.getName()); if (deployment.isLive()) { node.setName("<span style=\"color: green; font-weight: bold\">(live)</span> " + name); } else { node.setName(name); } sortValue = deployment.getName(); } else if (from instanceof BundleDestination) { BundleDestination destination = (BundleDestination) from; node.setIsFolder(true); node.setIcon("subsystems/bundle/BundleDestination_16.png"); parentID = bundleGroupId.toString() + "_" + destination.getBundle().getId() + "_destinations"; node.setParentID(parentID); node.setID(parentID + '_' + destination.getId()); node.setName(StringUtility.escapeHtml(destination.getName())); sortValue = destination.getName(); } node.setAttribute(FIELD_SORT_VALUE, sortValue.toLowerCase()); return node; }
From source file:org.rhq.coregui.client.inventory.groups.detail.ResourceGroupTreeView.java
License:Open Source License
private ResourceGroupEnhancedTreeNode createClusterGroupNode(ClusterKey parentKey, ResourceType type, ClusterFlyweight child) {//from ww w. ja v a 2s . c o m // This node represents one type of resource that has 1 or more individual resources as members in the group. // It will be associated with both a resource type and a cluster key. // If an autoCluster contains disparate resource names the server returns only "..." because it doesn't // know what to name the node. This typically happens if the cluster group (i.e. root group) members are // themselves disparate. In general this is not the case, because recursive compat groups are typically // used specifically for groups of logically equivalent resources, like cloned AS instances. String childName = child.getName(); if ("...".equals(childName)) { childName = MSG.group_tree_groupOfResourceType(type.getName()); } ResourceGroupEnhancedTreeNode node = new ResourceGroupEnhancedTreeNode(childName); ClusterKeyFlyweight keyFlyweight = child.getClusterKey(); ClusterKey key = new ClusterKey(parentKey, keyFlyweight.getResourceTypeId(), keyFlyweight.getResourceKey()); String id = key.getKey(); String parentId = parentKey.getKey(); node.setID(id); node.setParentID(parentId); node.setClusterKey(key); node.setResourceType(type); node.setIsFolder(!child.getChildren().isEmpty()); int memberCount = child.getMembers(); int clusterSize = child.getClusterSize(); if (memberCount < clusterSize) { // it appears one or more individual group members doesn't have a resource with the given cluster key // label the tree node so the user knows this cluster node is not representative of the entire group membership double percentage = (double) memberCount / (double) clusterSize; String percentageStr = NumberFormat.getFormat("0%").format(percentage); String title = childName + " <span style=\"color: red; font-style: italic\">(" + percentageStr + ")</span>"; node.setTitle(title); // "1 out of 2 group members have "foo" child resources" node.setTooltip(MSG.group_tree_partialClusterTooltip(String.valueOf(memberCount), String.valueOf(clusterSize), childName)); } return node; }
From source file:org.rhq.coregui.client.util.MeasurementConverterClient.java
License:Open Source License
private static NumberFormat getDefaultNumberFormat() { NumberFormat nf = NumberFormat.getFormat("0.0"); return nf; }
From source file:org.rhq.coregui.client.util.MeasurementConverterClient.java
License:Open Source License
/** * Formats the given array of double values: determines the necessary precision such that when formatted, they are * distinct and reasonable to look at. For example, for values { 1.45 1.46 1.47 1.48 1.49 } the desired precision is * 2 - less precision loses significant digits, and more precision provides no added benefit. Max precision is * bounded for presentation considerations. * * @param values the values to be formatted * @param targetUnits the target units for the values * @param bestFit whether or not to use a normalized scale for the family of units * * @return the formatted values// ww w .jav a2 s . c o m */ public static String[] formatToSignificantPrecision(double[] values, MeasurementUnits targetUnits, boolean bestFit) { if ((null == values) || (values.length == 0)) { return null; } MeasurementUnits originalUnits = targetUnits; /* * in the overwhelming majority of cases, you're going to want to apply a bestFit * to the passed data, but it's not required; it's perfectly possible to allow a * list of doubles to be formatted without being fit, in which case the targetUnits * will be part of the formatted display for each result element */ if (bestFit) { // find bestFit units by taking the average Double average = 0.0; for (int i = 0, sz = values.length; i < sz; i++) { /* * adding fractional amount iterative leads to greater * error, but prevents overflow on large data sets */ average += (values[i] / sz); } MeasurementNumericValueAndUnits fittedAverage = fit(average, targetUnits); //noinspection UnnecessaryLocalVariable MeasurementUnits fittedUnits = fittedAverage.getUnits(); /* * and change the local reference to targetUnits, so that the same logic * can be used both for the bestFit and non-bestFit computations */ targetUnits = fittedUnits; } Set<String> existingStrings; // technically this *is* unused because int precisionDigits = 0; boolean scaleWithMorePrecision = true; String[] results = new String[values.length]; NumberFormat nf = getDefaultNumberFormat(); /* * we scale at most to MAX_PRECISION_DIGITS to allow for presentation limits * * increase the maxPrecisionDigits in the while condition * itself to ensure it gets done for every loop */ while (scaleWithMorePrecision && (++precisionDigits <= MAX_PRECISION_DIGITS)) { /* * make the assumption that we no longer need to scale beyond this iteration */ scaleWithMorePrecision = false; /* * we need to record the uniquely formatted values so we can determine */ existingStrings = new HashSet<String>(); nf = NumberFormat.getFormat(getFormat(0, precisionDigits)); Double[] scaledValues = new Double[values.length]; for (int i = 0; i < scaledValues.length; i++) { /* * For relative units apply the scale now, prior to the nf.format(), since we are not using format( Double...). * Otherwise, apply standard multi-unit scaling. */ if (MeasurementUnits.Family.RELATIVE == originalUnits.getFamily()) { scaledValues[i] = MeasurementUnits.scaleUp(values[i], originalUnits); } else { scaledValues[i] = scale(new MeasurementNumericValueAndUnits(values[i], originalUnits), targetUnits); } } for (int i = 0; i < results.length; i++) { /* * JUST get the formatted value, specifically DON'T tack on the formatted units yet; * we do this to see how many units we'll have to scale to afterwards (outside this * while loop) to make the array of values passed to us unique */ String formatted = nf.format(scaledValues[i]); /* * check whether formatted value was in the set or not; if it was, we have to * loop, but only if we're not not already at our maximum precision */ boolean wasNewElement = existingStrings.add(formatted); if ((!wasNewElement) && (precisionDigits < MAX_PRECISION_DIGITS)) { scaleWithMorePrecision = true; break; } results[i] = formatted; } } /* * we did the best we could in terms of trying to find a precision that adds the most * uniqueness to the given set of values, NOW tack on the formatted value for the units */ for (int i = 0; i < results.length; i++) { results[i] = format(results[i], targetUnits); } return results; }
From source file:org.rhq.coregui.client.util.MeasurementConverterClient.java
License:Open Source License
public static String format(Double value, MeasurementUnits targetUnits, boolean bestFit, Integer minimumFractionDigits, Integer maximumFractionDigits) { if (value == null || Double.isNaN(value)) { return NULL_OR_NAN_FORMATTED_VALUE; }/*from w w w. ja v a 2 s. c o m*/ if (bestFit) { MeasurementNumericValueAndUnits valueAndUnits = fit(value, targetUnits); value = valueAndUnits.getValue(); targetUnits = valueAndUnits.getUnits(); } // apply relative scale at presentation time if (targetUnits != null && MeasurementUnits.Family.RELATIVE == targetUnits.getFamily()) { value = MeasurementUnits.scaleUp(value, targetUnits); } NumberFormat numberFormat = NumberFormat .getFormat(getFormat(minimumFractionDigits != null ? minimumFractionDigits : 1, maximumFractionDigits != null ? maximumFractionDigits : 1)); String formatted = numberFormat.format(value); return format(formatted, targetUnits); }
From source file:org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.ResourceGroupTreeView.java
License:Open Source License
private ResourceGroupEnhancedTreeNode createClusterGroupNode(ClusterKey parentKey, ResourceType type, ClusterFlyweight child) {//from ww w . j a v a2s. c o m // This node represents one type of resource that has 1 or more individual resources as members in the group. // It will be associated with both a resource type and a cluster key. ResourceGroupEnhancedTreeNode node = new ResourceGroupEnhancedTreeNode(child.getName()); ClusterKeyFlyweight keyFlyweight = child.getClusterKey(); ClusterKey key = new ClusterKey(parentKey, keyFlyweight.getResourceTypeId(), keyFlyweight.getResourceKey()); String id = key.getKey(); String parentId = parentKey.getKey(); node.setID(id); node.setParentID(parentId); node.setClusterKey(key); node.setResourceType(type); node.setIsFolder(!child.getChildren().isEmpty()); int memberCount = child.getMembers(); int clusterSize = child.getClusterSize(); if (memberCount < clusterSize) { // it appears one or more individual group members doesn't have a resource with the given cluster key // label the tree node so the user knows this cluster node is not representative of the entire group membership double percentage = (double) memberCount / (double) clusterSize; String percentageStr = NumberFormat.getFormat("0%").format(percentage); String title = child.getName() + " <span style=\"color: red; font-style: italic\">(" + percentageStr + ")</span>"; node.setTitle(title); // "1 out of 2 group members have "foo" child resources" node.setTooltip(MSG.group_tree_partialClusterTooltip(String.valueOf(memberCount), String.valueOf(clusterSize), child.getName())); } return node; }
From source file:org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.calltime.CallTimeView.java
License:Open Source License
public void setup() { Table table = new Table(extendLocatorId("Table"), MSG.view_resource_monitor_calltime_title(), new Criteria("scheduleId", String.valueOf(scheduleId))); table.getListGrid().setAlternateRecordStyles(false); table.setDataSource(new CallTimeDataSource()); table.getListGrid().setUseAllDataSourceFields(true); final NumberFormat format = NumberFormat.getFormat("0"); ListGridField callDestination = new ListGridField("callDestination", MSG.view_resource_monitor_calltime_destination()); ListGridField count = new ListGridField("count", MSG.view_resource_monitor_calltime_count(), 70); ListGridField minimum = new ListGridField("minimum", MSG.view_resource_monitor_calltime_minimum(), 70); ListGridField average = new ListGridField("average", MSG.view_resource_monitor_calltime_average(), 70); average.setCellFormatter(new CellFormatter() { public String format(Object o, ListGridRecord listGridRecord, int i, int i1) { return format.format(((Number) o).doubleValue()); }// w w w .j av a 2s . com }); ListGridField maximum = new ListGridField("maximum", MSG.view_resource_monitor_calltime_maximum(), 70); ListGridField total = new ListGridField("total", MSG.common_title_total(), 70); table.getListGrid().setFields(callDestination, count, minimum, average, maximum, total); addMember(table); markForRedraw(); }
From source file:org.roda.wui.common.client.tools.Humanize.java
public static String readableFileSize(long size) { if (size <= 0) { return "0 B"; }/*from w w w . j a va 2 s . c o m*/ int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return NumberFormat.getFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + UNITS[digitGroups]; }
From source file:org.roda.wui.common.client.tools.Humanize.java
/** * Format a value in milliseconds as a string * //from w ww. jav a 2s.com * @param value * @param showMillis * @return a formatted string for time duration */ public static String formatValueMilliseconds(long value, boolean showMillis) { long hours = value / 3600000; long minutes = (value % 3600000) / 60000; long seconds = ((value % 3600000) % 60000) / 1000; long millis = value % 1000; NumberFormat numberFormat = NumberFormat.getFormat("00"); NumberFormat millisFormat = NumberFormat.getFormat("000"); if (showMillis) { return numberFormat.format(hours) + ":" + numberFormat.format(minutes) + ":" + numberFormat.format(seconds) + "." + millisFormat.format(millis); } else { return numberFormat.format(hours) + ":" + numberFormat.format(minutes) + ":" + numberFormat.format(seconds); } }
From source file:org.roda.wui.common.client.widgets.wcag.AccessibleSimplePager.java
@Override protected String createText() { // Default text is 1 based. NumberFormat formatter = NumberFormat.getFormat("#,###"); HasRows display = getDisplay();/*from w ww . ja va2 s. co m*/ Range range = display.getVisibleRange(); int pageStart = range.getStart() + 1; int pageSize = range.getLength(); int dataSize = display.getRowCount(); int endIndex = Math.min(dataSize, pageStart + pageSize - 1); endIndex = Math.max(pageStart, endIndex); boolean exact = display.isRowCountExact(); return formatter.format(pageStart) + "-" + formatter.format(endIndex) + " " + (exact ? messages.of() : messages.ofOver()) + " " + formatter.format(dataSize); }