List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:edu.caltech.ipac.firefly.visualize.conv.CoordUtil.java
/** * Converts decimal angle to string format * @param dangle decimal angle/* w w w.j av a 2 s .com*/ * @param islat true if the coordstr is latitude * @param isequ true if the coordstr is in equatorial system * @param precision for DMS, precision = 4+ number of * decimal digits you want in seconds * for HMS, precision = 3+ number of * decimal digits you want in seconds * @return String representation of angle */ public static String dd2sex(double dangle, boolean islat, boolean isequ, int precision) throws CoordException { int c_precision; int form; double tmp, dfs; int ofs; int hd, m, s; int rhd, rm, rs, rfs; int drfs; int d; int circ; char chd; char cm = 'm'; char cs = 's'; int isign = 1; String signstr; NumberFormat df; String fmtstr; int i; String buf; if (precision <= 0) c_precision = 0; else if (precision <= MAX_PRECISION) c_precision = precision; else c_precision = DEFAULT_PRECISION; if ((dangle < 0.0) && islat) isign = -1; if ((dangle < 0.0) && !islat) dangle = (dangle % 360.0) + 360.0; if ((dangle >= 360.0) && !islat) dangle = dangle % 360.0; // sign for Latitude/Dec '+' or '-' if (isign == 1) { if (islat) signstr = "+"; else signstr = ""; } else signstr = "-"; if (isequ) { if (islat) form = FORM_DMS; else form = FORM_HMS; } else form = FORM_DECIMAL_DEGREE; if (form == FORM_HMS) dangle /= 15.0; // convert degree to hours if ((form == FORM_DMS) || (form == FORM_HMS)) { tmp = Math.abs(dangle); hd = (int) tmp; tmp -= hd; tmp *= 60.0; m = (int) tmp; tmp -= m; tmp *= 60.0; s = (int) tmp; tmp -= s; dfs = tmp; if (form == FORM_DMS) { // sexagesimal degrees circ = 360; chd = 'd'; switch (c_precision) { case 0: d = 1; break; case 1: case 2: d = 2; break; case 3: case 4: d = 3; break; default: d = c_precision - 1; // 3 + precision + 4 break; } drfs = c_precision - 4; } else { // sexagesimal hours min sec circ = 24; chd = 'h'; switch (c_precision) { case 0: case 1: d = 2; break; case 2: case 3: d = 3; break; default: d = c_precision; break; // 3+p-3 } drfs = c_precision - 3; // the digits after seconds } switch (d) { case 1: // only degree rhd = hd + ((m >= 30) ? 1 : 0); if (rhd >= circ) rhd -= circ; buf = signstr; df = NumberFormat.getFormat("00"); buf += df.format(rhd); buf += "d"; break; case 2: // degree + minutes rm = m + ((s >= 30) ? 1 : 0); rhd = hd; if (rm >= 60) { rm -= 60; rhd++; } if (rhd >= circ) rhd -= circ; buf = signstr; buf += rhd; buf += chd; df = NumberFormat.getFormat("00"); buf += df.format(rm); buf += cm; break; case 3: // degree + minutes + seconds rs = s + ((dfs >= 0.5) ? 1 : 0); rm = m; rhd = hd; if (rs >= 60) { rs -= 60; rm++; } if (rm >= 60) { rm -= 60; rhd++; } if (rhd >= circ) rhd -= circ; buf = signstr; buf += rhd; buf += chd; df = NumberFormat.getFormat("00"); buf += df.format(rm); buf += cm; buf += df.format(rs); buf += cs; break; default: rs = s; rm = m; rhd = hd; tmp = Math.pow(10, drfs); ofs = (int) tmp; rfs = (int) Math.round(dfs * ofs); if (rfs >= ofs) { rfs -= ofs; rs++; } if (rs >= 60) { rs -= 60; rm++; } if (rm >= 60) { rm -= 60; rhd++; } if (rhd >= circ) rhd -= circ; buf = signstr; buf += rhd; buf += chd; df = NumberFormat.getFormat("00"); buf += df.format(rm); buf += cm; buf += df.format(rs); buf += "."; for (i = 0, fmtstr = ""; i < drfs; i++) fmtstr += "0"; //System.out.println("RBH fmtstr = " + fmtstr); df = NumberFormat.getFormat(fmtstr); buf += df.format(rfs); buf += cs; break; } } else // form == FORM_DECIMAL_DEGREE or otherwise unrecognized { if (islat && dangle >= 0) buf = "+"; else buf = ""; for (i = 0, fmtstr = "0."; i < c_precision; i++) fmtstr += "0"; df = NumberFormat.getFormat(fmtstr); // NumberFormat nf = NumberFormat.getInstance(Locale.US); // df= (DecimalFormat)nf; // df.setMaximumFractionDigits(c_precision); buf += df.format(dangle); buf += "d"; } return buf; }
From source file:edu.caltech.ipac.firefly.visualize.draw.WebGrid.java
protected String[] getLabels(double[][] levels) { String labels[] = new String[levels[0].length + levels[1].length]; int digits;/*from w ww.j a v a 2 s . co m*/ double delta; double value; int offset = 0; for (int i = 0; i < 2; i += 1) { if (levels[i].length < 2) { digits = 1; } else { delta = levels[i][1] - levels[i][0]; if (delta < 0) delta += 360; /* if (i == 0) { delta /= 15; }*/ if (delta > 1) { digits = 1; } else if (delta > .2) { digits = 2; } else if (delta > .02) { digits = 3; } else if (delta > .002) { digits = 4; } else if (delta > .0002) { digits = 5; } else { digits = 6; } } NumberFormat nf = NumberFormat.getFormat("#.###"); for (int j = 0; j < levels[i].length; j += 1) { value = levels[i][j]; if (_sexigesimal) { if (i == 0) // ra label { //sSharedCoords.setRa(value); //labels[offset] = sSharedCoords.raToString(); //labels[offset] = String.valueOf(value); try { labels[offset] = CoordUtil.dd2sex(value, false, true, 3); } catch (CoordException cx) { labels[offset] = nf.format(value); } } else { //sSharedCoords.setDec(value); //labels[offset] = sSharedCoords.decToString(); //labels[offset] = String.valueOf(value); try { labels[offset] = CoordUtil.dd2sex(value, true, true, 3); } catch (CoordException cx) { labels[offset] = nf.format(value); } } } else { //labels[offset] = String.valueOf(value); labels[offset] = nf.format(value); } offset += 1; } } return labels; }
From source file:edu.caltech.ipac.firefly.visualize.graph.XYPlotOptionsPanel.java
private void setup() { suspendEvents = true;/*from w w w. j a va 2s.c o m*/ setupOK = true; xColDialog = null; yColDialog = null; XYPlotMeta meta = _xyPlotWidget.getPlotMeta(); plotStyle.setValue(meta.plotStyle().key); plotError.setValue(meta.plotError()); plotSpecificPoints.setValue(meta.plotSpecificPoints()); plotGrid.setValue(!meta.noGrid()); // set X and Y columns first, since other fields might be dependent on them setupXYColumnFields(); setFldValue(xNameFld, meta.userMeta.xName); setFldValue(xUnitFld, meta.userMeta.xUnit); setFldValue(yNameFld, meta.userMeta.yName); setFldValue(yUnitFld, meta.userMeta.yUnit); XYPlotData data = _xyPlotWidget.getPlotData(); if (data != null) { if (data.hasError() && plotError.isEnabled()) plotError.setVisible(true); else plotError.setVisible(false); if (data.hasSpecificPoints() && plotSpecificPoints.isEnabled() && data.getCurveData().size() > 0) { String desc = data.getSpecificPoints().getDescription(); if (StringUtils.isEmpty(desc)) { desc = "Specific Points"; } plotSpecificPoints.setHTML("Plot " + desc); plotSpecificPoints.setVisible(true); } else plotSpecificPoints.setVisible(false); if (data.getCurveData().size() == 0 || data.isSampled()) { // only specific points to plot plotStyle.setVisible(false); } else { plotStyle.setVisible(true); } MinMax minMax = data.getXMinMax(); if (meta.getXScale() instanceof LogScale || (minMax.getMin() > 0 && minMax.getMax() / minMax.getMin() > 4)) { xLogScale.setEnabled(true); xLogScale.setVisible(true); } else { xLogScale.setEnabled(false); xLogScale.setVisible(false); } xLogScale.setValue(meta.getXScale() instanceof LogScale && xLogScale.isEnabled()); //xLogScale.setValue(meta.getXScale() instanceof LogScale); // same for y minMax = plotError.getValue() ? data.getWithErrorMinMax() : data.getYMinMax(); if (meta.getYScale() instanceof LogScale || (minMax.getMin() > 0 && minMax.getMax() / minMax.getMin() > 4)) { yLogScale.setEnabled(true); yLogScale.setVisible(true); } else { yLogScale.setEnabled(false); yLogScale.setVisible(false); } yLogScale.setValue(meta.getYScale() instanceof LogScale && yLogScale.isEnabled()); //yLogScale.setValue(meta.getYScale() instanceof LogScale); // aspect ratio if (meta.userMeta != null && meta.userMeta.aspectRatio > 0) { xyRatioFld.setValue(((DoubleFieldDef) xyRatioFld.getFieldDef()).format(meta.userMeta.aspectRatio)); } else { xyRatioFld.reset(); } stretchFld.setValue(meta.userMeta != null && meta.userMeta.stretchToFill ? "fill" : "fit"); // density plot parameters if (data.isSampled()) { densityPlotPanel.setVisible(true); binning.setValue((meta.userMeta != null && meta.userMeta.samplingXBins > 0 && meta.userMeta.samplingYBins > 0) ? "user" : "auto"); shading.setValue((meta.userMeta != null && meta.userMeta.logShading) ? "log" : "lin"); int xBins = data.getXSampleBins(); if (xBins > 0) { xBinsFld.setValue(Integer.toString(xBins)); } int yBins = data.getYSampleBins(); if (yBins > 0) { yBinsFld.setValue(Integer.toString(yBins)); } } else { densityPlotPanel.setVisible(false); } MinMax yMinMax = data.getYDatasetMinMax(); DoubleFieldDef yminFD = (DoubleFieldDef) yMinMaxPanel.getMinField().getFieldDef(); yminFD.setMinValue(Double.NEGATIVE_INFINITY); yminFD.setMaxValue(yMinMax.getMax()); NumberFormat nf_y = NumberFormat.getFormat(MinMax.getFormatString(yMinMax, 3)); yminFD.setErrMsg("Must be numerical value less than " + nf_y.format(yMinMax.getMax())); DoubleFieldDef ymaxFD = (DoubleFieldDef) yMinMaxPanel.getMaxField().getFieldDef(); ymaxFD.setMinValue(yMinMax.getMin()); ymaxFD.setMaxValue(Double.POSITIVE_INFINITY); ymaxFD.setErrMsg("Must be numerical value greater than " + nf_y.format(yMinMax.getMin())); MinMax xMinMax = data.getXDatasetMinMax(); DoubleFieldDef xminFD = (DoubleFieldDef) xMinMaxPanel.getMinField().getFieldDef(); xminFD.setMinValue(Double.NEGATIVE_INFINITY); xminFD.setMaxValue(xMinMax.getMax()); NumberFormat nf_x = NumberFormat.getFormat(MinMax.getFormatString(xMinMax, 3)); xminFD.setErrMsg("Must be numerical value less than " + nf_x.format(xMinMax.getMax())); DoubleFieldDef xmaxFD = (DoubleFieldDef) xMinMaxPanel.getMaxField().getFieldDef(); xmaxFD.setMinValue(xMinMax.getMin()); xmaxFD.setMaxValue(Double.POSITIVE_INFINITY); xmaxFD.setErrMsg("Must be numerical value greater than " + nf_x.format(xMinMax.getMin())); } MinMax xLimits = meta.userMeta.getXLimits(); if (xLimits != null) { NumberFormat nf = NumberFormat.getFormat(MinMax.getFormatString(xLimits, 3)); if (xLimits.getMin() != Double.NEGATIVE_INFINITY) { xMinMaxPanel.getMinField().setValue(nf.format(xLimits.getMin())); } else { xMinMaxPanel.getMinField().reset(); } if (xLimits.getMax() != Double.POSITIVE_INFINITY) { xMinMaxPanel.getMaxField().setValue(nf.format(xLimits.getMax())); } else { xMinMaxPanel.getMaxField().reset(); } } else { xMinMaxPanel.getMinField().reset(); xMinMaxPanel.getMaxField().reset(); } MinMax yLimits = meta.userMeta.getYLimits(); if (yLimits != null) { NumberFormat nf = NumberFormat.getFormat(MinMax.getFormatString(yLimits, 3)); if (yLimits.getMin() != Double.NEGATIVE_INFINITY) { yMinMaxPanel.getMinField().setValue(nf.format(yLimits.getMin())); } else { yMinMaxPanel.getMinField().reset(); } if (yLimits.getMax() != Double.POSITIVE_INFINITY) { yMinMaxPanel.getMaxField().setValue(nf.format(yLimits.getMax())); } else { yMinMaxPanel.getMaxField().reset(); } } else { yMinMaxPanel.getMinField().reset(); yMinMaxPanel.getMaxField().reset(); } xMinMaxPanelDesc.setHTML(getXMinMaxDescHTML(data == null ? null : data.getXDatasetMinMax())); yMinMaxPanelDesc.setHTML(getYMinMaxDescHTML(data == null ? null : data.getYDatasetMinMax())); //if (meta.getMaxPoints() > 0) { // maxPoints.setValue(meta.getMaxPoints()+""); //} //if (_xyPlotWidget instanceof XYPlotWidget) { // tableInfo.setHTML(((XYPlotWidget)_xyPlotWidget).getTableInfo()); //} setupOK = (xMinMaxPanel.validate() && yMinMaxPanel.validate() && validateColumns() && (data == null || !data.isSampled() || validateDensityPlotParams()) && xyRatioFld.validate()); suspendEvents = false; }
From source file:edu.caltech.ipac.firefly.visualize.graph.XYPlotOptionsPanel.java
private String getXMinMaxDescHTML(MinMax xMinMax) { String desc = "Remove out-of-bound points by defining a new X range.<br>"; if (xMinMax != null) { NumberFormat nf_x = NumberFormat.getFormat(MinMax.getFormatString(xMinMax, 3)); desc += "Dataset min X: " + nf_x.format(xMinMax.getMin()) + ", max X: " + nf_x.format(xMinMax.getMax()); }/*from w w w . ja va2 s . c om*/ return desc; }
From source file:edu.caltech.ipac.firefly.visualize.graph.XYPlotOptionsPanel.java
private String getYMinMaxDescHTML(MinMax yMinMax) { String desc = "Remove out-of-bound points by defining a new Y range.<br>"; if (yMinMax != null) { NumberFormat nf_y = NumberFormat.getFormat(MinMax.getFormatString(yMinMax, 3)); desc += "Dataset min Y: " + nf_y.format(yMinMax.getMin()) + ", max Y: " + nf_y.format(yMinMax.getMax()); }//from ww w . ja v a2 s .c o m return desc; }
From source file:edu.caltech.ipac.firefly.visualize.task.rpc.RotateTask.java
public static String makeMessage(PlotState.RotateType rotateType, double angle) { final NumberFormat nf = NumberFormat.getFormat("#.#"); String retval;//from w w w. j ava 2s. c o m switch (rotateType) { case NORTH: retval = "Rotating North..."; break; case ANGLE: retval = "Rotating to " + nf.format(angle) + " degrees ..."; break; case UNROTATE: retval = "Returning to original rotation..."; break; default: retval = "undefined"; break; } return retval; }
From source file:edu.umn.msi.tropix.webgui.client.utils.FileSizeUtils.java
License:Open Source License
private static String divide(final long numerator, final long denominator) { final NumberFormat formatted = NumberFormat.getFormat("#######.00"); return formatted.format((1.0 * numerator) / denominator); }
From source file:eml.studio.client.ui.widget.BaseWidget.java
License:Open Source License
public void printMessage(String eventName, int code, boolean modifier, boolean control) { final NumberFormat formatter = NumberFormat.getDecimalFormat(); String message = eventName + " - Char Code: " + formatter.format(code) + ". "; if (code == KeyCodes.KEY_ENTER) { message += "Key is ENTER. "; }//from w ww . j a v a 2 s. c o m if (modifier) message += "Modifier is down. "; if (control) message += "CTRL is down. "; logger.info("message" + message); }
From source file:eu.cloud4soa.frontend.widget.monitoring.client.views.gxt.charts.ChartImpl.java
License:Open Source License
private List<String> getYAxisLabels(double minY, double maxY, int maxNumberLabels) { NumberFormat fmt = NumberFormat.getFormat("###.#"); List<String> yValues = new ArrayList<String>(); double delta = (maxY - minY) / (maxNumberLabels - 1); double label = minY; int i = 0;// w ww . ja v a2s. c om while (label <= (maxY + delta) && i < maxNumberLabels) { yValues.add(fmt.format(Math.round(label))); label += delta; i++; } return yValues; }
From source file:examples.client.Main.java
License:Apache License
public void onModuleLoad() { // Like opening a browser Workspace w = new GWTWorkspace(); // Enables WebSocket connections w.addURIHandler(new WebSocket()); // Get array of long and stay connected through WebSocket String uri = "ws://test.objectfabric.org/array"; w.openAsync(uri, new AsyncCallback<Resource>() { @Override// w w w .ja v a 2s . c o m public void onSuccess(Resource result) { final TArrayLong array = (TArrayLong) result.get(); final NumberFormat format = NumberFormat.getDecimalFormat(); // Called when an array element is set array.addListener(new IndexListener() { @Override public void onSet(int i) { Element div = Document.get().getElementById("div" + i); div.setInnerHTML(format.format(array.get(i))); } }); } @Override public void onFailure(Exception e) { } }); }