Example usage for com.google.gwt.json.client JSONNumber JSONNumber

List of usage examples for com.google.gwt.json.client JSONNumber JSONNumber

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONNumber JSONNumber.

Prototype

public JSONNumber(double value) 

Source Link

Document

Creates a new JSONNumber from the double value.

Usage

From source file:com.eduworks.gwt.client.net.packet.AjaxPacket.java

License:Apache License

public void put(String key, Object jsonValue) {
    if (jsonValue instanceof String)
        super.put(key, new JSONString((String) jsonValue));
    else if (jsonValue instanceof Number)
        super.put(key, new JSONNumber(Double.parseDouble(String.valueOf(jsonValue))));
    else if (jsonValue instanceof JSONArray)
        super.put(key, (JSONArray) jsonValue);
    else if (jsonValue instanceof JSONObject)
        super.put(key, (JSONObject) jsonValue);
    else if (jsonValue instanceof Boolean)
        super.put(key, JSONBoolean.getInstance((Boolean) jsonValue));
    else if (jsonValue == null)
        super.put(key, (JSONNull) jsonValue);
    else//  w w  w.j  a  va  2  s.  com
        throw new JSONException();
}

From source file:com.emitrom.lienzo.client.core.shape.GridLayer.java

License:Open Source License

@Override
public JSONObject toJSONObject() {
    JSONObject obj = super.toJSONObject();

    JSONArray lines = new JSONArray();

    JSONArray sizes = new JSONArray();

    for (int i = 0; i < 4; i++) {
        if (m_lines[i] == null) {
            lines.set(i, JSONNull.getInstance());
        } else {//from  w  w w.j a v a  2 s .c om
            lines.set(i, m_lines[i].toJSONObject());
        }
        sizes.set(i, new JSONNumber(m_sizes[i]));
    }
    obj.put("lines", lines);

    obj.put("sizes", sizes); // TODO could put sizes in Attributes

    return obj;
}

From source file:com.example.slider.client.SliderExample.java

License:Apache License

/**
 * This is the entry point method./*from w  ww.  j  av a  2 s. c  o  m*/
 */
public void onModuleLoad() {
    /*
     * Create a slider with default behavior:
     * minimum possible value of 0, maximum possible value of 100,
     * default value of 25
     */
    Label sliderLabel = new Label("Value:");
    m_sliderLabel = new Label("0");
    m_sliderLabel.addStyleName("slider-values");
    m_slider = new Slider("slider");
    RootPanel.get("sliderContainer").add(sliderLabel);
    RootPanel.get("sliderContainer").add(m_sliderLabel);
    RootPanel.get("sliderContainer").add(m_slider);
    m_slider.addListener(this);

    /*
     * Create a RangeSlider with:
     * minimum possible value of 0, maximum possible value of 100,
     * default range of 25-40
     */
    Label rangeLabel = new Label("Price range:");
    m_rangeSliderLabel = new Label("$25 - $40");
    m_rangeSliderLabel.addStyleName("slider-values");
    m_rangeSlider = new RangeSlider("range", 0, 100, 25, 40);
    RootPanel.get("rangeContainer").add(rangeLabel);
    RootPanel.get("rangeContainer").add(m_rangeSliderLabel);
    RootPanel.get("rangeContainer").add(m_rangeSlider);
    m_rangeSlider.addListener(this);

    /*
     * Create a slider with:
     * minimum possible value of 50, maximum possible value of 500,
     * default 100, and step of 50
     * and 
     */
    Label stepLabel = new Label("Donation amount ($50 increments):");
    m_stepSliderLabel = new Label("$200");
    m_stepSliderLabel.addStyleName("slider-values");
    JSONObject options = Slider.getOptions(50, 500, new int[] { 200 });
    options.put(SliderOption.STEP.toString(), new JSONNumber(50));
    m_stepSlider = new Slider("step", options);
    RootPanel.get("stepContainer").add(stepLabel);
    RootPanel.get("stepContainer").add(m_stepSliderLabel);
    RootPanel.get("stepContainer").add(m_stepSlider);
    m_stepSlider.addListener(this);

    /*
     * Create a slider with:
     * minimum possible value of 0, maximum possible value of 100,
     * default values of 25, 50, and 75
     */
    Label multiLabel = new Label("Values:");
    m_multiSliderLabel = new Label("25, 50, 75");
    m_multiSliderLabel.addStyleName("slider-values");
    m_multiSlider = new Slider("multi", 0, 100, new int[] { 25, 50, 75 });
    RootPanel.get("multiContainer").add(multiLabel);
    RootPanel.get("multiContainer").add(m_multiSliderLabel);
    RootPanel.get("multiContainer").add(m_multiSlider);
    m_multiSlider.addListener(this);
}

From source file:com.facebook.tsdb.tsdash.client.model.ApplicationState.java

License:Apache License

public String toJSON() {
    JSONObject topObj = new JSONObject();
    topObj.put("view", new JSONString(view.toString()));
    topObj.put("timeMode", new JSONString(timeMode.toString()));
    topObj.put("tsFrom", new JSONNumber(timeRange.from));
    topObj.put("tsTo", new JSONNumber(timeRange.to));
    topObj.put("autoReload", JSONBoolean.getInstance(autoReload));
    topObj.put("fullscreen", JSONBoolean.getInstance(fullscreen));
    topObj.put("reloadPeriod", new JSONNumber(reloadPeriod));
    topObj.put("interactive", JSONBoolean.getInstance(interactive));
    topObj.put("surface", JSONBoolean.getInstance(surface));
    topObj.put("palette", JSONBoolean.getInstance(palette));
    JSONArray metricsArray = new JSONArray();
    for (int i = 0; i < metrics.size(); i++) {
        metricsArray.set(i, metrics.get(i).toJSON());
    }/*from w  ww  . j av a 2 s.c  o  m*/
    topObj.put("m", metricsArray);
    return topObj.toString();
}

From source file:com.facebook.tsdb.tsdash.client.service.HTTPService.java

License:Apache License

public void loadTimeSeries(TimeRange timeRange, ArrayList<Metric> metrics,
        final AsyncCallback<TimeSeriesResponse> callback) {
    // encode parameters
    JSONObject paramObj = new JSONObject();
    paramObj.put("tsFrom", new JSONNumber(timeRange.from / 1000));
    paramObj.put("tsTo", new JSONNumber(timeRange.to / 1000));
    JSONArray metricsArray = new JSONArray();
    for (int i = 0; i < metrics.size(); i++) {
        if (metrics.get(i).isPlottable()) {
            metricsArray.set(i, metrics.get(i).toJSONParam());
        }/* w w w  . ja v  a2 s.c  o  m*/
    }
    paramObj.put("metrics", metricsArray);
    String param = "params=" + paramObj.toString();
    get(callback, DATA_URL, param, new TimeSeriesDecoder());
}

From source file:com.facebook.tsdb.tsdash.client.service.HTTPService.java

License:Apache License

public void loadMetricHeader(Metric metric, TimeRange timeRange, final AsyncCallback<MetricHeader> callback) {
    JSONObject paramObj = new JSONObject();
    paramObj.put("tsFrom", new JSONNumber(timeRange.from / 1000));
    paramObj.put("tsTo", new JSONNumber(timeRange.to / 1000));
    paramObj.put("metric", new JSONString(metric.name));
    paramObj.put("tags", metric.encodeTags());
    String encodedParams = "params=" + paramObj.toString();
    get(callback, METRIC_HEADER_URL, encodedParams, new MetricHeaderDecoder());
}

From source file:com.facebook.tsdb.tsdash.client.service.HTTPService.java

License:Apache License

public void loadPlot(TimeRange timeRange, ArrayList<Metric> metrics, int width, int height, boolean surface,
        boolean palette, final AsyncCallback<PlotResponse> callback) {
    JSONObject paramObj = new JSONObject();
    paramObj.put("tsFrom", new JSONNumber(timeRange.from / 1000));
    paramObj.put("tsTo", new JSONNumber(timeRange.to / 1000));
    paramObj.put("width", new JSONNumber(width));
    paramObj.put("height", new JSONNumber(height));
    paramObj.put("surface", JSONBoolean.getInstance(surface));
    paramObj.put("palette", JSONBoolean.getInstance(palette));
    JSONArray metricsArray = new JSONArray();
    for (int i = 0; i < metrics.size(); i++) {
        if (metrics.get(i).isPlottable()) {
            metricsArray.set(i, metrics.get(i).toJSONParam());
        }// www .j  a  v  a 2 s. c  o m
    }
    paramObj.put("metrics", metricsArray);
    String param = "params=" + paramObj.toString();
    get(callback, PLOT_URL, param, new PlotResponseDecoder());
}

From source file:com.flatown.client.SearchBox.java

License:Apache License

/** Returns this SearchBox as a JSONValue */
public JSONValue toJSON() {
    JSONObject json = new JSONObject();
    json.put("query", new JSONString(getSearchQuery()));
    json.put("dbName", new JSONString(getDatabase()));
    json.put("numResults", new JSONNumber(getNumResults()));
    json.put("vis", JSONBoolean.getInstance(areResultsDisplayed()));
    return json;/*w  ww  .  j av a2s.  c  o  m*/
}

From source file:com.github.gilbertotorrezan.gwtcloudinary.client.CloudinaryUploadWidget.java

License:Open Source License

/**
 * The maximum number of files allowed in multiple upload mode. If selecting or dragging more files, only the first max_images files will be uploaded.
 * //from w  w w  . j  a v a2  s  .c om
 * @param maxFiles Integer. Default: null. Unlimited. Example: 10
 */
public CloudinaryUploadWidget setMaxFiles(Integer maxFiles) {
    options.put("max_files", maxFiles == null ? null : new JSONNumber(maxFiles));
    return this;
}

From source file:com.github.gilbertotorrezan.gwtcloudinary.client.CloudinaryUploadWidget.java

License:Open Source License

/**
 * If specified, enforce the given aspect ratio on selected region when performing interactive cropping. Relevant only if cropping is enabled.
 * The aspect ratio is defined as width/height. For example, 0.5 for portrait oriented rectangle or 1 for square.
 * //w w  w.  j  a  v  a  2  s .  c  o m
 * @param croppingAspectRatio Decimal. Default: null. No constraint. Example: 0.5
 */
public CloudinaryUploadWidget setCroppingAspectRatio(Double croppingAspectRatio) {
    options.put("cropping_aspect_ratio",
            croppingAspectRatio == null ? null : new JSONNumber(croppingAspectRatio));
    return this;
}