/**
* 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.picture.web;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.panel.Panel;
import org.bricket.plugin.picture.domain.Picture;
import org.bricket.service.UncheckedRuntimeException;
import org.bricket.web.BricketApplication;
/**
* Simple way to display a picture without worrying about html and stuff.
*
* @author Ingo Renner
* @author Henning Teek
*
*/
public class SimplePicturePanel extends Panel {
private final PictureVariantType variant;
private final Picture picture;
public SimplePicturePanel(String id, final PictureVariantType variant, final Picture picture) {
super(id);
this.variant = variant;
this.picture = picture;
}
@Override
protected void onInitialize() {
super.onInitialize();
final String url;
final String css;
switch (variant) {
case THUMBNAIL:
url = ((BricketApplication) getApplication()).getThumbnailUrl(picture.getId(), RequestCycle.get());
css = "thumbnail";
break;
case PREVIEW:
url = ((BricketApplication) getApplication()).getPreviewUrl(picture.getId(), RequestCycle.get());
css = "preview";
break;
case LAYOUT:
url = ((BricketApplication) getApplication()).getLayoutUrl(picture.getId(), RequestCycle.get());
css = "layout";
break;
default:
throw new UncheckedRuntimeException("Unknown dimension " + variant);
}
final WebComponent wc = new WebComponent("pic");
wc.add(new SimpleAttributeModifier("alt", picture.getTitle()));
wc.add(new SimpleAttributeModifier("src", url));
wc.add(new SimpleAttributeModifier("class", css));
add(wc);
}
}