Page navigation is now working.
authorErik Brakkee <erik@brakkee.org>
Sun, 22 Sep 2013 19:32:37 +0000 (21:32 +0200)
committerErik Brakkee <erik@brakkee.org>
Sun, 22 Sep 2013 19:32:37 +0000 (21:32 +0200)
src/main/java/org/wamblee/photos/wicket/AlbumPanel.html
src/main/java/org/wamblee/photos/wicket/AlbumPanel.java
src/main/java/org/wamblee/photos/wicket/HomePage.html
src/main/java/org/wamblee/photos/wicket/HomePage.java
src/main/java/org/wamblee/photos/wicket/photos.css

index 345b619b5257cfe08987b97a7ecb9ea6add41f32..5b6011b6c794dc5cf04ea349b697e5ec13d55b8b 100644 (file)
 <span wicket:id="message">Message here.</span>
 
 <wicket:panel>
+    <div id="navigation">
+        <h1>Now viewing album <span class="path" wicket:id="path">/phot/entry/xxx</span></h1>
+        Click on an album or photo to start
+        <br/>
+        <br/>
+        <a href="#" wicket:id="prevLink">Prev</a>
+        &nbsp; &nbsp;
+        <span wicket:id="pageLinks">
+            <a href="#" wicket:id="pageLink"><span wicket:id="label">pageno</span></a>
+        </span>
+        &nbsp; &nbsp;
+        <a href="#" wicket:id="nextLink">Next</a>
+        <a href="#" wicket:id="parentLink">Parent</a>
+        <br/>
+        <br/>
+    </div>
     <div id="photos">
         <table>
             <tr wicket:id="row">
index 093ed15644faf3b8aaef9c91093dedebdf2d3abc..57e95c7983f11c796580976935612ec23096321e 100644 (file)
@@ -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);
 
index e110290d91ab9bcb206790aba28b240c48f56370..dcd6266aa9c583dd2449648ba36f602ffa3b45cc 100644 (file)
@@ -10,7 +10,6 @@
 
 <wicket:extend>
 
-    <span wicket:id="message">Message here.</span>
 
     <span wicket:id="content">Content</span>
 
index 0a55e869c56cac75a824584ac5c073dda930b14e..a5d42faaa194aa655e12545e9a85f121a353c474 100644 (file)
@@ -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<String> usernames = userAdmin.getUsers();
index 4c08befdd724f8ca741395e15c27fc9c4d861a38..df80436018f16adb770e335faf73980595aced6c 100644 (file)
@@ -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 {