From: Erik Brakkee Date: Sun, 22 Sep 2013 19:32:37 +0000 (+0200) Subject: Page navigation is now working. X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=7cecbacb4d7ff41c801d53303eefa965df572f2b;p=photos Page navigation is now working. --- diff --git a/src/main/java/org/wamblee/photos/wicket/AlbumPanel.html b/src/main/java/org/wamblee/photos/wicket/AlbumPanel.html index 345b619..5b6011b 100644 --- a/src/main/java/org/wamblee/photos/wicket/AlbumPanel.html +++ b/src/main/java/org/wamblee/photos/wicket/AlbumPanel.html @@ -12,6 +12,22 @@ Message here. +
diff --git a/src/main/java/org/wamblee/photos/wicket/AlbumPanel.java b/src/main/java/org/wamblee/photos/wicket/AlbumPanel.java index 093ed15..57e95c7 100644 --- a/src/main/java/org/wamblee/photos/wicket/AlbumPanel.java +++ b/src/main/java/org/wamblee/photos/wicket/AlbumPanel.java @@ -42,6 +42,8 @@ public class AlbumPanel extends Panel { 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 @@ -67,6 +69,7 @@ public class AlbumPanel extends Panel { } private String path; + private int index; /** * Constructor that is invoked when page is invoked without a session. @@ -81,26 +84,118 @@ public class AlbumPanel extends Panel { 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); diff --git a/src/main/java/org/wamblee/photos/wicket/HomePage.html b/src/main/java/org/wamblee/photos/wicket/HomePage.html index e110290..dcd6266 100644 --- a/src/main/java/org/wamblee/photos/wicket/HomePage.html +++ b/src/main/java/org/wamblee/photos/wicket/HomePage.html @@ -10,7 +10,6 @@ - Message here. Content diff --git a/src/main/java/org/wamblee/photos/wicket/HomePage.java b/src/main/java/org/wamblee/photos/wicket/HomePage.java index 0a55e86..a5d42fa 100644 --- a/src/main/java/org/wamblee/photos/wicket/HomePage.java +++ b/src/main/java/org/wamblee/photos/wicket/HomePage.java @@ -20,7 +20,6 @@ import java.util.logging.Logger; import javax.inject.Inject; import org.apache.wicket.PageParameters; -import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.Link; import org.wamblee.photos.model.Album; import org.wamblee.photos.model.Photo; @@ -89,8 +88,6 @@ public class HomePage extends BasePage { path = "/"; } - add(new Label("message", "Hello world!")); - System.out.println("Currently logged in user: " + user); List usernames = userAdmin.getUsers(); diff --git a/src/main/java/org/wamblee/photos/wicket/photos.css b/src/main/java/org/wamblee/photos/wicket/photos.css index 4c08bef..df80436 100644 --- a/src/main/java/org/wamblee/photos/wicket/photos.css +++ b/src/main/java/org/wamblee/photos/wicket/photos.css @@ -69,12 +69,20 @@ ul.feedbackPanel { margin-top: 1em; } -#content em { - display: block; +#navigation h1 { + font-size: 1.3em; + font-weight: bold; +} + +#navigation h1 .path { + font-style: oblique; +} + +#navigation em, #navigation a { margin-bottom: 0px; font-style: normal; - font-weight: bold; - font-size: 24px; + font-size: small; + font-family: sans-serif; } #photos th, #content td {