com.google.gwt.core.client.JsonUtils Java Examples

The following examples show how to use com.google.gwt.core.client.JsonUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MaterialCandleStick.java    From gwt-material-demo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: MaterialComboCharts.java    From gwt-material-demo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: SliderBase.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
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;
    }
 
Example #4
Source File: SliderBase.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
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;
    }
 
Example #5
Source File: AnnotationRegistry.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #6
Source File: GeoJsonTest.java    From gwt-ol with Apache License 2.0 5 votes vote down vote up
public void testWriteGeoJSON() {

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

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

    }
 
Example #7
Source File: SliderBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #8
Source File: SliderBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #9
Source File: JsonTokenizer.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: SJsonFactoryWeb.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(SJsonObject object) {

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

  return null;
}
 
Example #11
Source File: WebModelFactory.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@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");

}
 
Example #12
Source File: WebModelFactory.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public Object parseJsonObject(String json) {
  if (json != null)
    return JsonUtils.<JavaScriptObject> safeEval(json);

  return null;
}
 
Example #13
Source File: WebServerOperationExecutor.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
protected <O extends ServiceOperation.Options> String toJson(O options) {
  if (options != null) {
    if (options instanceof JavaScriptObject) {
      return JsonUtils.stringify((JavaScriptObject) options);
    }
  }
  return null;
}
 
Example #14
Source File: OverlaySerdes.java    From requestor with Apache License 2.0 4 votes vote down vote up
protected <T extends JavaScriptObject> T eval(String response) {
    return USE_SAFE_EVAL ? JsonUtils.<T>safeEval(response) : JsonUtils.<T>unsafeEval(response);
}
 
Example #15
Source File: FastJsonWriter.java    From gwt-jackson with Apache License 2.0 4 votes vote down vote up
private void string(String value) {
  out.append(JsonUtils.escapeValue(value));
}
 
Example #16
Source File: WebServerOperationExecutor.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
protected OperationError parseServiceError(String json) {
  return (OperationError) JsonUtils.safeEval(json);
}
 
Example #17
Source File: Range.java    From gwtbootstrap3-extras with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: SelectBase.java    From gwtbootstrap3-extras with Apache License 2.0 3 votes vote down vote up
/**
 * 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));
}
 
Example #19
Source File: JsonObjectSerdes.java    From requestor with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}