private static final Logger LOGGER = Logger.getLogger(AlbumPanel.class.getName());
private static final long serialVersionUID = 1L;
+ public static final int MAX_ROWS = 5;
+ public static final int MAX_COLUMNS = 5;
@Inject
@AuthorizedPhotos
}
private String path;
+ private int index;
/**
* Constructor that is invoked when page is invoked without a session.
info("Invalid album '" + path + "', showing root album instead");
path = "/";
}
+ add(new Label("path", path));
- PhotoEntry current = authorized.getEntry(path);
+ index = 0;
+ String indexString = parameters.getString("index", "0");
+ try {
+ index = Integer.parseInt(indexString);
+ }
+ catch (NumberFormatException e) {
+ // use default value 0
+ }
+ if (index < 0) {
+ index = 0;
+ }
+ PhotoEntry current = authorized.getEntry(path);
if (current instanceof Photo) {
throw new RuntimeException("AlbumPanel can only show album: " + current.getClass().getName());
}
+ final Album album = (Album) current;
- Album album = (Album) current;
+ Link prevLink = new Link("prevLink") {
+ {
+ if (index - MAX_ROWS * MAX_COLUMNS < 0) {
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ public void onClick() {
+ PageParameters pars = new PageParameters();
+ pars.put("path", path);
+ pars.put("index", index - MAX_ROWS * MAX_COLUMNS);
+ setResponsePage(HomePage.class, pars);
+ }
+ };
+ add(prevLink);
+
+ Link nextLink = new Link("nextLink") {
+ {
+ if (index + MAX_ROWS * MAX_COLUMNS >= album.size()) {
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ public void onClick() {
+ PageParameters pars = new PageParameters();
+ pars.put("path", path);
+ pars.put("index", index + MAX_ROWS * MAX_COLUMNS);
+ setResponsePage(HomePage.class, pars);
+ }
+ };
+ add(nextLink);
+
+ Link parentLink = new Link("parentLink") {
+ {
+ if ("/".equals(path)) {
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ public void onClick() {
+ PageParameters pars = new PageParameters();
+ String parentPath = path.substring(0, path.lastIndexOf("/"));
+ if (parentPath.length() == 0) {
+ parentPath = "/";
+ }
+ pars.put("path", parentPath);
+ pars.put("index", 0);
+ setResponsePage(HomePage.class, pars);
+ }
+ };
+ add(parentLink);
+
+ RepeatingView pageLinks = new RepeatingView("pageLinks");
+ add(pageLinks);
+ for (int i = 0; i < album.size() / MAX_ROWS / MAX_COLUMNS; i++) {
+ final int istart = i * MAX_ROWS * MAX_COLUMNS;
+ Link pageLink = new Link("pageLink") {
+ {
+ if (istart == index) {
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ public void onClick() {
+ PageParameters pars = new PageParameters();
+ pars.put("path", path);
+ pars.put("index", istart);
+ setResponsePage(HomePage.class, pars);
+ }
+ };
+ pageLink.add(new Label("label", i + ""));
+ pageLinks.add(pageLink);
+ WebMarkupContainer container = new WebMarkupContainer(pageLinks.newChildId());
+ container.add(pageLink);
+ pageLinks.add(container);
+ }
- int ientry = 0;
+ int ientry = index;
int irow = 0;
RepeatingView row = new RepeatingView("row");
add(row);
- while (irow < 5 && ientry < album.size()) {
+ while (irow < MAX_ROWS && ientry < album.size()) {
int icolumn = 0;
WebMarkupContainer columns = new WebMarkupContainer(row.newChildId());
row.add(columns);
RepeatingView column = new RepeatingView("column");
columns.add(column);
- while (icolumn < 5 && ientry < album.size()) {
+ while (icolumn < MAX_COLUMNS && ientry < album.size()) {
WebMarkupContainer thumbnail = new WebMarkupContainer(column.newChildId());
column.add(thumbnail);