view flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java @ 2953:75e9eab05ee4

Added overview chart to sq relation period input panel. flys-client/trunk@4932 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 11 Jul 2012 11:24:27 +0000
parents
children b7aab14310cb
line wrap: on
line source
package de.intevation.flys.client.client.ui.sq;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONString;

import com.google.gwt.core.client.GWT;

import com.smartgwt.client.types.Alignment;

import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.events.ResizedHandler;
import com.smartgwt.client.widgets.events.ResizedEvent;

import de.intevation.flys.client.client.ui.MultiPeriodPanel;

import de.intevation.flys.client.shared.model.DataList;

import de.intevation.flys.client.client.Config;
/**
 * This UIProvider creates helper panel for sq relation.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class SQMultiPeriodPanel
extends      MultiPeriodPanel
implements   ResizedHandler
{
    protected VLayout chartContainer;

    protected Img chartImg;

    public SQMultiPeriodPanel() {
        chartImg = new Img();
    }


    protected Canvas createHelper() {
        Config config    = Config.getInstance();
        String locale    = config.getLocale ();

        chartContainer = new VLayout();
        chartContainer.addResizedHandler(this);
        chartContainer.setAlign(Alignment.CENTER);

        return chartContainer;
    }


    protected void updateChart() {
        Config config    = Config.getInstance();
        String locale    = config.getLocale ();

        int hWidth = chartContainer.getWidth() - 12;
        int hHeight = chartContainer.getHeight() - 12;

        if ((int)(hHeight *4f/3) < hWidth) {
            hWidth = (int)(hHeight * 4f/3);
        }
        else {
            hHeight = (int)(hWidth *3f/4);
        }
        String river = artifact.getArtifactDescription().getRiver();

        JSONObject jfix = new JSONObject();
        JSONObject jfilter = new JSONObject();
        JSONObject jrName = new JSONObject();
        JSONString jrValue = new JSONString(river);
        JSONObject jextent = new JSONObject();
        JSONNumber jwidth = new JSONNumber(hWidth);
        JSONNumber jheight = new JSONNumber(hHeight);

        jrName.put("name", jrValue);
        jfilter.put("river", jrName);
        jextent.put("width", jwidth);
        jextent.put("height", jheight);
        jfilter.put("extent", jextent);
        jfix.put("sq", jfilter);
        String filter = jfix.toString();

        String imgUrl = GWT.getModuleBaseURL();
        imgUrl += "sq-km-chart";
        imgUrl += "?locale=" + locale;
        imgUrl += "&filter=" + filter;
        if (chartContainer.hasMember(chartImg)) {
            chartImg.setWidth(hWidth);
            chartImg.setHeight(hHeight);
            chartImg.setSrc(imgUrl);
        }
        else {
            chartImg = new Img(imgUrl, hWidth, hHeight);
            chartContainer.addMember(chartImg);
        }
    }


    public void onResized(ResizedEvent re) {
        updateChart();
    }
}

http://dive4elements.wald.intevation.org