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.nrao.dss.client.widget.form.ProjAllotmentFieldSet.java

License:Open Source License

private void setEditableField(String label, NumberField nf) {
    nf.setFieldLabel(label);/*from  w  ww  .j  a  v  a  2s . c  o m*/
    nf.setFormat(NumberFormat.getFormat("#0.00"));
    nf.setValidator(new DSSTimeValidator());
    nf.addListener(Events.Blur, new Listener<BaseEvent>() {
        @Override
        public void handleEvent(BaseEvent be) {
            double value = ((NumberField) be.getSource()).getValue().doubleValue();
            double orgvl = ((NumberField) be.getSource()).getOriginalValue().doubleValue();
            String color = (orgvl == value) ? "black" : "red";
            ((NumberField) be.getSource()).el().firstChild().setStyleAttribute("color", color);
            //               if (orgvl == value) {
            //                  ((NumberField) be.getSource()).setStyleAttribute("color", "black");
            //               } else {
            //                  ((NumberField) be.getSource()).setStyleAttribute("color", "red");
            //               }
        }
    });
}

From source file:edu.nrao.dss.client.widget.NumCopyPeriodGroupDialog.java

License:Open Source License

private void initLayout() {

    //setLayout(new FlowLayout());

    FormPanel fp = new FormPanel();
    fp.setHeaderVisible(false);/*from  www . j  a  v a2 s  .  com*/

    numCopies = new NumberField();
    numCopies.setFieldLabel("Copies");
    numCopies.setFormat(NumberFormat.getFormat("#0"));
    numCopies.setValue(1);

    fp.add(numCopies);

    add(fp);
}

From source file:edu.nrao.dss.client.widget.SessionTimePanel.java

License:Open Source License

private void initLayout() {
    setLayout(new RowLayout(Orientation.VERTICAL)); //FitLayout());
    setBorders(false);/*from   w  w  w  . j  av a 2 s  . c o m*/
    setVisible(true);
    setHeaderVisible(false);

    // this table is used to place two forms side by side
    LayoutContainer sessionTable = new LayoutContainer();
    TableLayout tbSess = new TableLayout(2);
    tbSess.setWidth("100%");
    tbSess.setBorder(0);
    sessionTable.setLayout(tbSess);
    sessionTable.setBorders(true);

    TableData tdSess = new TableData();
    tdSess.setVerticalAlign(VerticalAlignment.TOP);

    // Question: why must I do this, just to get the two forms to share space?
    tdSess.setColspan(1);
    tdSess.setWidth("400px");

    final FormPanel sessionForm = new FormPanel();
    sessionForm.setHeading("Session");
    sessionForm.setBorders(false);
    sessionForm.setBodyBorder(false);

    sessions.setFieldLabel("Sessions");
    sessionForm.add(sessions);

    // what's the current session?
    sessionName.setValue("");
    sessionName.setReadOnly(true);
    // Note: this doesn't work
    sessionName.setStyleAttribute("color", "grey");
    sessionName.setFieldLabel("Session Name");
    sessionName.setVisible(false);
    sessionForm.add(sessionName);

    sessionForm.add(saveSess);

    sessionTable.add(sessionForm, tdSess);

    final FormPanel sessionForm2 = new FormPanel();
    sessionForm2.setHeading("Allotment");
    sessionForm2.setBorders(false);

    sessionGrade.setReadOnly(true);
    // Note: this doesn't work
    sessionGrade.setStyleAttribute("color", "grey");
    sessionGrade.setFieldLabel("Grade");
    sessionForm2.add(sessionGrade);

    sessionTime.setFieldLabel("Alloted (Hrs)");
    sessionTime.setFormat(NumberFormat.getFormat("#0.00"));
    sessionTime.setValidator(new DSSTimeValidator());
    sessionForm2.add(sessionTime);

    sessionTimeRemaining.setReadOnly(true);
    sessionTimeRemaining.setFieldLabel("Remaining (Hrs)");
    sessionTimeRemaining.setFormat(NumberFormat.getFormat("#0.00"));
    //sessionTimeRemaining.setValidator(new DSSTimeValidator());    
    sessionForm2.add(sessionTimeRemaining);

    sessionTable.add(sessionForm2, tdSess);

    add(sessionTable, new RowData(1, -1, new Margins(4)));
    sessionTimeAccounting.setHeading("Session Time Accounting");
    sessionTimeAccounting.collapse();
    add(sessionTimeAccounting, new RowData(1, -1, new Margins(4)));
}

From source file:edu.nrao.dss.client.widget.TimeAccountingPanel.java

License:Open Source License

private void setDefaultField(String label, NumberField nf) {
    nf.setFieldLabel(label);//from   w ww.j av a  2 s .  c o m
    nf.setReadOnly(true);
    // NOTE: it would be good to darken the background of read-only fields
    // but since it seems we can't do this till they've been rendered, it doesn't work.
    nf.setFormat(NumberFormat.getFormat("#0.00"));
    nf.setValidator(new DSSTimeValidator());
    // remind the user that they've changed a value      
    nf.addListener(Events.Blur, new Listener<BaseEvent>() {
        @Override
        public void handleEvent(BaseEvent be) {
            NumberField nf = ((NumberField) be.getSource());
            double value = nf.getValue().doubleValue();
            double orgvl = nf.getOriginalValue().doubleValue();
            String color = (orgvl == value) ? "black" : "red";
            if (nf.isRendered()) {
                nf.el().firstChild().setStyleAttribute("color", color);
            }
        }
    });
}

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.controller.DBController.java

License:Open Source License

/**
 * Get program panel show values .//from   www.  j a v a 2 s.  c o m
 * 
 * @param program
 * @param isUpdate
 * @return  Program panel show value array
 */
public static String[] getProgramPanelValue(final Program program, boolean isUpdate) {

    final String[] values = new String[10];
    int i = 0;
    values[i++] = program.getName();

    //for category
    values[i++] = null;
    String TypeString = program.getType();
    logger.info(TypeString.toLowerCase());
    if ("?".equals(TypeString.toLowerCase()) || "standalone".equals(TypeString.toLowerCase()))
        values[i] = Constants.studioUIMsg.standalone() + "/" + Constants.studioUIMsg.distributed() + "/ETL"
                + "/Tensorflow";
    if ("spark".equals(TypeString) || "?".equals(TypeString) || TypeString.equals("distributed")
            || TypeString.toLowerCase().equals("distributed")) {
        values[i] = Constants.studioUIMsg.distributed() + "/" + Constants.studioUIMsg.standalone() + "/ETL"
                + "/Tensorflow";
    }
    if ("etl".equals(TypeString))
        values[i] = "ETL/" + Constants.studioUIMsg.distributed() + "/" + Constants.studioUIMsg.standalone()
                + "/Tensorflow";
    if ("tensorflow".equals(TypeString))
        values[i] = "Tensorflow/" + Constants.studioUIMsg.distributed() + "/"
                + Constants.studioUIMsg.standalone() + "/ETL";

    i++;

    if (program.getProgramable())
        values[i] = Constants.studioUIMsg.yes() + "/" + Constants.studioUIMsg.no();
    else
        values[i] = Constants.studioUIMsg.no() + "/" + Constants.studioUIMsg.yes();
    i++;

    boolean deterministic = program.getIsdeterministic();
    if (deterministic)
        values[i] = Constants.studioUIMsg.yes() + "/" + Constants.studioUIMsg.no();
    else
        values[i] = Constants.studioUIMsg.no() + "/" + Constants.studioUIMsg.yes();
    i++;

    double version = 0;
    if ((!program.getVersion().contains("n")) && isUpdate) {
        version = Double.parseDouble(program.getVersion()) + 0.1;
    } else
        version = Double.parseDouble(program.getVersion());

    values[i] = NumberFormat.getFormat("#0.0").format(version);
    i++;

    Date dateNow = new Date();
    DateTimeFormat dateFormat = DateTimeFormat.getFormat("yyyy-MM-dd KK:mm:ss a");
    values[i] = dateFormat.format(dateNow);
    i++;

    values[i++] = AppController.email;
    values[i++] = program.getDescription();
    values[i++] = program.getCommandline();

    String tensorflowMode = program.getTensorflowMode();
    if ("?".equals(tensorflowMode) || "standalone".equals(tensorflowMode))
        values[i] = Constants.studioUIMsg.standalone() + "/" + Constants.studioUIMsg.modelDistributed() + "/"
                + Constants.studioUIMsg.dataDistributed();
    else if ("".equals(tensorflowMode) || "model distributed".equals(tensorflowMode))
        values[i] = Constants.studioUIMsg.modelDistributed() + "/" + Constants.studioUIMsg.standalone() + "/"
                + Constants.studioUIMsg.dataDistributed();
    else if ("?".equals(tensorflowMode) || "data distributed".equals(tensorflowMode))
        values[i] = Constants.studioUIMsg.dataDistributed() + "/" + Constants.studioUIMsg.standalone() + "/"
                + Constants.studioUIMsg.modelDistributed();
    else
        values[i] = Constants.studioUIMsg.standalone() + "/" + Constants.studioUIMsg.modelDistributed() + "/"
                + Constants.studioUIMsg.dataDistributed();

    return values;
}

From source file:eml.studio.client.controller.DBController.java

License:Open Source License

/**
 * Get dataset panel show values .//from  w  w  w. ja  v a2 s  .  c  o m
 * 
 * @param dataset
 * @param isUpdate
 * @return  Data panel show value array
 */
public static String[] getDatasetPanelValue(final Dataset dataset, boolean isUpdate) {
    String[] values = new String[7];
    Date dateNow = new Date();
    DateTimeFormat dateFormat = DateTimeFormat.getFormat("yyyy-MM-dd KK:mm:ss a");
    values[4] = dateFormat.format(dateNow);
    double version = 0;
    if ((!dataset.getVersion().contains("n")) && isUpdate) {
        version = Double.parseDouble(dataset.getVersion()) + 0.1;
    } else
        version = Double.parseDouble(dataset.getVersion());
    values[3] = NumberFormat.getFormat("#0.0").format(version);

    values[1] = null;
    String TypeString = dataset.getContenttype();
    if (TypeString == null || TypeString.equals("") || "General".equals(TypeString))
        values[2] = "General/CSV/TSV/JSON";
    else if ("TSV".equals(TypeString))
        values[2] = "TSV/General/CSV/JSON";
    else if ("CSV".equals(TypeString))
        values[2] = "CSV/General/TSV/JSON";
    else
        values[2] = "JSON/General/TSV/CSV";
    values[0] = dataset.getName();
    values[5] = AppController.email;
    values[6] = dataset.getDescription();
    return values;
}

From source file:eml.studio.client.util.TimeUtils.java

License:Open Source License

public static String timeDiff(Date date1, Date date2) {
    if (date1 == null || date2 == null)
        return "";
    long nh = 1000 * 60 * 60;
    long nm = 1000 * 60;
    long ns = 1000;
    try {/*from w ww  . jav a2 s .com*/
        long diff = date2.getTime() - date1.getTime();

        // gap of hour
        long hour = diff / nh;
        // gap of min
        long min = diff % nh / nm;
        // gap of sec
        long sec = diff % nh % nm / ns;
        String res = NumberFormat.getFormat("#00").format(hour) + ":"
                + NumberFormat.getFormat("#00").format(min) + ":" + NumberFormat.getFormat("#00").format(sec);
        return res;
    } catch (IllegalArgumentException ex) {
        return null;
    }
}

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;/*from ww  w  .j a  va  2s  . c o m*/
    while (label <= (maxY + delta) && i < maxNumberLabels) {
        yValues.add(fmt.format(Math.round(label)));
        label += delta;
        i++;
    }

    return yValues;
}

From source file:fr.insalyon.creatis.vip.core.client.view.util.FieldUtil.java

License:Open Source License

/**
 * Gets a CellFormatter to parse file sizes.
 *
 * @return//from   w w w . j  a  va 2  s  .  co  m
 */
public static CellFormatter getSizeCellFormatter() {

    return new CellFormatter() {

        @Override
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {

            if (value == null) {
                return null;
            }

            long length = ((Number) value).longValue();
            if (length > 0) {
                String size = length + " B";
                NumberFormat nf = NumberFormat.getFormat("#.##");
                if (length / 1024 > 0) {
                    if (length / (1024 * 1024) > 0) {
                        if (length / (1024 * 1024 * 1024) > 0) {
                            size = nf.format(length / (double) (1024 * 1024 * 1024)) + " GB";
                        } else {
                            size = nf.format(length / (double) (1024 * 1024)) + " MB";
                        }
                    } else {
                        size = nf.format(length / (double) 1024) + " KB";
                    }
                }
                return size;

            } else {
                return "";
            }
        }
    };
}