Add book length

This commit is contained in:
2020-02-09 15:02:12 +00:00
parent 43b0ccd96d
commit 785a4f1b7b
5 changed files with 22 additions and 2 deletions
@@ -710,4 +710,21 @@ public class Book extends BookTreeNode {
} }
return cleanName.toString(); return cleanName.toString();
} }
@Override
public double getLength() {
Debug.trace();
double len = 0;
for (Enumeration o = children(); o.hasMoreElements();) {
Object ob = (Object)o.nextElement();
if (ob instanceof Chapter) {
Chapter c = (Chapter)ob;
len += c.getLength();
len += (c.getPreGap() / 1000d);
len += (c.getPostGap() / 1000d);
}
}
return len;
}
} }
@@ -14,8 +14,8 @@ public abstract class BookTreeNode extends DefaultMutableTreeNode {
public abstract void setNotes(String t); public abstract void setNotes(String t);
public abstract String getNotes(); public abstract String getNotes();
public abstract void onSelect(BookTreeNode target); public abstract void onSelect(BookTreeNode target);
public abstract Book getBook(); public abstract Book getBook();
public abstract double getLength();
} }
@@ -181,7 +181,7 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
ret.setIcon(b.getIcon()); ret.setIcon(b.getIcon());
p.add(ret, ctx); p.add(ret, ctx);
JLabel author = new JLabel(b.getAuthor()); JLabel author = new JLabel(b.getAuthor() + " - " + Utils.secToTime(b.getLength(), "HH:mm:ss"));
ctx.gridy++; ctx.gridy++;
author.setBorder(new EmptyBorder(0, 27, 0, 0)); author.setBorder(new EmptyBorder(0, 27, 0, 0));
Font f = author.getFont(); Font f = author.getFont();
@@ -383,6 +383,7 @@ public class Chapter extends BookTreeNode {
} }
} }
@Override
public double getLength() { public double getLength() {
Debug.trace(); Debug.trace();
double len = 0; double len = 0;
@@ -391,6 +392,7 @@ public class Chapter extends BookTreeNode {
if (ob instanceof Sentence) { if (ob instanceof Sentence) {
Sentence s = (Sentence)ob; Sentence s = (Sentence)ob;
len += s.getLength(); len += s.getLength();
len += (s.getPostGap() / 1000d);
} }
} }
return len; return len;
@@ -817,6 +817,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
} }
/* Get the length of the sample in seconds */ /* Get the length of the sample in seconds */
@Override
public double getLength() { public double getLength() {
Debug.trace(); Debug.trace();
if (runtime > 0.01d) return runtime; if (runtime > 0.01d) return runtime;