Optimized record deny and keyboard intercept
This commit is contained in:
@@ -36,6 +36,7 @@ import java.awt.event.AdjustmentEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -681,95 +682,45 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
centralPanel.getActionMap().put("startRecord", new AbstractAction() {
|
centralPanel.getActionMap().put("startRecord", new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (!canStartRecording()) return;
|
||||||
if (!getLock()) return;
|
if (!getLock()) return;
|
||||||
if (getFocusOwner() == bookNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == chapterNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == sentenceNotesArea) { freeLock(); return; }
|
|
||||||
if (bookTree.isEditing()) {
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getBook().getNoiseFloor() == 0) {
|
|
||||||
freeLock();
|
|
||||||
alertNoRoomNoise();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startRecording();
|
startRecording();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
centralPanel.getActionMap().put("startRecordShort", new AbstractAction() {
|
centralPanel.getActionMap().put("startRecordShort", new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (!canStartRecording()) return;
|
||||||
if (!getLock()) return;
|
if (!getLock()) return;
|
||||||
if (getFocusOwner() == bookNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == chapterNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == sentenceNotesArea) { freeLock(); return; }
|
|
||||||
if (bookTree.isEditing()) {
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getBook().getNoiseFloor() == 0) {
|
|
||||||
freeLock();
|
|
||||||
alertNoRoomNoise();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startRecordingShort();
|
startRecordingShort();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
centralPanel.getActionMap().put("startRecordNewPara", new AbstractAction() {
|
centralPanel.getActionMap().put("startRecordNewPara", new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (!canStartRecording()) return;
|
||||||
if (!getLock()) return;
|
if (!getLock()) return;
|
||||||
if (getFocusOwner() == bookNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == chapterNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == sentenceNotesArea) { freeLock(); return; }
|
|
||||||
if (bookTree.isEditing()) {
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getBook().getNoiseFloor() == 0) {
|
|
||||||
alertNoRoomNoise();
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startRecordingNewParagraph();
|
startRecordingNewParagraph();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
centralPanel.getActionMap().put("startRecordNewSection", new AbstractAction() {
|
centralPanel.getActionMap().put("startRecordNewSection", new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (!canStartRecording()) return;
|
||||||
if (!getLock()) return;
|
if (!getLock()) return;
|
||||||
if (getFocusOwner() == bookNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == chapterNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == sentenceNotesArea) { freeLock(); return; }
|
|
||||||
if (bookTree.isEditing()) {
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getBook().getNoiseFloor() == 0) {
|
|
||||||
freeLock();
|
|
||||||
alertNoRoomNoise();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startRecordingNewSection();
|
startRecordingNewSection();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
centralPanel.getActionMap().put("startRerecord", new AbstractAction() {
|
centralPanel.getActionMap().put("startRerecord", new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (!canStartRecording()) return;
|
||||||
if (!getLock()) return;
|
if (!getLock()) return;
|
||||||
if (getFocusOwner() == bookNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == chapterNotesArea) { freeLock(); return; }
|
|
||||||
if (getFocusOwner() == sentenceNotesArea) { freeLock(); return; }
|
|
||||||
if (bookTree.isEditing()) {
|
|
||||||
freeLock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getBook().getNoiseFloor() == 0) {
|
|
||||||
freeLock();
|
|
||||||
alertNoRoomNoise();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
startReRecording();
|
startReRecording();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -834,6 +785,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
mainScroll.setViewportView(bookTree);
|
mainScroll.setViewportView(bookTree);
|
||||||
bookTree.setEditable(true);
|
bookTree.setEditable(true);
|
||||||
|
|
||||||
|
for (KeyListener kl : bookTree.getListeners(KeyListener.class)) {
|
||||||
|
bookTree.removeKeyListener(kl);
|
||||||
|
}
|
||||||
|
|
||||||
TreeCellRenderer renderer = new BookTreeRenderer();
|
TreeCellRenderer renderer = new BookTreeRenderer();
|
||||||
try {
|
try {
|
||||||
bookTree.setCellRenderer(renderer);
|
bookTree.setCellRenderer(renderer);
|
||||||
@@ -1038,6 +993,27 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean canStartRecording() {
|
||||||
|
if (getFocusOwner() == bookNotesArea) { return false; }
|
||||||
|
if (getFocusOwner() == chapterNotesArea) { return false; }
|
||||||
|
if (getFocusOwner() == sentenceNotesArea) { return false; }
|
||||||
|
if (bookTree.isEditing()) { return false; }
|
||||||
|
if (getBook() == null) {
|
||||||
|
JOptionPane.showMessageDialog(AudiobookRecorder.window, "No book selected. Select a book to record.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Microphone.getDevice() == null) {
|
||||||
|
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Microphone not started. Start the microphone first.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getBook().getNoiseFloor() == 0) {
|
||||||
|
alertNoRoomNoise();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void bindKeys(JComponent component) {
|
void bindKeys(JComponent component) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F"), "startRecordShort");
|
component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F"), "startRecordShort");
|
||||||
|
|||||||
@@ -995,6 +995,8 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void backup() throws IOException {
|
public void backup() throws IOException {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (getFile() == null) return;
|
||||||
|
if (!getFile().exists()) return;
|
||||||
File whereto = getFile().getParentFile();
|
File whereto = getFile().getParentFile();
|
||||||
String name = getFile().getName();
|
String name = getFile().getName();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user