/** * Copyright 2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.bricket.plugin.galleriffic.web; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.wicket.RequestCycle; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.markup.html.CSSPackageResource; import org.apache.wicket.markup.html.JavascriptPackageResource; import org.apache.wicket.markup.html.WebComponent; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.model.StringResourceModel; import org.bricket.plugin.galleriffic.resources.GallerifficResourceReference; import org.bricket.plugin.galleriffic.resources.GallerifficStyleResourceReference; import org.bricket.plugin.galleriffic.resources.OpacityResourceReference; import org.bricket.plugin.picture.domain.Picture; import org.bricket.web.BricketApplication; import org.bricket.web.BricketDomReadyJavascriptBehaviour; import org.bricket.web.BricketPanel; import org.odlabs.wiquery.core.commons.CoreJavaScriptResourceReference; /** * Non pageable variant to display pictures by galleriffic. TODO pageable * variant * * @author Ingo Renner * @author Henning Teek * */ public class GallerifficPanel extends BricketPanel { private static final class GalleryListView extends ListView<Picture> { private GalleryListView(String id, List<? extends Picture> list) { super(id, list); } @Override protected void populateItem(ListItem<Picture> item) { final Picture picture = item.getModelObject(); final String thumbUri = ((BricketApplication) getApplication()).getThumbnailUrl(picture.getId(), RequestCycle.get()); final String layoutUri = ((BricketApplication) getApplication()).getLayoutUrl(picture.getId(), RequestCycle.get()); // anchor WebMarkupContainer wm = new WebMarkupContainer("anchor"); wm.add(new SimpleAttributeModifier("alt", picture.getFilename())); wm.add(new SimpleAttributeModifier("title", picture.getTitle())); wm.add(new SimpleAttributeModifier("name", picture.getId().toString())); wm.add(new SimpleAttributeModifier("href", layoutUri)); // Thumnail Img innerhalb anchor WebComponent wc = new WebComponent("thumb"); wc.add(new SimpleAttributeModifier("alt", picture.getTitle())); wc.add(new SimpleAttributeModifier("src", thumbUri)); wm.add(wc); item.add(wm); // caption text item.add(new Label("caption", picture.getDescription())); } } private final List<Picture> pictures; private final GallerifficConfig config; public GallerifficPanel(String id, GallerifficConfig gallerifficConfig, List<Picture> pictures) { super(id); this.pictures = pictures; this.config = gallerifficConfig; } @Override protected void initGui() { add(JavascriptPackageResource.getHeaderContribution(CoreJavaScriptResourceReference.get())); add(JavascriptPackageResource.getHeaderContribution(new GallerifficResourceReference())); add(JavascriptPackageResource.getHeaderContribution(new OpacityResourceReference())); add(CSSPackageResource.getHeaderContribution(new GallerifficStyleResourceReference())); // we need some id's so that we can have more than one GallerifficPanel // on one page final WebMarkupContainer controls = new WebMarkupContainer("controls"); controls.setOutputMarkupId(true); add(controls); final WebMarkupContainer loading = new WebMarkupContainer("loading"); loading.setOutputMarkupId(true); add(loading); final WebMarkupContainer slideshow = new WebMarkupContainer("slideshow"); slideshow.setOutputMarkupId(true); add(slideshow); final WebMarkupContainer caption = new WebMarkupContainer("caption"); caption.setOutputMarkupId(true); add(caption); final WebMarkupContainer thumbs = new WebMarkupContainer("thumbs"); thumbs.setOutputMarkupId(true); add(thumbs); thumbs.add(new GalleryListView("picturesview", pictures)); final Map<String, Object> vars = new HashMap<String, Object>(); // Component id's vars.put("controls", controls.getMarkupId()); vars.put("loading", loading.getMarkupId()); vars.put("slideshow", slideshow.getMarkupId()); vars.put("caption", caption.getMarkupId()); vars.put("thumbs", thumbs.getMarkupId()); // Translations vars.put("playLinkText", new StringResourceModel("playLinkText.label", GallerifficPanel.this, null).getString()); vars.put("pauseLinkText", new StringResourceModel("pauseLinkText.label", GallerifficPanel.this, null).getString()); vars.put("prevLinkText", new StringResourceModel("prevLinkText.label", GallerifficPanel.this, null).getString()); vars.put("nextLinkText", new StringResourceModel("nextLinkText.label", GallerifficPanel.this, null).getString()); vars.put("nextPageLinkText", new StringResourceModel("nextPageLinkText.label", GallerifficPanel.this, null).getString()); vars.put("prevPageLinkText", new StringResourceModel("prevPageLinkText.label", GallerifficPanel.this, null).getString()); // Tileconfig getConfig().fillIn(vars); // Add generated javascript config add(new BricketDomReadyJavascriptBehaviour(GallerifficPanel.class, "GallerifficPanel.js", vars)); } public GallerifficConfig getConfig() { return config; } }