}
add(new Label("path", path));
- PhotoEntry current = authorized.getEntry(path);
- if (current instanceof Album) {
- throw new RuntimeException("PhotoPanel can only show a photo: " + current.getClass().getName());
- }
- final Photo photo = (Photo) current;
-
- String parentPath_ = path.substring(0, path.lastIndexOf("/"));
- if (parentPath_.length() == 0) {
- parentPath_ = "/";
- }
- final String parentPath = parentPath_;
- final Album parent = (Album) authorized.getEntry(parentPath);
- final Photo before = parent.findPhotoBefore(photo.getId());
- final Photo after = parent.findPhotoAfter(photo.getId());
+ String parentPath = getParentPath();
Link prevLink = new Link("prevLink") {
- {
- if (before == null) {
- setEnabled(false);
- }
- }
-
@Override
public void onClick() {
+ Photo before = getPrevPhoto();
if (before == null) {
return;
}
pars.put("path", before.getPath());
setResponsePage(HomePage.class, pars);
}
+
+ @Override
+ public boolean isEnabled() {
+ return getPrevPhoto() != null;
+ }
};
add(prevLink);
Link nextLink = new Link("nextLink") {
- {
- if (after == null) {
- setEnabled(false);
- }
- }
-
@Override
public void onClick() {
+ Photo after = getNextPhoto();
if (after == null) {
return;
}
pars.put("path", after.getPath());
setResponsePage(HomePage.class, pars);
}
+
+ @Override
+ public boolean isEnabled() {
+ return getNextPhoto() != null;
+ }
};
add(nextLink);
public void onClick() {
PageParameters pars = new PageParameters();
- pars.put("path", parentPath);
+ pars.put("path", getParentPath());
pars.put("index", 0);
setResponsePage(HomePage.class, pars);
}
add(parentLink);
- Image image = new Image("photo", new ByteArrayResource("image/jpeg", getData(photo)));
+ Image image = new Image("photo", new ByteArrayResource("image/jpeg", getData(getPhoto())));
add(image);
}
+ private Photo getPhoto() {
+ PhotoEntry current = authorized.getEntry(path);
+ if (current instanceof Album) {
+ throw new RuntimeException("PhotoPanel can only show a photo: " + current.getClass().getName());
+ }
+ return (Photo) current;
+ }
+
+ private Photo getPrevPhoto() {
+ return getAlbum().findPhotoBefore(getPhoto().getId());
+ }
+
+ private Photo getNextPhoto() {
+ return getAlbum().findPhotoAfter(getPhoto().getId());
+ }
+
+ private Album getAlbum() {
+ return (Album) getAuthorizedPhotos().getEntry(getParentPath());
+ }
+
+ private String getParentPath() {
+ String parentPath = path.substring(0, path.lastIndexOf("/"));
+ if (parentPath.length() == 0) {
+ parentPath = "/";
+ }
+ return parentPath;
+ }
+
private byte[] getData(Photo aPhoto) {
try (InputStream is = aPhoto.getPhoto()) {
return getBytes(is);
}
return bos.toByteArray();
}
+
+ private Album getAuthorizedPhotos() {
+ return authorized;
+ }
}
\ No newline at end of file