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:edu.nrao.dss.client.util.Conversions.java
License:Open Source License
public static String degreesToTime(double signed_degrees) { double degrees = Math.abs(signed_degrees); String sign = ""; int hours = (int) (degrees / 15.0); int minutes = (int) ((degrees / 15.0 - hours) * 60.0); double seconds = ((degrees / 15.0 - hours) * 60.0 - minutes) * 60.0; if (Math.abs(seconds - 60.0) < 0.1) { minutes += 1;/*from w w w . jav a 2 s . c o m*/ seconds = Math.abs(seconds - 60.0); } if (Math.abs(minutes - 60.0) < 0.1) { hours += 1; minutes = Math.abs(minutes - 60); } if (Math.abs(hours - 24.0) < 0.1) { hours = Math.abs(hours - 24); } if (signed_degrees < 0.0) { sign = "-"; } StringBuilder result = new StringBuilder(); result.append(sign).append(NumberFormat.getFormat("00").format(hours)).append(":") .append(NumberFormat.getFormat("00").format(minutes)).append(":") .append(NumberFormat.getFormat("00.0").format(seconds)); return result.toString(); }
From source file:edu.nrao.dss.client.util.Conversions.java
License:Open Source License
public static String degreesToSexagesimal(double signed_decimaldegrees) { double decimaldegrees = Math.abs(signed_decimaldegrees); int degrees = (int) (decimaldegrees); int minutes = (int) ((Math.abs(decimaldegrees) - Math.abs(degrees)) * 60.0); double seconds = ((Math.abs(decimaldegrees) - Math.abs(degrees)) * 60.0 - minutes) * 60.0; String sign = ""; if (Math.abs(seconds - 60.0) < 0.1) { minutes += 1;/* w w w . j av a 2 s.c om*/ seconds = Math.abs(seconds - 60.0); } if (Math.abs(minutes - 60.0) < 0.1) { degrees += 1; minutes = Math.abs(minutes - 60); } if (signed_decimaldegrees < 0.0) { sign = "-"; } String degreeFormat; if (degrees >= 100 | degrees <= -100) { degreeFormat = "000"; } else { degreeFormat = "00"; } StringBuilder result = new StringBuilder(); result.append(sign).append(NumberFormat.getFormat(degreeFormat).format(degrees)).append(":") .append(NumberFormat.getFormat("00").format(minutes)).append(":") .append(NumberFormat.getFormat("00.0").format(seconds)); return result.toString(); }
From source file:edu.nrao.dss.client.util.dssgwtcal.DayView.java
License:Open Source License
private void addScoreLabels(float scores[], int dayIndex, int numDays, Date date) { // compute where horizontally this line of scores should be printed float lefts[] = new float[numDays]; for (int i = 0; i < numDays; i++) { lefts[i] = i * (100.0f / numDays); }//from w w w. j a v a 2 s .co m float thisLeft = lefts[dayIndex]; float widths = 6f; // constant width float quarterHeight = this.getSettings().getPixelsPerInterval(); //30.0f; // height of one quarter == (2 px/min)(15 min) float qTop = 0.0f; Date start = date; Date end; int numQtrs = 24 * 4; // each hour has 4 15-min quarters String desc; int scoreOffset = dayIndex * numQtrs; for (int q = 0; q < numQtrs; q++) { // figure out where this score goes qTop = (q * quarterHeight); start = new Date(start.getTime() + (1000 * 60 * 15 * q)); end = new Date(start.getTime() + (1000 * 60 * 14)); float scoreValue = scores[q + scoreOffset]; desc = NumberFormat.getFormat("#0.00").format((double) scoreValue); // here's the object that will hold our score Label score = new Label(); score.setDescription(desc); score.setTitle(""); score.setStart(start); score.setEnd(end); score.setLeft(thisLeft); score.setWidth(widths); score.setHeight(quarterHeight); score.setTop(qTop); DOM.setStyleAttribute(score.getElement(), "size", "1"); // add it to the calendar! this.dayViewBody.getGrid().grid.add((Widget) score); if (scoreValue == 0.0) { DOM.setStyleAttribute(score.getElement(), "color", "FF0000"); } } }
From source file:edu.nrao.dss.client.widget.explorers.PeriodColConfig.java
License:Open Source License
private void scoreField() { setAlignment(HorizontalAlignment.RIGHT); setNumberFormat(NumberFormat.getFormat("0")); setRenderer(new GridCellRenderer<BaseModelData>() { public Object render(BaseModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) { if (model.get(property) != null) { String retval = model.get(property).toString(); if (4 < retval.length()) { retval = retval.substring(0, 4); }// www . j a va2 s .c o m return retval; } else { return ""; } } }); }
From source file:edu.nrao.dss.client.widget.explorers.PeriodColConfig.java
License:Open Source License
private void doubleField() { NumberField field = createDoubleField(); setAlignment(HorizontalAlignment.RIGHT); setEditor(new CellEditor(field) { @Override/*from ww w . j a v a 2 s . c o m*/ public Object preProcessValue(Object value) { if (value == null) { return null; } return Double.valueOf(value.toString()); } @Override public Object postProcessValue(Object value) { if (value == null) { return null; } return value.toString(); } }); setNumberFormat(NumberFormat.getFormat("0")); setRenderer(new GridCellRenderer<BaseModelData>() { public Object render(BaseModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) { if (model.get(property) != null) { return model.get(property).toString(); } else { return ""; } } }); }
From source file:edu.nrao.dss.client.widget.explorers.SessionColConfig.java
License:Open Source License
private void doubleField() { NumberField field = createDoubleField(); setAlignment(HorizontalAlignment.RIGHT); setEditor(new CellEditor(field)); setNumberFormat(NumberFormat.getFormat("0")); setRenderer(new GridCellRenderer<BaseModelData>() { public Object render(BaseModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) { if (model.get(property) != null) { return model.get(property).toString(); } else { return ""; }//from ww w . j av a 2s. com } }); }
From source file:edu.nrao.dss.client.widget.explorers.SessionColConfig.java
License:Open Source License
private void intField() { NumberField field = createIntegerField(); setAlignment(HorizontalAlignment.RIGHT); setEditor(new CellEditor(field) { @Override/*from w w w . j av a 2 s . co m*/ public Object preProcessValue(Object value) { if (value == null) { return null; } return Integer.parseInt(value.toString()); } @Override public Object postProcessValue(Object value) { if (value == null) { return null; } return value.toString(); } }); setNumberFormat(NumberFormat.getFormat("0")); setRenderer(new GridCellRenderer<BaseModelData>() { public Object render(BaseModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) { if (model.get(property) != null) { return model.get(property).toString(); } else { return ""; } } }); }
From source file:edu.nrao.dss.client.widget.explorers.UserExplorer.java
License:Open Source License
private ColumnModel initColumnModel() { List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); ColumnConfig column = new ColumnConfig("username", "Username", 100); CellEditor editor = new CellEditor(new TextField<String>()); column.setEditor(editor);/*w w w. j a v a 2 s .co m*/ configs.add(column); column = new ColumnConfig("first_name", "First Name", 100); column.setEditor(new CellEditor(new TextField<String>())); configs.add(column); column = new ColumnConfig("last_name", "Last Name", 100); column.setEditor(new CellEditor(new TextField<String>())); configs.add(column); column = new ColumnConfig("pst_id", "PST ID", 100); column.setEditor(new CellEditor(new TextField<String>())); column.setNumberFormat(NumberFormat.getFormat("#")); configs.add(column); column = new ColumnConfig("original_id", "Original ID", 100); column.setEditor(new CellEditor(new TextField<String>())); column.setNumberFormat(NumberFormat.getFormat("#")); configs.add(column); CheckColumnConfig checkColumn = new CheckColumnConfig("sanctioned", "Sanctioned?", 70); checkColumn.setEditor(new CellEditor(new CheckBox())); configs.add(checkColumn); checkBoxes.add(checkColumn); column = new ColumnConfig("role", "Role", 80); column.setEditor(initCombo(new String[] { "Administrator", "Observer", "Operator" })); configs.add(column); checkColumn = new CheckColumnConfig("staff", "Staff?", 65); checkColumn.setEditor(new CellEditor(new CheckBox())); configs.add(checkColumn); checkBoxes.add(checkColumn); column = new ColumnConfig("projects", "Projects", 800); editor = new CellEditor(new TextField<String>()); editor.disable(); column.setEditor(editor); configs.add(column); return new ColumnModel(configs); }
From source file:edu.nrao.dss.client.widget.FactorGrid.java
License:Open Source License
public FactorGrid(int rows, int cols, String[] headers, String[][] factors) { super(rows + 1, cols); setBorderWidth(2);//from w w w . j av a 2 s . c om setCellPadding(1); setCellSpacing(1); HashMap<String, Integer> colMap = new HashMap<String, Integer>(); for (int col = 0; col < cols; col++) { setHeader(col, headers[col]); colMap.put(headers[col], col); getCellFormatter().setHorizontalAlignment(0, col, HasHorizontalAlignment.ALIGN_CENTER); } for (int row = 0; row < rows; ++row) { for (int fac = 0; fac < cols; fac++) { int col = colMap.get(headers[fac]); String text = factors[row][col]; Double value; if (!text.contains("-") & !text.contains("?")) { value = Double.valueOf(text); text = NumberFormat.getFormat("#0.0000").format(value); } else { value = null; } setText(row + 1, col, text); getCellFormatter().setHorizontalAlignment(row + 1, col, HasHorizontalAlignment.ALIGN_CENTER); getCellFormatter().setWordWrap(row + 1, col, false); if (value != null) { if (value == 0.000) { getCellFormatter().setStyleName(row + 1, col, "gwt-FactorGrid-" + "zero"); } } } } }
From source file:edu.nrao.dss.client.widget.form.ProjAllotmentFieldSet.java
License:Open Source License
private void setReadOnlyField(String label, NumberField nf) { nf.setFieldLabel(label);//from w w w . java 2 s .co m nf.setReadOnly(true); // Note: this does not work! nf.setStyleAttribute("color", "grey"); nf.setFormat(NumberFormat.getFormat("#0.00")); }