package org.apache.wicket.examples.linkomatic;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.wicket.Component;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ClientSideImageMap;
import org.apache.wicket.markup.html.link.DownloadLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.link.PopupSettings;
import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.markup.html.pages.RedirectPage;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.INamedParameters;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.SharedResourceReference;
import org.apache.wicket.util.file.Files;
import org.apache.wicket.util.time.Duration;
@author
public class Home extends WicketExamplePage
{
private int linkClickCount = 0;
private int onClickLinkClickCount = 0;
public Home()
{
final Link actionLink = new Link("actionLink")
{
@Override
public void onClick()
{
linkClickCount++;
}
};
actionLink.add(new Label("linkClickCount", new PropertyModel<Integer>(this,
"linkClickCount")));
add(actionLink);
final Link actionOnClickLink = new Link("actionOnClickLink")
{
@Override
public void onClick()
{
onClickLinkClickCount++;
}
};
add(actionOnClickLink);
add(new Label("onClickLinkClickCount", new PropertyModel<Integer>(this,
"onClickLinkClickCount")));
add(new BookmarkablePageLink<>("page1Link", Page1.class));
BookmarkablePageLink<Void> page3Link = new BookmarkablePageLink<>("page3Link", Page3.class);
page3Link.getPageParameters()
.add("bookmarkparameter", "3++2 & 5 � >< space + �");
add(page3Link);
add(new Link<Void>("bookDetailsLink")
{
@Override
public void onClick()
{
setResponsePage(new BookDetails(new Book("The Hobbit")));
}
});
add(new Link<Void>("bookDetailsLink2")
{
@Override
public void onClick()
{
setResponsePage(new BookDetails(new Book("Inside The Matrix")));
}
});
Image imageForMap = new Image("imageForMap", new PackageResourceReference(Home.class,
"ImageMap.gif"));
add(imageForMap);
add(new ClientSideImageMap("imageMap", imageForMap).addRectangleArea(
new BookmarkablePageLink<Page1>("page1", Page1.class), 0, 0, 100, 100)
.addCircleArea(new BookmarkablePageLink<Page2>("page2", Page2.class), 160, 50, 35)
.addPolygonArea(new BookmarkablePageLink<Page3>("page3", Page3.class), 212, 79, 241, 4,
279, 54, 212, 79)
.add(RelativePathPrefixHandler.RELATIVE_PATH_BEHAVIOR));
PopupSettings popupSettings = new PopupSettings("popuppagemap").setHeight(500)
.setWidth(500);
add(new BookmarkablePageLink<>("popupLink", Popup.class).setPopupSettings(popupSettings));
add(new BookmarkablePageLink<>("popupButtonLink", Popup.class).setPopupSettings(popupSettings));
add(new ExternalLink("google", "http://www.google.com", "Click this link to go to Google"));
PopupSettings googlePopupSettings = new PopupSettings(PopupSettings.RESIZABLE |
PopupSettings.SCROLLBARS).setHeight(500).setWidth(700);
add(new ExternalLink("googlePopup", "http://www.google.com",
"Click this link to go to Google in a popup").setPopupSettings(googlePopupSettings));
add(new ResourceLink<>("cancelButtonLink", new SharedResourceReference("cancelButton")));
add(new DownloadLink("downloadLink", new AbstractReadOnlyModel<File>()
{
private static final long serialVersionUID = 1L;
@Override
public File getObject()
{
File tempFile;
try
{
tempFile = File.createTempFile("wicket-examples-download-link--", ".tmp");
InputStream data = new ByteArrayInputStream("some data".getBytes());
Files.writeTo(tempFile, data);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
return tempFile;
}
}, "Downlöad\"here now.tmp").setCacheDuration(Duration.NONE).setDeleteAfterDownload(true));
FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
add(feedbackPanel);
add(new RedirectForm("redirectForm"));
Link linkToAnchor = new Link("linkToAnchor")
{
@Override
public void onClick()
{
}
};
add(linkToAnchor);
Link anotherlinkToAnchor = new Link("anotherlinkToAnchor")
{
@Override
public void onClick()
{
}
};
add(anotherlinkToAnchor);
Component anchorLabel = new Label("anchorLabel",
"this label is here to function as an anchor for a link").setOutputMarkupId(true);
add(anchorLabel);
linkToAnchor.setAnchor(anchorLabel);
Link<Void> linkWithLabel = new Link<Void>("linkWithLabel")
{
@Override
public void onClick()
{
}
};
linkWithLabel.setBody(Model.of("A link that provides its body with Link.setBody(someModel)"));
add(linkWithLabel);
}
private final class RedirectForm extends Form<RedirectForm>
{
private String redirectUrl = "http://www.theserverside.com";
@param
public RedirectForm(String id)
{
super(id);
setDefaultModel(new CompoundPropertyModel<>(this));
add(new TextField<>("redirectUrl"));
}
@see
@Override
protected void onSubmit()
{
setResponsePage(new RedirectPage(redirectUrl));
}
@return
public String getRedirectUrl()
{
return redirectUrl;
}
@param
public void setRedirectUrl(String redirectUrl)
{
this.redirectUrl = redirectUrl;
}
}
@return
public int getLinkClickCount()
{
return linkClickCount;
}
@param
public void setLinkClickCount(final int linkClickCount)
{
this.linkClickCount = linkClickCount;
}
@return
public int getOnClickLinkClickCount()
{
return onClickLinkClickCount;
}
@param
public void setOnClickLinkClickCount(int onClickLinkClickCount)
{
this.onClickLinkClickCount = onClickLinkClickCount;
}
@see
@Override
public boolean isVersioned()
{
return false;
}
}