All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.wicketslides.SlidesPanel Maven / Gradle / Ivy

package com.googlecode.wicketslides;

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

import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;

/**
 * This class provide a almost-out-of-the-box wicket Panel with a smoothgallery
 * in it. What is missing are Mootools resources cause they should be added
 * outside the panel.
 * 
 * To add the Mootools javascript resources just make:
 * 
 * 
 *  add(JavascriptPackageResource.getHeaderContribution(WicketSlides.MOOTOOLS));
 *  add(JavascriptPackageResource.getHeaderContribution(WicketSlides.MOOTOOLS_MORE));
 * 
 * 
 * 
 * in a parent container of the SlidesPanel instance.
 * 
 * @author ildella
 * 
 */
public class SlidesPanel extends Panel {

   private List imageList;
   private List thumbList;
   private Boolean thumbs;
   private Integer width;
   private Integer height;
   private String useHistoryManager;
   private Integer thumbWidth;
   private Integer thumbHeight;
   private Boolean timed;
   private Integer fadeDuration;
   private Integer delay;
   private Boolean showArrow;
   private Boolean embedLinks;
   private Boolean showInfoPane;

   private SlidesPanel(final String id) {
      super(id);
   }

   private void processPanel() {

      add(CSSPackageResource.getHeaderContribution(WicketSlides.LAYOUT_CSS));
      add(CSSPackageResource.getHeaderContribution(WicketSlides.JD_GALLERY_CSS));
      add(JavascriptPackageResource.getHeaderContribution(WicketSlides.JD_GALLERY));

      add(new HeaderContributor(new IHeaderContributor() {
         @Override
         public void renderHead(final IHeaderResponse response) {
            response.renderString("");
         }
      }));
      add(new HeaderContributor(new IHeaderContributor() {

         @Override
         public void renderHead(final IHeaderResponse response) {
            response.renderOnDomReadyJavascript("" + "var myGallery = new gallery($('myGallery'), {" + "timed: "
                  + timed + ", " + "fadeDuration: " + fadeDuration + ", " + "delay: " + delay + ", "
                  + "useHistoryManager: " + useHistoryManager + "," + "thumbWidth: " + thumbWidth + ", "
                  + "thumbHeight: " + thumbHeight + ", " + "showInfopane: " + showInfoPane + ", " + "embedLinks: "
                  + embedLinks + ", " + "thumbCloseCarousel: true, " + "showCarouselLabel: true, "
                  + "textShowCarousel: 'Pictures', " + "showArrows: " + showArrow + ", " + "showCarousel: " + thumbs
                  + " " + "});" + (thumbs ? "myGallery.showCarousel();" : "") + "HistoryManager.start();");
         }

      }));

      final ListView listview = new ListView("imageElement", imageList) {

         @Override
         protected void populateItem(final ListItem item) {
            loader.populate(item);
         }

      };

      add(listview);

   }

   private ImageLoader loader;

   public static class Builder {
      private final String id;
      private List imageList = new ArrayList(1);
      private List thumbList = new ArrayList(1);
      private Boolean thumbs = false;
      private Integer width = 480;
      private Integer height = 360;
      private Integer thumbWidth = 48;
      private Integer thumbHeight = 36;
      private Boolean timed = false;
      private Integer fadeDuration = 600;
      private Integer delay = 6000;
      private Boolean showArrow = true;
      private final Boolean embedLinks = true;
      private final Boolean showInfoPane = true;
      private ImageLoader loader = new ImageLoader();
      private Boolean useHistoryManager = Boolean.FALSE;

      public Builder(final String id) {
         this.id = id;
      }

      public SlidesPanel build() {
         final SlidesPanel panel = new SlidesPanel(id);
         panel.imageList = imageList;
         panel.thumbList = thumbList;
         panel.thumbs = thumbs;
         panel.width = width;
         panel.height = height;
         panel.thumbWidth = thumbWidth;
         panel.thumbHeight = thumbHeight;
         panel.useHistoryManager = useHistoryManager.toString();
         panel.timed = timed;
         panel.fadeDuration = fadeDuration;
         panel.delay = delay;
         panel.showArrow = showArrow;
         panel.embedLinks = embedLinks;
         panel.showInfoPane = showInfoPane;
         panel.loader = loader;
         if (thumbs == null) {
            if (thumbList.contains(null) || imageList.size() != thumbList.size()) {
               panel.thumbs = false;
            } else if (imageList.size() == thumbList.size()) {
               panel.thumbs = true;
            }
         }

         panel.processPanel();
         return panel;
      }

      public Builder showThumbs(final Boolean showThumbs) {
         if (showThumbs == null) {
            thumbs = false;
         }
         thumbs = showThumbs;
         return this;
      }

      public Builder thumbList(final List thumbList) {
         if (thumbList == null || thumbList.isEmpty()) {
            thumbs = false;
         }
         this.thumbList = thumbList;
         return this;
      }

      public Builder size(final Integer width, final Integer height) {
         if (width == null || height == null) {
            throw new IllegalArgumentException("Either provide both width and height, or don't call size() at all");
         }
         this.width = width;
         this.height = height;
         return this;
      }

      public Builder thumbSize(final Integer width, final Integer height) {
         if (width == null || height == null) {
            throw new IllegalArgumentException("Either provide both width and height, or don't call size() at all");
         }
         thumbWidth = width;
         thumbHeight = height;
         return this;
      }

      public Builder timed(final Boolean timed) {
         this.timed = timed;
         return this;
      }

      public Builder showArrow(final Boolean showArrow) {
         this.showArrow = showArrow;
         return this;
      }

      public Builder fadeDuration(final Integer fadeDuration) {
         this.fadeDuration = fadeDuration;
         return this;
      }

      public Builder delay(final Integer delay) {
         this.delay = delay;
         return this;
      }

      public Builder historyManager(final boolean useHistoryManager) {
         this.useHistoryManager = useHistoryManager;
         return this;
      }

      public Builder addImage(final String imageUrl, final String thumbUrl) {
         imageList.add(imageUrl);
         thumbList.add(thumbUrl);
         return this;
      }

      public Builder addImage(final String imageUrl) {
         imageList.add(imageUrl);
         return this;
      }

      public Builder addImageList(final List listImagesUrl) {
         imageList = listImagesUrl;
         return this;
      }

      public Builder addThumbList(final List listThumbsUrl) {
         thumbList = listThumbsUrl;
         return this;
      }

      public Builder loadImageWith(final ImageLoader loader) {
         this.loader = loader;
         return this;
      }

      public void addImage(final SlideshowImage mainImage, final SlideshowImage thumbImag2) {
         imageList.add(mainImage);
         thumbList.add(thumbImag2);
      }

   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy