Various cleanups as recommended by FindBug

This commit is contained in:
2018-09-16 20:58:07 +01:00
parent c74de99835
commit eade8ef47d
5 changed files with 36 additions and 58 deletions

View File

@@ -171,7 +171,7 @@ public class AudiobookRecorder extends JFrame {
toolsOptions = new JMenuItem("Options"); toolsOptions = new JMenuItem("Options");
toolsOptions.addActionListener(new ActionListener() { toolsOptions.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Options o = new Options(AudiobookRecorder.this); new Options(AudiobookRecorder.this);
} }
}); });
@@ -580,7 +580,7 @@ public class AudiobookRecorder extends JFrame {
} }
AudiobookRecorder frame = new AudiobookRecorder(); new AudiobookRecorder();
} }
public void createNewBook() { public void createNewBook() {
@@ -758,7 +758,6 @@ public class AudiobookRecorder extends JFrame {
Sentence s = (Sentence)o.getObject(); Sentence s = (Sentence)o.getObject();
if (!s.isLocked()) { if (!s.isLocked()) {
s.deleteFiles(); s.deleteFiles();
Chapter c = (Chapter)s.getParent();
bookTreeModel.removeNodeFromParent(s); bookTreeModel.removeNodeFromParent(s);
} }
} }
@@ -1628,8 +1627,10 @@ public class AudiobookRecorder extends JFrame {
play.write(data, 0, data.length); play.write(data, 0, data.length);
} }
s = (Sentence)next; s = (Sentence)next;
if (s != null) {
bookTree.setSelectionPath(new TreePath(s.getPath())); bookTree.setSelectionPath(new TreePath(s.getPath()));
} }
}
} catch (Exception e) { } catch (Exception e) {
playing = null; playing = null;
} }
@@ -1651,7 +1652,6 @@ public class AudiobookRecorder extends JFrame {
if (len == 0) return null; if (len == 0) return null;
AudioFormat f = roomNoise.getAudioFormat(); AudioFormat f = roomNoise.getAudioFormat();
int frameSize = f.getFrameSize();
float sr = f.getSampleRate(); float sr = f.getSampleRate();

View File

@@ -3,23 +3,23 @@ package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.*;
public class Icons { public class Icons {
static public ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png")); static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
static public ImageIcon chapter = new ImageIcon(Icons.class.getResource("icons/chapter.png")); static public final ImageIcon chapter = new ImageIcon(Icons.class.getResource("icons/chapter.png"));
static public ImageIcon sentence = new ImageIcon(Icons.class.getResource("icons/sentence.png")); static public final ImageIcon sentence = new ImageIcon(Icons.class.getResource("icons/sentence.png"));
static public ImageIcon play = new ImageIcon(Icons.class.getResource("icons/play.png")); static public final ImageIcon play = new ImageIcon(Icons.class.getResource("icons/play.png"));
static public ImageIcon playon = new ImageIcon(Icons.class.getResource("icons/playon.png")); static public final ImageIcon playon = new ImageIcon(Icons.class.getResource("icons/playon.png"));
static public ImageIcon stop = new ImageIcon(Icons.class.getResource("icons/stop.png")); static public final ImageIcon stop = new ImageIcon(Icons.class.getResource("icons/stop.png"));
static public ImageIcon record = new ImageIcon(Icons.class.getResource("icons/record.png")); static public final ImageIcon record = new ImageIcon(Icons.class.getResource("icons/record.png"));
static public ImageIcon openBook = new ImageIcon(Icons.class.getResource("icons/open.png")); static public final ImageIcon openBook = new ImageIcon(Icons.class.getResource("icons/open.png"));
static public ImageIcon newBook = new ImageIcon(Icons.class.getResource("icons/new.png")); static public final ImageIcon newBook = new ImageIcon(Icons.class.getResource("icons/new.png"));
static public ImageIcon newChapter = new ImageIcon(Icons.class.getResource("icons/new-chapter.png")); static public final ImageIcon newChapter = new ImageIcon(Icons.class.getResource("icons/new-chapter.png"));
static public ImageIcon recordRoom = new ImageIcon(Icons.class.getResource("icons/record-room.png")); static public final ImageIcon recordRoom = new ImageIcon(Icons.class.getResource("icons/record-room.png"));
static public ImageIcon save = new ImageIcon(Icons.class.getResource("icons/save.png")); static public final ImageIcon save = new ImageIcon(Icons.class.getResource("icons/save.png"));
static public ImageIcon redo = new ImageIcon(Icons.class.getResource("icons/redo.png")); static public final ImageIcon redo = new ImageIcon(Icons.class.getResource("icons/redo.png"));
static public ImageIcon fft = new ImageIcon(Icons.class.getResource("icons/fft.png")); static public final ImageIcon fft = new ImageIcon(Icons.class.getResource("icons/fft.png"));
static public ImageIcon peak = new ImageIcon(Icons.class.getResource("icons/peak.png")); static public final ImageIcon peak = new ImageIcon(Icons.class.getResource("icons/peak.png"));
static public ImageIcon locked = new ImageIcon(Icons.class.getResource("icons/locked.png")); static public final ImageIcon locked = new ImageIcon(Icons.class.getResource("icons/locked.png"));
static public ImageIcon appIcon = new ImageIcon(Icons.class.getResource("icons/appIcon.png")); static public final ImageIcon appIcon = new ImageIcon(Icons.class.getResource("icons/appIcon.png"));
static public ImageIcon star = new ImageIcon(Icons.class.getResource("icons/star.png")); static public final ImageIcon star = new ImageIcon(Icons.class.getResource("icons/star.png"));
} }

View File

@@ -14,20 +14,6 @@ public class OpenBookPanel extends JPanel {
JTable table; JTable table;
class BookInfo {
public String name;
public String author;
public String genre;
public String comment;
public BookInfo(String n, String a, String g, String c) {
name = n;
author = a;
genre = g;
comment = c;
}
}
public class BookCellRenderer implements TableCellRenderer { public class BookCellRenderer implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) return null; if (value == null) return null;
@@ -96,7 +82,9 @@ public class OpenBookPanel extends JPanel {
try { try {
File dir = new File(Options.get("path.storage")); File dir = new File(Options.get("path.storage"));
if (dir.exists() && dir.isDirectory()) {
for (File b : dir.listFiles()) { for (File b : dir.listFiles()) {
if (b == null) continue;
if (!b.isDirectory()) continue; if (!b.isDirectory()) continue;
File xml = new File(b, "audiobook.abk"); File xml = new File(b, "audiobook.abk");
if (xml.exists()) { if (xml.exists()) {
@@ -104,6 +92,7 @@ public class OpenBookPanel extends JPanel {
model.addBook(book); model.addBook(book);
} }
} }
}
table = new JTable(model); table = new JTable(model);

View File

@@ -322,16 +322,14 @@ public class Options extends JDialog {
boolean supported = false; boolean supported = false;
Line l;
try { try {
l = m.getLine(stereoDIF); m.getLine(stereoDIF);
supported = true; supported = true;
} catch (Exception e) { } catch (Exception e) {
} }
try { try {
l = m.getLine(monoDIF); m.getLine(monoDIF);
supported = true; supported = true;
} catch (Exception e) { } catch (Exception e) {
} }
@@ -360,16 +358,14 @@ public class Options extends JDialog {
boolean supported = false; boolean supported = false;
Line l;
try { try {
l = m.getLine(stereoDIF); m.getLine(stereoDIF);
supported = true; supported = true;
} catch (Exception e) { } catch (Exception e) {
} }
try { try {
l = m.getLine(monoDIF); m.getLine(monoDIF);
supported = true; supported = true;
} catch (Exception e) { } catch (Exception e) {
} }

View File

@@ -63,11 +63,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
false false
); );
if (format == null) {
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Sample format not supported", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
Mixer.Info mixer = Options.getRecordingMixer(); Mixer.Info mixer = Options.getRecordingMixer();
line = null; line = null;
@@ -418,7 +413,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
try { try {
AudioInputStream s = AudioSystem.getAudioInputStream(f); AudioInputStream s = AudioSystem.getAudioInputStream(f);
AudioFormat format = s.getFormat(); AudioFormat format = s.getFormat();
long len = s.getFrameLength();
int frameSize = format.getFrameSize(); int frameSize = format.getFrameSize();
s.skip(frameSize * startOffset); s.skip(frameSize * startOffset);
@@ -447,7 +441,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
try { try {
AudioInputStream s = AudioSystem.getAudioInputStream(f); AudioInputStream s = AudioSystem.getAudioInputStream(f);
AudioFormat format = s.getFormat(); AudioFormat format = s.getFormat();
long len = s.getFrameLength();
int frameSize = format.getFrameSize(); int frameSize = format.getFrameSize();
updateCrossings(); updateCrossings();