view flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemeNavigationPanel.java @ 4254:33b15ac17fd1

Only create and add GaugePanel when necessary The GaugePanel isn't created always and only show if WINFO and a river is selected now. It is only created on demand. Therefore all access to the GaugePanel is abstraced via methods that check if the GaugePanel is null before accessing it's methods.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 25 Oct 2012 13:58:53 +0200
parents f43d06d6a4a2
children f3325079dacc
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.ArrayList;
import java.util.List;

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

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.event.OnMoveEvent;
import de.intevation.flys.client.client.event.OnMoveHandler;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ThemeNavigationPanel extends Canvas {

    public static final int PANEL_MARGIN  = 5;
    public static final int BUTTON_HEIGHT = 25;
    public static final int BUTTON_MARGIN = 5;


    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);


    protected List<OnMoveHandler> handlers;


    public ThemeNavigationPanel() {
        this.handlers = new ArrayList<OnMoveHandler>();

        setWidth100();
        setHeight(BUTTON_HEIGHT);
        setMargin(PANEL_MARGIN);

        HLayout layout = new HLayout();
        layout.setWidth100();
        layout.setHeight(BUTTON_HEIGHT);
        layout.setMembersMargin(BUTTON_MARGIN);

        Canvas cu = createButton(MSG.theme_top(), OnMoveEvent.TOP);
        Canvas u  = createButton(MSG.theme_up(), OnMoveEvent.UP);
        Canvas d  = createButton(MSG.theme_down(), OnMoveEvent.DOWN);
        Canvas cd = createButton(MSG.theme_bottom(), OnMoveEvent.BOTTOM);

        layout.addMember(cu);
        layout.addMember(u);
        layout.addMember(d);
        layout.addMember(cd);

        addChild(layout);
    }


    protected Canvas createButton(final String title, final int moveType) {
        String url = GWT.getHostPageBaseURL() + title;

        ImgButton b = new ImgButton();
        b.setSrc(url);
        b.setHeight(BUTTON_HEIGHT);
        b.setWidth(40);
        b.setIconHeight(BUTTON_HEIGHT-10);
        b.setShowDown(false);
        b.setShowRollOver(false);
        b.setShowDisabled(false);
        b.setShowDisabledIcon(true);
        b.setShowDownIcon(false);
        b.setShowFocusedIcon(false);
        b.setBackgroundColor("f2f2f2");
        b.setBorder("1px solid #A6ABB4");

        b.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                fireOnMoveEvent(moveType);
            }
        });

        return b;
    }


    protected void addOnMoveHandler(OnMoveHandler handler) {
        if (handler != null) {
            handlers.add(handler);
        }
    }


    protected void fireOnMoveEvent(int type) {
        OnMoveEvent event = new OnMoveEvent(type);

        for (OnMoveHandler handler: handlers) {
            handler.onMove(event);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org