Add lock and unlock all #15

This commit is contained in:
2018-09-23 15:42:16 +01:00
parent ae22c8c86d
commit c591025b4f
5 changed files with 35 additions and 1 deletions

View File

@@ -796,6 +796,8 @@ public class AudiobookRecorder extends JFrame {
JMenuObject moveUp = new JMenuObject("Move Up", c);
JMenuObject moveDown = new JMenuObject("Move Down", c);
JMenu mergeWith = new JMenu("Merge chapter with");
JMenuObject lockAll = new JMenuObject("Lock all sentences", c);
JMenuObject unlockAll = new JMenuObject("Unlock all sentences", c);
for (Enumeration<Chapter> bc = book.children(); bc.hasMoreElements();) {
Chapter chp = bc.nextElement();
@@ -878,6 +880,30 @@ public class AudiobookRecorder extends JFrame {
}
});
lockAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
for (Enumeration<Sentence> s = c.children(); s.hasMoreElements();) {
Sentence snt = s.nextElement();
snt.setLocked(true);
bookTreeModel.reload(snt);
}
}
});
unlockAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
for (Enumeration<Sentence> s = c.children(); s.hasMoreElements();) {
Sentence snt = s.nextElement();
snt.setLocked(false);
bookTreeModel.reload(snt);
}
}
});
menu.add(moveUp);
menu.add(moveDown);
@@ -887,6 +913,9 @@ public class AudiobookRecorder extends JFrame {
menu.addSeparator();
menu.add(peak);
menu.addSeparator();
menu.add(lockAll);
menu.add(unlockAll);
menu.show(bookTree, e.getX(), e.getY());
}

View File

@@ -14,6 +14,8 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
if (s.isLocked()) {
ret.setForeground(new Color(0x20, 0x00, 0x00));
ret.setIcon(Icons.locked);
} else if (s.getStartOffset() == 0) {
ret.setIcon(Icons.important);
} else {
ret.setIcon(Icons.sentence);
}

View File

@@ -21,5 +21,6 @@ public class Icons {
static public final ImageIcon locked = new ImageIcon(Icons.class.getResource("icons/locked.png"));
static public final ImageIcon appIcon = new ImageIcon(Icons.class.getResource("icons/appIcon.png"));
static public final ImageIcon star = new ImageIcon(Icons.class.getResource("icons/star.png"));
static public final ImageIcon important = new ImageIcon(Icons.class.getResource("icons/important.png"));
}

View File

@@ -121,7 +121,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
storedAudioData = null;
if (!id.equals("room-noise")) {
autoTrimSampleFFT();
autoTrimSamplePeak();
if (Options.getBoolean("process.sphinx")) {
recognise();
}
@@ -574,6 +574,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
public void clearCache() {
storedAudioData = null;
System.gc();
}
public boolean lockedInCache() {
@@ -582,6 +583,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
public int findNearestZeroCrossing(int pos, int range) {
int[] data = getAudioData();
if (data == null) return 0;
if (pos < 0) pos = 0;
if (pos >= data.length) pos = data.length-1;