Example usage for com.google.gwt.i18n.client NumberFormat getFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getFormat.

Prototype

public static NumberFormat getFormat(String pattern) 

Source Link

Document

Gets a NumberFormat instance for the default locale using the specified pattern and the default currencyCode.

Usage

From source file:edu.caltech.ipac.firefly.ui.catalog.CatalogPanel.java

private void updateToActive() {
    ActiveTarget at = ActiveTarget.getInstance();
    _targetPanel.setTarget(at.getActive());

    if (_currSearchMethod == null)
        return;//from  www  . j  a va2s .c  o m
    NumberFormat formatter = NumberFormat.getFormat("#.000000");
    String ra, dec;

    SearchMethods method = _methods.get(_currSearchMethod);
    if (_searchMethod.getValue().equals(POLYGON) && at.getImageCorners() != null) {
        WorldPt[] wpts = at.getImageCorners();
        StringBuffer wptsString = new StringBuffer();
        if (wpts.length > 0) {
            ra = formatter.format(wpts[0].getLon());
            dec = formatter.format(wpts[0].getLat());
            wptsString.append(ra + " " + dec);
            for (int i = 1; i < wpts.length; i++) {
                ra = formatter.format(wpts[i].getLon());
                dec = formatter.format(wpts[i].getLat());
                wptsString.append(", " + ra + " " + dec);
            }

        }
        ((SearchMethods.Polygon) method).getField().setValue(new String(wptsString));
    }

}

From source file:edu.caltech.ipac.firefly.visualize.conv.CoordUtil.java

/**
 * Converts decimal angle to string format
 * @param dangle decimal angle/*ww w.  jav a  2 s . co  m*/
 * @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  w  w .  j  a  v a2 s. c  om
    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;/*ww  w .  ja  v  a2  s. c  om*/
    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());
    }//  ww w . ja v  a2  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   w ww.  j a v a 2s  . 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  ww. j  ava2 s. 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.colorado.csdms.wmt.client.ui.cell.DoubleCellRenderer.java

License:Open Source License

public String render(Double object) {
    if (object == null) {
        return "";
    }//from  www .  jav a  2  s.c  o m
    return NumberFormat.getFormat("#,##0.0#####").format(object);
}

From source file:edu.nrao.dss.client.FactorsAccess.java

License:Open Source License

private void populateHeadersFactors(JSONObject json, Date start, String tz) {
    JSONArray fs = json.get("factors").isArray();
    JSONArray fs0 = fs.get(0).isArray();
    int length = fs0.size();
    // Grid size including times, but not headers
    int rows = fs.size();
    int cols = length + 1;
    // Extract column header names
    headers = new String[cols];
    headers[0] = "Date [" + tz + "]";
    for (int i = 0; i < length; ++i) {
        String str = fs0.get(i).isArray().get(0).toString();
        headers[i + 1] = str.substring(1, str.indexOf('"', 1));
    }//from   ww  w  .  j a  v a  2  s .c o m
    // Extract factor values
    factors = new String[rows][cols];
    long msecs = start.getTime();
    Date quarter = new Date();
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
    for (int t = 0; t < rows; ++t) {
        JSONArray row = fs.get(t).isArray();
        quarter.setTime(msecs);
        msecs += 15 * 60 * 1000;
        factors[t][0] = dtf.format(quarter);
        for (int f = 0; f < length; ++f) {
            JSONObject obj = row.get(f).isArray().get(1).isObject();
            String repr;
            if (obj.containsKey("Nothing")) {
                repr = "?";
            } else {
                double value = obj.get("Just").isNumber().doubleValue();
                repr = NumberFormat.getFormat("#0.0000000").format(value);
            }
            factors[t][f + 1] = repr;
        }
    }
}

From source file:edu.nrao.dss.client.forms.SourceForm.java

License:Open Source License

private void calcDiameter() {
    // Do we have everything we need?   
    Radio frameChoice = frame.getValue();
    if (frameChoice != null & !topoFreq.getValue().isEmpty() & !restFreq.getValue().isEmpty()
            & !sourceVelocity.getValue().isEmpty() & !redshift.getValue().isEmpty()) {
        if (frameChoice.getValueAttribute().equals("Topocentric Frame")) {
            double d = 0.1 * diameter.getValue() * calcFWHM(Double.valueOf(topoFreq.getValue()) * 1e6);
            diameter_display.setValue(NumberFormat.getFormat("#.##").format(d));
        } else {//  w  w  w  . j  a  v a 2  s  .c om
            //  TODO: Refactor to use Functions.velocity2Frequency()
            double rfreq = Double.valueOf(restFreq.getValue()) * 1e6;
            double tfreq = 0;
            if (doppler.getSelected().equals("Redshift")) {
                tfreq = rfreq / (1 + Double.valueOf(redshift.getValue()));
            } else if (doppler.getSelected().equals("Radio")) {
                tfreq = rfreq * (1 - (Double.valueOf(sourceVelocity.getValue()) * 1e3) / (c * 1e-2));
            } else {
                tfreq = rfreq / (1 + (Double.valueOf(sourceVelocity.getValue()) * 1e3) / (c * 1e-2));
            }
            double d = 0.1 * diameter.getValue() * calcFWHM(tfreq);
            diameter_display.setValue(NumberFormat.getFormat("#.##").format(d));
            topoFreq.setValue("" + tfreq * 1e-6);
        }
    }
}