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

View File

@@ -710,4 +710,21 @@ public class Book extends BookTreeNode {
}
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;
}
}

View File

@@ -14,8 +14,8 @@ public abstract class BookTreeNode extends DefaultMutableTreeNode {
public abstract void setNotes(String t);
public abstract String getNotes();
public abstract void onSelect(BookTreeNode target);
public abstract Book getBook();
public abstract double getLength();
}

View File

@@ -181,7 +181,7 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
ret.setIcon(b.getIcon());
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++;
author.setBorder(new EmptyBorder(0, 27, 0, 0));
Font f = author.getFont();

View File

@@ -383,6 +383,7 @@ public class Chapter extends BookTreeNode {
}
}
@Override
public double getLength() {
Debug.trace();
double len = 0;
@@ -391,6 +392,7 @@ public class Chapter extends BookTreeNode {
if (ob instanceof Sentence) {
Sentence s = (Sentence)ob;
len += s.getLength();
len += (s.getPostGap() / 1000d);
}
}
return len;

View File

@@ -817,6 +817,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
/* Get the length of the sample in seconds */
@Override
public double getLength() {
Debug.trace();
if (runtime > 0.01d) return runtime;