More work on the dynamic client side rendering + video display.

This commit is contained in:
Erik Forkalsrud 2011-03-19 23:58:42 -07:00
parent 2f5876a0e9
commit 9b584bd82e
14 changed files with 66 additions and 47 deletions

View file

@ -30,9 +30,11 @@ public class ComparatorFactory {
public int compare(Entry e1, Entry e2) { public int compare(Entry e1, Entry e2) {
if (!e1.isFile() && e2.isFile()) { boolean d1 = "dir".equals(e1.getType());
boolean d2 = "dir".equals(e2.getType());
if (d1 && !d2) {
return -1; return -1;
} else if (e1.isFile() && !e2.isFile()) { } else if (!d1 && d2) {
return +1; return +1;
} }
return 0; return 0;

View file

@ -146,7 +146,8 @@ public class DirectoryEntry extends EntryWithChildren<Entry> {
String name = key.substring("file.".length(), key.length() - ".dimensions".length()); String name = key.substring("file.".length(), key.length() - ".dimensions".length());
if (!entryMap.containsKey(name)) { if (!entryMap.containsKey(name)) {
File f = new File(file, name); File f = new File(file, name);
FileEntry entry = new FileEntry(this, f); String type = props.getProperty("file." + name + ".type", "image");
FileEntry entry = new FileEntry(this, f, type);
Thumbnail thumbnail = new Thumbnail(f); Thumbnail thumbnail = new Thumbnail(f);
entry.setCaption(props.getProperty("file." + name + ".caption")); entry.setCaption(props.getProperty("file." + name + ".caption"));
Date fileDate = sdf.parse(props.getProperty("file." + name + ".captureDate")); Date fileDate = sdf.parse(props.getProperty("file." + name + ".captureDate"));

View file

@ -85,7 +85,7 @@ public class DirectoryMetadataGenerator {
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) { if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) {
Map<String, String> p = generateThumbnailProperties(f); Map<String, String> p = generateThumbnailProperties(f);
addPropsForFile(props, f, p); addPropsForFile(props, f, p);
} else if (name.endsWith(".MOV") || name.endsWith(".mp4") || name.endsWith(".avi")) { } else if (name.endsWith(".mov") || name.endsWith(".MOV") || name.endsWith(".mp4") || name.endsWith(".avi")) {
Map<String, String> p = generateVideoProperties(f); Map<String, String> p = generateVideoProperties(f);
addPropsForFile(props, f, p); addPropsForFile(props, f, p);
} }

View file

@ -26,13 +26,15 @@ public abstract class Entry {
Entry next; Entry next;
Entry prev; Entry prev;
Entry parent; Entry parent;
String type;
protected Entry(File file) { protected Entry(File file, String type) {
this.file = file; this.file = file;
this.type = type;
} }
protected Entry(Entry other) { protected Entry(Entry other) {
this(other.file); this(other.file, other.type);
this.thumbnail = other.thumbnail; this.thumbnail = other.thumbnail;
this.caption = other.caption; this.caption = other.caption;
this.date = other.date; this.date = other.date;
@ -43,7 +45,9 @@ public abstract class Entry {
*/ */
} }
public abstract boolean isFile(); public String getType() {
return this.type;
}
/** /**

View file

@ -20,16 +20,9 @@ public class EntryWithChildren<T extends Entry> extends Entry {
} }
protected EntryWithChildren(File path) { protected EntryWithChildren(File path) {
super(path); super(path, "dir");
} }
/* (non-Javadoc)
* @see org.forkalsrud.album.exif.Entry#isFile()
*/
@Override
public boolean isFile() {
return false;
}
void fillLinkedList() { void fillLinkedList() {

View file

@ -12,18 +12,14 @@ import java.io.File;
public class FileEntry extends Entry { public class FileEntry extends Entry {
public FileEntry(Entry parent, File file) { public FileEntry(Entry parent, File file, String type) {
super(file); super(file, type);
if (!file.isFile()) { if (!file.isFile()) {
throw new RuntimeException("Use FileEntry only for files: " + file); throw new RuntimeException("Use FileEntry only for files: " + file);
} }
this.parent = parent; this.parent = parent;
} }
@Override
public boolean isFile() {
return true;
}
} }

View file

@ -35,7 +35,7 @@ public class SearchEngine {
tryAttribute(dir, dir.getPath().getAbsolutePath(), query); tryAttribute(dir, dir.getPath().getAbsolutePath(), query);
for (Entry e : dir.getContents()) { for (Entry e : dir.getContents()) {
if (!e.isFile()) { if ("dir".equals(e.getType())) {
queue.add((DirectoryEntry)e); queue.add((DirectoryEntry)e);
continue; continue;
} }

View file

@ -11,11 +11,6 @@ public class SearchEntry extends Entry {
this.score = 1; this.score = 1;
} }
@Override
public boolean isFile() {
return true;
}
public void addScore() { public void addScore() {
this.score += 1; this.score += 1;
} }

View file

@ -6,6 +6,9 @@ import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
@ -279,7 +282,7 @@ public class AlbumServlet
out.println(" {"); out.println(" {");
out.println(" \"name\": " + jsStr(e.getName()) + ","); out.println(" \"name\": " + jsStr(e.getName()) + ",");
out.println(" \"path\": " + jsStr(mapper.map(e.getThumbnail().getPath())) + ","); out.println(" \"path\": " + jsStr(mapper.map(e.getThumbnail().getPath())) + ",");
out.println(" \"type\": \"" + (e.isFile() ? "file" : "dir") + "\","); out.println(" \"type\": " + jsStr(e.getType()) + ",");
out.println(" \"width\": " + e.getThumbnail().getSize().getWidth() + ","); out.println(" \"width\": " + e.getThumbnail().getSize().getWidth() + ",");
out.println(" \"height\": " + e.getThumbnail().getSize().getHeight() + ","); out.println(" \"height\": " + e.getThumbnail().getSize().getHeight() + ",");
out.println(" \"caption\": " + jsStr(e.getCaption())); out.println(" \"caption\": " + jsStr(e.getCaption()));

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -12,7 +12,7 @@
<script type="text/javascript" src="assets/fancybox/jquery.fancybox-1.3.1.js"></script> <script type="text/javascript" src="assets/fancybox/jquery.fancybox-1.3.1.js"></script>
<script type="text/javascript" src="assets/fancybox/jquery.easing-1.3.pack.js"></script> <script type="text/javascript" src="assets/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="assets/fancybox/jquery.mousewheel-3.0.2.pack.js"></script> <script type="text/javascript" src="assets/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<!-- <script type="text/javascript" src="flowplayer/flowplayer-3.0.3.min.js"></script> --> <script type="text/javascript" src="assets/flowplayer/flowplayer-3.0.3.min.js"></script>
<link rel="stylesheet" href="assets/fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen" /> <link rel="stylesheet" href="assets/fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen" />
@ -87,9 +87,9 @@ $(function() {
function scale(w, h, max) { function scale(w, h, max) {
if (w > h) { if (w > h) {
return { w : Math.round(max), h: Math.round((max * h + max / 2) / w) }; return { w : Math.floor(max), h: Math.floor((max * h + max / 2) / w) };
} else { } else {
return { w: Math.round((max * w + max / 2) / h), h: Math.round(max) }; return { w: Math.floor((max * w + max / 2) / h), h: Math.floor(max) };
} }
} }
@ -104,7 +104,7 @@ $(function() {
var gridDiv = $("<div class=\"grid\">\n" var gridDiv = $("<div class=\"grid\">\n"
+ " <span class=\"name\">" + entry.name + "</span><br/>\n" + " <span class=\"name\">" + entry.name + "</span><br/>\n"
+ " <div class=\"imgborder\"><a class=\"ss\" href=\"album" + entry.path + "?size=800\" rel=\"album\" title=\"" + entry.name + "\">" + " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"album" + entry.path + "?size=800\" title=\"" + entry.name + "\">"
+ "<img class=\"picture\" src=\"album" + entry.path + "?size=250\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n" + "<img class=\"picture\" src=\"album" + entry.path + "?size=250\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
+ "<p id=\"" + entry.name + "\" class=\"caption\"></p>\n" + "<p id=\"" + entry.name + "\" class=\"caption\"></p>\n"
+ "</div>\n"); + "</div>\n");
@ -112,10 +112,11 @@ $(function() {
var element = gridDiv.filter("a.ss"); var element = gridDiv.filter("a.ss");
//$("<p>" + entry.type + "</p>").appendTo("#dbg");
switch (entry.type) { switch (entry.type) {
case "video": case "movie":
element.fancybox({ $("#ent" + idx).attr("rel", "album").attr("href", "raw/" + entry.name).fancybox({
'index' : idx,
'titlePosition' : 'inside', 'titlePosition' : 'inside',
'transitionIn' : 'elastic', 'transitionIn' : 'elastic',
'transitionOut' : 'elastic', 'transitionOut' : 'elastic',
@ -123,7 +124,7 @@ $(function() {
'easingOut' : 'easeOutQuad', 'easingOut' : 'easeOutQuad',
'titleFormat' : formatTitle, 'titleFormat' : formatTitle,
'padding' : 0, 'padding' : 0,
'href' : "flowplayer/flowplayer-3.0.3.swf", 'href' : "assets/flowplayer/flowplayer-3.0.3.swf",
'width' : entry.width, 'width' : entry.width,
'height' : entry.height, 'height' : entry.height,
'type' : 'swf', 'type' : 'swf',
@ -131,13 +132,13 @@ $(function() {
'allowfullscreen' : 'true', 'allowfullscreen' : 'true',
'wmode' : 'transparent', 'wmode' : 'transparent',
'flashvars': 'flashvars':
"config={ 'clip': { 'url': '" + escape(element.href) + "', 'provider': 'h264streaming' },\ "config={ 'clip': { 'url': 'raw/" + escape(entry.name) + "', 'provider': 'h264streaming' },\
'plugins': {\ 'plugins': {\
'h264streaming': {\ 'h264streaming': {\
'url': 'flowplayer/flowplayer.h264streaming-3.0.5.swf'\ 'url': 'assets/flowplayer/flowplayer.h264streaming-3.0.5.swf'\
},\ },\
'controls': {\ 'controls': {\
'url': 'flowplayer/flowplayer.controls-3.0.3.swf',\ 'url': 'assets/flowplayer/flowplayer.controls-3.0.3.swf',\
'backgroundColor': 'transparent', 'progressColor': 'transparent', 'bufferColor': 'transparent',\ 'backgroundColor': 'transparent', 'progressColor': 'transparent', 'bufferColor': 'transparent',\
'play':true,\ 'play':true,\
'fullscreen':true,\ 'fullscreen':true,\
@ -148,19 +149,19 @@ $(function() {
} }
}); });
break; break;
case "file": case "image":
element.fancybox({ var largeDim = scale(entry.width, entry.height, 800);
'index' : idx, $("#ent" + idx).attr("rel", "album").fancybox({
'titlePosition' : 'inside', 'titlePosition' : 'inside',
'transitionIn' : 'elastic', 'transitionIn' : 'elastic',
'transitionOut' : 'elastic', 'transitionOut' : 'elastic',
'easingIn' : 'easeInQuad', 'easingIn' : 'easeInQuad',
'easingOut' : 'easeOutQuad', 'easingOut' : 'easeOutQuad',
'titleFormat' : formatTitle, 'titleFormat' : formatTitle,
'width' : entry.width, 'width' : largeDim.w,
'height' : entry.height, 'height' : largeDim.h,
'type' : "image", 'type' : "image",
'href' : element.href 'href' : $("#ent" + idx).href
}); });
break; break;
} }