/**
* 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.multibox.web;
import java.util.Locale;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
/**
* @author Ingo Renner
* @author Henning Teek
*/
public final class MultiboxItemPanel extends Panel {
private String mbId;
private int itemId;
public MultiboxItemPanel(String wicketId, final int itemId, IModel<ImageObject> model, String mbId) {
super(wicketId, model);
this.mbId = mbId;
this.itemId = itemId;
}
@Override
protected void onBeforeRender() {
if (!hasBeenRendered()) {
initGui();
}
super.onBeforeRender();
}
private void initGui() {
ImageObject img = (ImageObject) getDefaultModelObject();
String mbItemId = mbId + "-" + itemId;
final String type = img.getImageFilename()
.substring(img.getImageFilename().lastIndexOf('.') + 1, img.getImageFilename().length())
.toLowerCase(Locale.getDefault());
WebMarkupContainer anchor = new WebMarkupContainer("imgprev");
anchor.setMarkupId(mbItemId);
anchor.setOutputMarkupId(true);
anchor.add(new AttributeModifier("href", true, new Model<String>(img.getImageFilename())));
anchor.add(new AttributeModifier("class", true, new Model<String>(mbId)));
anchor.add(new AttributeModifier("title", true, new Model<String>(img.getSub())));
anchor.add(new AttributeModifier("rel", true, new Model<String>("type:" + type + ",ajax:true,width:"
+ getXSize() + ",height:" + getYSize())));
add(anchor);
WebMarkupContainer thumb = new WebMarkupContainer("imgthumb");
thumb.setOutputMarkupId(true);
thumb.add(new AttributeModifier("src", true, new Model<String>(img.getThumbnailFilename())));
anchor.add(thumb);
add(new Label("desc", img.getDescription()).add(new AttributeModifier("class", true, new Model<String>(
"multiBoxDesc " + mbItemId))));
}
private int getXSize() {
return 640 + 22;
}
private int getYSize() {
return 480 + 16;
}
}