类com.google.gwt.core.client.JsonUtils源码实例Demo

下面列出了怎么用com.google.gwt.core.client.JsonUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: gwt-material-demo   文件: MaterialCandleStick.java
private void draw() {
	JsArrayMixed dataArray = JsonUtils.unsafeEval("[['Mon',20,28,38,45],['Tue',31,38,55,66],['Wed',50,55,77,80],['Thu',77,77,66,50],['Fri',68,66,22,15]]");

	// Prepare the data
	DataTable dataTable = ChartHelper.arrayToDataTable(dataArray, true);

	// Set options
	CandlestickChartOptions options = CandlestickChartOptions.create();
	BackgroundColor bgColor = BackgroundColor.create();
	bgColor.setStroke("#2196f3");
	bgColor.setFill("#90caf9");
	bgColor.setStrokeWidth(2);
	
	
	
	options.setLegend(Legend.create(LegendPosition.NONE));
	options.setFallingColor(bgColor);
	options.setRisingColor(bgColor);

	// Draw the chart
	chart.draw(dataTable, options);
}
 
源代码2 项目: gwt-material-demo   文件: MaterialComboCharts.java
private void draw() {
	JsArrayMixed dataArray = JsonUtils
			.unsafeEval("[['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua  Guinea', 'Rwanda', 'Average'],['2004/05', 165, 938, 522, 998, 450, 614.6],['2005/06', 135, 1120, 599, 1268, 288, 682],['2006/07', 157, 1167, 587, 807, 397, 623],['2007/08', 139, 1110, 615, 968, 215, 609.4],['2008/09', 136, 691, 629, 1026, 366, 569.6]]");

	// Prepare the data
	DataTable dataTable = ChartHelper.arrayToDataTable(dataArray);

	// Set options
	ComboChartOptions options = ComboChartOptions.create();
	options.setFontName("Tahoma");
	options.setTitle("Monthly Coffee Production by Country");
	options.setHAxis(HAxis.create("Cups"));
	options.setVAxis(VAxis.create("Month"));
	options.setSeriesType(SeriesType.BARS);
	ComboChartSeries series = ComboChartSeries.create();
	series.setType(SeriesType.LINE);
	options.setSeries(5, series);

	// Draw the chart
	chart.draw(dataTable, options);
}
 
源代码3 项目: swellrt   文件: AnnotationRegistry.java
/**
 * Define a new custom annotation.
 *
 * @param key annotation's name
 * @param cssClass a css class for the html container
 * @param cssStyle css styles for the html container
 */
public static void define(String key, String cssClass, JavaScriptObject cssStyleObj) throws SEditorException {

  if (key == null || key.startsWith("paragraph") || key.startsWith(AnnotationConstants.STYLE_PREFIX) || CANONICAL_KEYS.getString(key) != null) {
    throw new SEditorException("Not valid annotation name");
  }

  JsoView cssStyles = null;
  if (JsEditorUtils.isString(cssStyleObj)) {
    JavaScriptObject o = JsonUtils.unsafeEval(cssStyleObj.toString());
    if (o != null) {
      cssStyles = JsoView.as(o);
    }
  } else {
    cssStyles = JsoView.as(cssStyleObj);
  }

  AnnotationController annotation = new AnnotationController(key);
  store.put(key, annotation);
  UserAnnotationHandler.register(Editor.ROOT_REGISTRIES, key, cssClass, cssStyles,
      annotation.getTextEventHanlder(), annotation.getTextEventHanlder(),
      annotation.getTextEventHanlder());
}
 
源代码4 项目: gwtbootstrap3-extras   文件: SliderBase.java
private List<Double> getNumberArrayAttribute(SliderOption option, List<Double> defaultValue) {

        // Get array attribute
        JsArrayNumber array = null;
        if (isAttached()) {
            array = getNumberArrayAttribute(getElement(), option.getName());
        } else {
            String value = attributeMixin.getAttribute(option.getDataAttribute());
            if (value != null && !value.isEmpty()) {
                array = JsonUtils.safeEval(value);
            }
        }

        // Attribute not set
        if (array == null) {
            return defaultValue;
        }

        // Put array to list
        List<Double> list = new ArrayList<Double>(array.length());
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }
        return list;
    }
 
源代码5 项目: gwtbootstrap3-extras   文件: SliderBase.java
private List<String> getStringArrayAttribute(SliderOption option, List<String> defaultValue) {

        // Get array attribute
        JsArrayString array = null;
        if (isAttached()) {
            array = getStringArrayAttribute(getElement(), option.getName());
        } else {
            String value = attributeMixin.getAttribute(option.getDataAttribute());
            if (value != null && !value.isEmpty()) {
                array = JsonUtils.safeEval(value);
            }
        }

        // Attribute not set
        if (array == null) {
            return defaultValue;
        }

        // Put array to list
        List<String> list = new ArrayList<String>(array.length());
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }
        return list;
    }
 
源代码6 项目: proarc   文件: JsonTokenizer.java
public static JSONValue parse(String token) {
    try {
        if (JsonUtils.safeToEval(token)) {
            JSONValue jsonv = JSONParser.parseStrict(token);
            return jsonv;
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, token, ex);
    }
    return null;
}
 
源代码7 项目: swellrt   文件: WebServerOperationExecutor.java
@Override
protected <O extends ServiceOperation.Options> String toJson(O options) {
  if (options != null) {
    if (options instanceof JavaScriptObject) {
      return JsonUtils.stringify((JavaScriptObject) options);
    }
  }
  return null;
}
 
源代码8 项目: swellrt   文件: WebModelFactory.java
@Override
public Object parseJsonObject(String json) {
  if (json != null)
    return JsonUtils.<JavaScriptObject> safeEval(json);

  return null;
}
 
源代码9 项目: swellrt   文件: WebModelFactory.java
@Override
public String serializeJsonObject(Object o) {

  if (isJsPrimitive(o)) {
    return o.toString();
  } else if (o instanceof JavaScriptObject) {
    return JsonUtils.stringify((JavaScriptObject) o);
  }

  throw new IllegalStateException("Object can't be serialized to JSON");

}
 
源代码10 项目: swellrt   文件: SJsonFactoryWeb.java
@Override
public String serialize(SJsonObject object) {

  if (object instanceof SJsonObjectWeb) {
    SJsonObjectWeb jow = (SJsonObjectWeb) object;
    return JsonUtils.stringify(jow.getJsoView());
  }

  return null;
}
 
源代码11 项目: gwt-ol   文件: GeoJsonTest.java
public void testWriteGeoJSON() {

        injectUrlAndTest(() -> {
            String geoJson = geoJsonFormat.writeFeatures(OLTestUtils.createLineFeatures(), null);
            assertNotNull(geoJson);

            java.lang.Object geoJsonObject = JsonUtils.safeEval(geoJson);
            assertNotNull(geoJsonObject);
        });

    }
 
源代码12 项目: gwtbootstrap3-extras   文件: SliderBase.java
private void updateSliderForNumberArray(SliderOption option, List<Double> value) {
    JsArrayNumber array = JavaScriptObject.createArray().cast();
    for (Double val : value) {
        array.push(val);
    }
    if (isAttached()) {
        setAttribute(getElement(), option.getName(), array);
        refresh();
    } else {
        String arrayStr = JsonUtils.stringify(array);
        attributeMixin.setAttribute(option.getDataAttribute(), arrayStr);
    }
}
 
源代码13 项目: gwtbootstrap3-extras   文件: SliderBase.java
private void updateSliderForStringArray(SliderOption option, List<String> value) {
    JsArrayString array = JavaScriptObject.createArray().cast();
    for (String val : value) {
        array.push(val);
    }
    if (isAttached()) {
        setAttribute(getElement(), option.getName(), array);
        refresh();
    } else {
        String arrayStr = JsonUtils.stringify(array);
        attributeMixin.setAttribute(option.getDataAttribute(), arrayStr);
    }
}
 
源代码14 项目: swellrt   文件: WebServerOperationExecutor.java
@Override
protected OperationError parseServiceError(String json) {
  return (OperationError) JsonUtils.safeEval(json);
}
 
源代码15 项目: requestor   文件: OverlaySerdes.java
protected <T extends JavaScriptObject> T eval(String response) {
    return USE_SAFE_EVAL ? JsonUtils.<T>safeEval(response) : JsonUtils.<T>unsafeEval(response);
}
 
源代码16 项目: gwt-jackson   文件: FastJsonWriter.java
private void string(String value) {
  out.append(JsonUtils.escapeValue(value));
}
 
源代码17 项目: gwtbootstrap3-extras   文件: Range.java
/**
 * Converts the given string to a range instance.<br>
 * <br>
 * Useful when using UiBinder.
 *
 * @param value
 * @return
 */
public static Range fromString(String value) {
    if (value == null || value.isEmpty())
        return null;
    JsArrayNumber array = JsonUtils.safeEval(value);
    return new Range(array);
}
 
源代码18 项目: gwtbootstrap3-extras   文件: SelectBase.java
/**
 * Sets the window padding to top, right, bottom, and right sides. This
 * is useful in cases where the window has areas that the drop-down menu
 * should not cover - for instance a fixed header.
 *
 * @param top
 * @param right
 * @param bottom
 * @param left
 */
public void setWindowPaddingTopRightBottomLeft(final int top, final int right,
        final int bottom, final int left) {
    JsArrayNumber array = JavaScriptObject.createArray(4).cast();
    array.push(top);
    array.push(right);
    array.push(bottom);
    array.push(left);
    attrMixin.setAttribute(WINDOW_PADDING, JsonUtils.stringify(array));
}
 
源代码19 项目: requestor   文件: JsonObjectSerdes.java
/**
 * Performs evaluation of serialized response obeying the #useSafeEval configuration.
 * <p/>
 *
 * If #useSafeEval is {@code true} then the eval is performed using {@link JsonUtils#safeEval},
 * otherwise then content will be loosely evaluated by {@link JsonUtils#unsafeEval}.
 *
 * @param response The serialized content
 *
 * @return The converted JavaScriptObject
 */
protected JavaScriptObject eval(String response) {
    return useSafeEval() ? JsonUtils.safeEval(response) : JsonUtils.unsafeEval(response);
}