Example usage for com.google.gwt.json.client JSONArray getJavaScriptObject

List of usage examples for com.google.gwt.json.client JSONArray getJavaScriptObject

Introduction

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

Prototype

public JavaScriptObject getJavaScriptObject() 

Source Link

Document

Returns the underlying JavaScript array that this object wraps.

Usage

From source file:amdb.client.slider.Slider.java

License:Apache License

/**
 * Sets the value of each anchor/*from w  w  w .j a  va2 s . co m*/
 * @param values - int array of values
 */
public void setValues(int[] values) {
    JSONArray vals = intArrayToJSONArray(values);
    setValuesJS(getElement().getId(), vals.getJavaScriptObject());
}

From source file:client.ui.components.Chart.java

License:Open Source License

/**
 * Get a {@code JavaScriptObject} with the information from a collection
 * of {@code Series} as required by the library.
 *
 * @param seriesCollection Collection of {@code Series}.
 * @return {@code JavaScriptObject} as required by the library.
 *///  ww w  .j a  v  a2s.c o  m
private JavaScriptObject seriesListToJSObject(Collection<Series> seriesCollection) {

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

    int dataArrayIndex = 0;
    JSONArray dataArray = new JSONArray();

    for (Series series : seriesCollection) {
        dataArray.set(dataArrayIndex, series.toJSONObject());
        dataArrayIndex++;
    }

    return dataArray.getJavaScriptObject();
}

From source file:com.ait.lienzo.client.core.shape.MultiPath.java

License:Open Source License

protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException {
    super(ShapeType.MULTI_PATH, node, ctx);

    JSONValue pval = node.get("path-list");

    if (null != pval) {
        final JSONArray list = pval.isArray();

        if (null != list) {
            final int size = list.size();

            for (int i = 0; i < size; i++) {
                final JSONValue lval = list.get(i);

                if (null != lval) {
                    final JSONArray path = lval.isArray();

                    if (null != path) {
                        PathPartListJSO pjso = path.getJavaScriptObject().cast();

                        add(new PathPartList(pjso, true));
                    }//from   w w  w  . j a  va  2 s . c  om
                }
            }
        }
    }
}

From source file:com.arcbees.analytics.client.ClientAnalytics.java

License:Apache License

private void call(JSONValue... params) {
    final JSONArray aryParams = new JSONArray();
    for (JSONValue p : params) {
        aryParams.set(aryParams.size(), p);
    }//from  w w  w .j a  v  a  2s.c o m
    nativeCall(aryParams.getJavaScriptObject());
}

From source file:com.chap.links.client.GraphDemo3_offline.java

License:Apache License

/**
 * This is the entry point method./*  w  ww  .  ja v a  2s .c  o m*/
 */
public void onModuleLoad() {
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");

    JSONArray dataA = new JSONArray();
    JSONArray dataB = new JSONArray();

    // create data 
    Date d = dtf.parse("2012-08-23");
    int n = 200; // number of datapoints
    for (int i = 0; i < n; i++) {
        JSONObject pointA = new JSONObject();
        pointA.put("date", new JSONNumber(d.getTime()));
        pointA.put("value", new JSONNumber(customFunctionA(i)));
        dataA.set(i, pointA);

        JSONObject pointB = new JSONObject();
        pointB.put("date", new JSONNumber(d.getTime()));
        pointB.put("value", new JSONNumber(customFunctionB(i)));
        dataB.set(i, pointB);

        d.setTime(d.getTime() + 1000 * 60); // steps of one minute
    }

    JSONObject dataSetA = new JSONObject();
    dataSetA.put("label", new JSONString("Function A"));
    dataSetA.put("data", dataA);

    JSONObject dataSetB = new JSONObject();
    dataSetB.put("label", new JSONString("Function B"));
    dataSetB.put("data", dataB);

    Graph.Options options = Graph.Options.create();
    options.setHeight("400px");
    options.setLineStyle(Graph.Options.LINESTYLE.DOT, 1);
    options.setLineColor("blue", 1);
    options.setLineLegend(false, 0);

    JSONArray data = new JSONArray();
    data.set(0, dataSetA);
    data.set(1, dataSetB);

    // create the graph, with data and options
    chart = new Graph(data.getJavaScriptObject(), options);

    RootPanel.get("mygraph").add(chart);
}

From source file:com.github.ligangty.common.highconvert.BaseChart.java

License:Apache License

@Override
protected void onLoad() {

    // Build some arrays that we can pass into the JS function so that it knows how many custom callback functions it needs to wire
    // up on the client side for formatter functions and event handlers.
    JSONArray xAxisLabelFormatters = new JSONArray();
    JSONArray xAxisEventHandlers = new JSONArray();
    for (int i = 0, xAxesSize = xAxes.size(); i < xAxesSize; i++) {
        XAxis xAxis = xAxes.get(i);/*from   ww w .  j av a2  s .  c om*/
        xAxisLabelFormatters.set(i,
                JSONBoolean.getInstance(xAxis.getLabels() != null && xAxis.getLabels().getFormatter() != null));

        JSONObject axisEventHandlers = new JSONObject();
        axisEventHandlers.put("setExtremes",
                JSONBoolean.getInstance(xAxis.getAxisSetExtremesEventHandler() != null));
        xAxisEventHandlers.set(i, axisEventHandlers);
    }
    JSONArray yAxisLabelFormatters = new JSONArray();
    JSONArray yAxisStackLabelFormatters = new JSONArray();
    JSONArray yAxisEventHandlers = new JSONArray();
    for (int i = 0, yAxesSize = yAxes.size(); i < yAxesSize; i++) {
        YAxis yAxis = yAxes.get(i);
        yAxisLabelFormatters.set(i,
                JSONBoolean.getInstance(yAxis.getLabels() != null && yAxis.getLabels().getFormatter() != null));
        yAxisStackLabelFormatters.set(i, JSONBoolean
                .getInstance(yAxis.getStackLabels() != null && yAxis.getStackLabels().getFormatter() != null));

        JSONObject axisEventHandlers = new JSONObject();
        axisEventHandlers.put("setExtremes",
                JSONBoolean.getInstance(yAxis.getAxisSetExtremesEventHandler() != null));
        yAxisEventHandlers.set(i, axisEventHandlers);
    }

    // Build a similar object for dealing with all of the data label formatters that may be set on the plot options
    JSONObject plotOptionsLabelFormatters = new JSONObject();
    plotOptionsLabelFormatters.put("area", hasDataLabelsFormatter(areaPlotOptions));
    plotOptionsLabelFormatters.put("arearange", hasDataLabelsFormatter(areaRangePlotOptions));
    plotOptionsLabelFormatters.put("areaspline", hasDataLabelsFormatter(areaSplinePlotOptions));
    plotOptionsLabelFormatters.put("areasplinerange", hasDataLabelsFormatter(areaSplineRangePlotOptions));
    plotOptionsLabelFormatters.put("bar", hasDataLabelsFormatter(barPlotOptions));
    plotOptionsLabelFormatters.put("column", hasDataLabelsFormatter(columnPlotOptions));
    plotOptionsLabelFormatters.put("columnrange", hasDataLabelsFormatter(columnRangePlotOptions));
    plotOptionsLabelFormatters.put("line", hasDataLabelsFormatter(linePlotOptions));
    plotOptionsLabelFormatters.put("pie", hasDataLabelsFormatter(piePlotOptions));
    plotOptionsLabelFormatters.put("ohlc", hasDataLabelsFormatter(ohlcPlotOptions));
    plotOptionsLabelFormatters.put("series", hasDataLabelsFormatter(seriesPlotOptions));
    plotOptionsLabelFormatters.put("scatter", hasDataLabelsFormatter(scatterPlotOptions));
    plotOptionsLabelFormatters.put("spline", hasDataLabelsFormatter(splinePlotOptions));

    // And one more for dealing with any data label formatters that have been applied directly to a series
    JSONArray seriesLabelFormatters = new JSONArray();
    for (int i = 0, seriesListSize = seriesList.size(); i < seriesListSize; i++) {
        Series series = seriesList.get(i);
        seriesLabelFormatters.set(i, hasDataLabelsFormatter(series));
    }

    // Another one for events fired on the chart
    JSONObject chartEventHandlers = new JSONObject();
    chartEventHandlers.put("click", JSONBoolean.getInstance(chartClickEventHandler != null));
    chartEventHandlers.put("load", JSONBoolean.getInstance(chartLoadEventHandler != null));
    chartEventHandlers.put("redraw", JSONBoolean.getInstance(chartRedrawEventHandler != null));
    chartEventHandlers.put("selection", JSONBoolean.getInstance(chartSelectionEventHandler != null));

    // And two more for events that have been applied to the series (or the points within the series)
    JSONObject seriesEventHandlers = new JSONObject();
    JSONObject pointEventHandlers = new JSONObject();

    if (seriesPlotOptions != null) {

        // Series event
        seriesEventHandlers.put("click",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesClickEventHandler() != null));
        seriesEventHandlers.put("checkboxClick",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesCheckboxClickEventHandler() != null));
        seriesEventHandlers.put("hide",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesHideEventHandler() != null));
        seriesEventHandlers.put("legendItemClick",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesLegendItemClickEventHandler() != null));
        seriesEventHandlers.put("mouseOver",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesMouseOverEventHandler() != null));
        seriesEventHandlers.put("mouseOut",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesMouseOutEventHandler() != null));
        seriesEventHandlers.put("show",
                JSONBoolean.getInstance(seriesPlotOptions.getSeriesShowEventHandler() != null));

        // Point events
        pointEventHandlers.put("click",
                JSONBoolean.getInstance(seriesPlotOptions.getPointClickEventHandler() != null));
        pointEventHandlers.put("mouseOver",
                JSONBoolean.getInstance(seriesPlotOptions.getPointMouseOverEventHandler() != null));
        pointEventHandlers.put("mouseOut",
                JSONBoolean.getInstance(seriesPlotOptions.getPointMouseOutEventHandler() != null));
        pointEventHandlers.put("remove",
                JSONBoolean.getInstance(seriesPlotOptions.getPointRemoveEventHandler() != null));
        pointEventHandlers.put("select",
                JSONBoolean.getInstance(seriesPlotOptions.getPointSelectEventHandler() != null));
        pointEventHandlers.put("unselect",
                JSONBoolean.getInstance(seriesPlotOptions.getPointUnselectEventHandler() != null));
        pointEventHandlers.put("update",
                JSONBoolean.getInstance(seriesPlotOptions.getPointUpdateEventHandler() != null));
    }

    // Pie charts support one additional point event
    if (piePlotOptions != null) {
        pointEventHandlers.put("legendItemClick",
                JSONBoolean.getInstance(piePlotOptions.getPointLegendItemClickEventHandler() != null));
    }

    chart = nativeRenderChart(getChartTypeName(), createNativeOptions(),
            toolTip != null && toolTip.getToolTipFormatter() != null,
            legend != null && legend.getLabelsFormatter() != null, chartEventHandlers.getJavaScriptObject(),
            seriesEventHandlers.getJavaScriptObject(), pointEventHandlers.getJavaScriptObject(),
            xAxisEventHandlers.getJavaScriptObject(), yAxisEventHandlers.getJavaScriptObject(),
            xAxisLabelFormatters.getJavaScriptObject(), yAxisLabelFormatters.getJavaScriptObject(),
            yAxisStackLabelFormatters.getJavaScriptObject(), plotOptionsLabelFormatters.getJavaScriptObject(),
            seriesLabelFormatters.getJavaScriptObject());

    // Now that we're rendered we're going to switch to maintaining everything within the DOM, so we can dump
    // any series data that we were managing internally
    for (Series series : seriesList) {
        series.clearInternalPointsList();
        series.setRendered(true);
    }

}

From source file:com.github.ligangty.common.highconvert.Series.java

License:Apache License

/**
 * Apply a new set of data (Y values only) to the series and optionally redraw it.  If you need
 * more control than just simply setting the y values of each data point, then use the
 * {@link #setPoints(com.github.ligangty.common.highconvert.Point[], boolean)} method instead.
 *
 * @param yValues The array of Y values to set on the data series (replacing any data already in place)
 * @param redraw  Whether to redraw the chart after the series is altered. If doing more operations
 *                on the chart, it is a good idea to set redraw to false and then call
 *                {@link com.github.ligangty.common.highconvert.Chart#redraw()} after.
 * @return A reference to this {@link com.github.ligangty.common.highconvert.Series} instance for convenient method chaining.
 *//*from   w  ww .  j  a  v a 2 s.  c o  m*/
public Series setPoints(Number[] yValues, boolean redraw) {
    this.points.clear();

    // If persistence is enabled than we need to store the point locally as well (so we have it if
    // the chart is dynamically moved to another panel).
    if (!isRendered() || chart.isPersistent()) {
        for (Number yValue : yValues) {
            this.addPoint(yValue);
        }
    }

    if (isRendered()) {
        final JavaScriptObject nativeSeries = chart.get(this.id);
        if (nativeSeries != null) {
            JSONArray jsonArray = new JSONArray();
            for (int i = 0, pointsLength = yValues.length; i < pointsLength; i++) {
                if ((yValues[i] != null)) {
                    jsonArray.set(i, new JSONNumber(yValues[i].doubleValue()));
                } else {
                    jsonArray.set(i, JSONNull.getInstance());
                }
            }
            nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
        }
    }

    return this;
}

From source file:com.github.ligangty.common.highconvert.Series.java

License:Apache License

/**
 * Apply a new set of data to the series and optionally redraw it. The format of the data values 
 * should match the chart type of the Series:
 * <ul>/*  w  ww .  j  ava 2s  . c o  m*/
 * <li>[x, y] - for standard line or area charts</li>
 * <li>[x, low, high] - for area range charts</li>
 * <li>[x, open, high, low, close] - for OHLC charts</li>
 * </ul> 
 * 
 * <p>If you need more control than just simply setting the x and y values of each data point, then 
 * use the {@link #setPoints(com.github.ligangty.common.highconvert.Point[])} method instead.
 *
 * @param values A two dimensional array of values, where the main array is the list of points and
 *               each inner array contains values matching the series data type, described above.
 * @param redraw Whether to redraw the chart after the series is altered. If doing more operations
 *               on the chart, it is a good idea to set redraw to false and then call
 *               {@link com.github.ligangty.common.highconvert.Chart#redraw()} after.
 * @return A reference to this {@link com.github.ligangty.common.highconvert.Series} instance for convenient method chaining.
 */
public Series setPoints(Number[][] values, boolean redraw) {
    this.points.clear();

    // If persistence is enabled than we need to store the point locally as well (so we have it if
    // the chart is dynamically moved to another panel).
    if (!isRendered() || chart.isPersistent()) {
        for (Number[] xyValue : values) {
            if (xyValue.length == 5) {
                // For OHLC charts
                this.addPoint(xyValue[0], xyValue[1], xyValue[2], xyValue[3], xyValue[4]);
            } else if (xyValue.length == 3) {
                // For area range charts
                this.addPoint(xyValue[0], xyValue[1], xyValue[2]);
            } else {
                this.addPoint(xyValue[0], xyValue[1]);
            }
        }
    }

    if (isRendered()) {
        final JavaScriptObject nativeSeries = chart.get(this.id);
        if (nativeSeries != null) {
            JSONArray jsonArray = new JSONArray();
            for (int i = 0, pointsLength = values.length; i < pointsLength; i++) {
                Number[] point = values[i];
                JSONValue jsonValue;
                if (point == null) {
                    jsonValue = JSONNull.getInstance();
                } else if (point.length == 5) {
                    // For OHLC charts
                    JSONArray pointArray = new JSONArray();
                    pointArray.set(0, BaseChart.convertNumberToJSONValue(point[0]));
                    pointArray.set(1, BaseChart.convertNumberToJSONValue(point[1]));
                    pointArray.set(2, BaseChart.convertNumberToJSONValue(point[2]));
                    pointArray.set(3, BaseChart.convertNumberToJSONValue(point[3]));
                    pointArray.set(4, BaseChart.convertNumberToJSONValue(point[4]));
                    jsonValue = pointArray;
                } else if (point.length == 3) {
                    // For Area Range charts
                    JSONArray pointArray = new JSONArray();
                    pointArray.set(0, BaseChart.convertNumberToJSONValue(point[0]));
                    pointArray.set(1, BaseChart.convertNumberToJSONValue(point[1]));
                    pointArray.set(2, BaseChart.convertNumberToJSONValue(point[2]));
                    jsonValue = pointArray;
                } else if (point.length > 1) {
                    JSONArray pointArray = new JSONArray();
                    pointArray.set(0, BaseChart.convertNumberToJSONValue(point[0]));
                    pointArray.set(1, BaseChart.convertNumberToJSONValue(point[1]));
                    jsonValue = pointArray;
                } else {
                    jsonValue = BaseChart.convertNumberToJSONValue(point[0]);
                }
                jsonArray.set(i, jsonValue);
            }
            nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
        }
    }

    return this;
}

From source file:com.github.ligangty.common.highconvert.Series.java

License:Apache License

/**
 * Apply a new set of data to the series and optionally redraw it.
 *
 * @param points The array of points to set on the data series (replacing any data already in place)
 * @param redraw Whether to redraw the chart after the series is altered. If doing more operations
 *               on the chart, it is a good idea to set redraw to false and then call
 *               {@link com.github.ligangty.common.highconvert.Chart#redraw()} after.
 * @return A reference to this {@link com.github.ligangty.common.highconvert.Series} instance for convenient method chaining.
 */// w  ww.  ja  v a 2 s. c o  m
public Series setPoints(Point[] points, boolean redraw) {
    this.points.clear();

    // If persistence is enabled than we need to store the point locally as well (so we have it if
    // the chart is dynamically moved to another panel).
    if (!isRendered() || chart.isPersistent()) {
        Collections.addAll(this.points, points);
    }

    if (isRendered()) {
        final JavaScriptObject nativeSeries = chart.get(this.id);
        if (nativeSeries != null) {
            JSONArray jsonArray = new JSONArray();
            for (int i = 0, pointsLength = points.length; i < pointsLength; i++) {
                jsonArray.set(i, chart.convertPointToJSON(points[i]));
            }
            nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
        }
    }

    return this;
}

From source file:com.horaz.client.widgets.charting.Plot.java

License:Open Source License

/**
 * creates/refreshes the plot/*from w ww. j  ava2 s . c o m*/
 */
public void render() {
    JSONArray a = new JSONArray();
    for (int i = 0; i < series.size(); i++) {
        a.set(i, series.get(i));
    }
    _init(getElement(), a.getJavaScriptObject(), options.getJavaScriptObject());
}