ch.sebastienzurfluh.swissmuseum.parcours.client.view.bookletnavigator.BookletNavigator.java Source code

Java tutorial

Introduction

Here is the source code for ch.sebastienzurfluh.swissmuseum.parcours.client.view.bookletnavigator.BookletNavigator.java

Source

/*
 * Copyright 2012-2013 Sebastien Zurfluh
 * 
 * This file is part of "Parcours".
 * 
 * "Parcours" is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * "Parcours" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with "Parcours".  If not, see <http://www.gnu.org/licenses/>.
 */

package ch.sebastienzurfluh.swissmuseum.parcours.client.view.bookletnavigator;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.googlecode.mgwt.ui.client.widget.Carousel;
import com.googlecode.mgwt.ui.client.widget.LayoutPanel;

import ch.sebastienzurfluh.swissmuseum.core.client.control.eventbus.EventBus;
import ch.sebastienzurfluh.swissmuseum.core.client.model.Model;
import ch.sebastienzurfluh.swissmuseum.core.client.model.structure.MenuData;
import ch.sebastienzurfluh.swissmuseum.core.client.patterns.Observable;
import ch.sebastienzurfluh.swissmuseum.core.client.patterns.Observer;
import ch.sebastienzurfluh.swissmuseum.core.client.view.pagewidget.TextParser;

/**
 * The BookletNavigator listens to the changes in the set of pages in the current booklet and
 * display those in a magasine-like manner.
 *
 *
 * @author Sebastien Zurfluh
 *
 */
public class BookletNavigator extends LayoutPanel implements Observer {
    private Model model;
    private EventBus eventBus;

    private TextParser textParser;

    private Carousel carousel;

    public BookletNavigator(EventBus eventBus, Model model) {
        this.model = model;
        this.eventBus = eventBus;

        /**
         * We need only one parser for all the pages
         */
        this.textParser = new TextParser(eventBus, model);

        carousel = new InteractiveCarousel(eventBus, model);
        add(carousel);

        // Needed for the panel to show properly!
        this.setHeight(Window.getClientHeight() + "px");
        carousel.setHeight(Window.getClientHeight() + "px");

        model.allPagesMenusInCurrentGroupObservable.subscribeObserver(this);
    }

    @Override
    public void notifyObserver(Observable source) {
        carousel.clear();
        carousel.add(new ReturnToHomeAnimation());
        for (MenuData menuData : model.getAllPageMenusInCurrentGroup()) {
            LoadOnDemandPageWidget page = new LoadOnDemandPageWidget(menuData, eventBus, model, textParser);
            carousel.add(page);
        }
        carousel.add(new ReturnToHomeAnimation());
    }

    class ReturnToHomeAnimation extends SimplePanel {

        public ReturnToHomeAnimation() {
            SimplePanel innerPanel = new SimplePanel(new Image("resources/images/generic_tiles/logo_parcours.png"));

            innerPanel.setStyleName("page-logoCentered");

            this.setStyleName("page-logoContainer");
            this.setHeight(Window.getClientHeight() + "px");

            this.setWidget(innerPanel);
        }
    }
}