Custom buttons with no focus
This commit is contained in:
@@ -362,13 +362,15 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JToolBar controlsLeft = new JToolBar(JToolBar.VERTICAL);
|
JToolBar controlsLeft = new JToolBar(JToolBar.VERTICAL);
|
||||||
JToolBar controlsRight = new JToolBar(JToolBar.VERTICAL);
|
JToolBar controlsRight = new JToolBar(JToolBar.VERTICAL);
|
||||||
|
|
||||||
|
controlsTop.setFloatable(false);
|
||||||
controlsLeft.setFloatable(false);
|
controlsLeft.setFloatable(false);
|
||||||
controlsRight.setFloatable(false);
|
controlsRight.setFloatable(false);
|
||||||
|
|
||||||
controlsLeft.add(reprocessAudioFFT);
|
controlsLeft.add(reprocessAudioFFT);
|
||||||
controlsLeft.add(reprocessAudioPeak);
|
controlsLeft.add(reprocessAudioPeak);
|
||||||
|
|
||||||
locked = new JCheckBox("Sentence locked");
|
locked = new JCheckBox("Phrase locked");
|
||||||
|
locked.setFocusable(false);
|
||||||
|
|
||||||
locked.addActionListener(new ActionListener() {
|
locked.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -634,7 +636,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
JPopupMenu menu = new JPopupMenu();
|
JPopupMenu menu = new JPopupMenu();
|
||||||
JMenuObject rec = new JMenuObject("Recognise text from audio", s);
|
JMenuObject rec = new JMenuObject("Recognise text from audio", s);
|
||||||
JMenu moveMenu = new JMenu("Move sentence to...");
|
JMenu moveMenu = new JMenu("Move phrase to...");
|
||||||
|
|
||||||
for (Enumeration c = book.children(); c.hasMoreElements();) {
|
for (Enumeration c = book.children(); c.hasMoreElements();) {
|
||||||
Chapter chp = (Chapter)c.nextElement();
|
Chapter chp = (Chapter)c.nextElement();
|
||||||
@@ -680,8 +682,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
JMenuObject ins = new JMenuObject("Insert sentence above", s);
|
JMenuObject ins = new JMenuObject("Insert phrase above", s);
|
||||||
JMenuObject del = new JMenuObject("Delete sentence", s);
|
JMenuObject del = new JMenuObject("Delete phrase", s);
|
||||||
|
|
||||||
|
|
||||||
ins.addActionListener(new ActionListener() {
|
ins.addActionListener(new ActionListener() {
|
||||||
@@ -741,8 +743,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JMenuObject moveUp = new JMenuObject("Move Up", c);
|
JMenuObject moveUp = new JMenuObject("Move Up", c);
|
||||||
JMenuObject moveDown = new JMenuObject("Move Down", c);
|
JMenuObject moveDown = new JMenuObject("Move Down", c);
|
||||||
JMenu mergeWith = new JMenu("Merge chapter with");
|
JMenu mergeWith = new JMenu("Merge chapter with");
|
||||||
JMenuObject lockAll = new JMenuObject("Lock all sentences", c);
|
JMenuObject lockAll = new JMenuObject("Lock all phrases", c);
|
||||||
JMenuObject unlockAll = new JMenuObject("Unlock all sentences", c);
|
JMenuObject unlockAll = new JMenuObject("Unlock all phrases", c);
|
||||||
JMenuObject exportChapter = new JMenuObject("Export chapter", c);
|
JMenuObject exportChapter = new JMenuObject("Export chapter", c);
|
||||||
JMenuObject deleteChapter = new JMenuObject("Delete chapter", c);
|
JMenuObject deleteChapter = new JMenuObject("Delete chapter", c);
|
||||||
|
|
||||||
|
|||||||
21
src/uk/co/majenko/audiobookrecorder/JButtonSpacePlay.java
Normal file
21
src/uk/co/majenko/audiobookrecorder/JButtonSpacePlay.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class JButtonSpacePlay extends JButton {
|
||||||
|
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
super(i);
|
||||||
|
getInputMap(JComponent.WHEN_FOCUSED).put(
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
|
||||||
|
"startPlayback"
|
||||||
|
);
|
||||||
|
|
||||||
|
setToolTipText(tt);
|
||||||
|
addActionListener(al);
|
||||||
|
setFocusPainted(false);
|
||||||
|
setFocusable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class JToggleButtonSpacePlay extends JToggleButton {
|
||||||
|
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
super(i);
|
||||||
|
getInputMap(JComponent.WHEN_FOCUSED).put(
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
|
||||||
|
"startPlayback"
|
||||||
|
);
|
||||||
|
|
||||||
|
setToolTipText(tt);
|
||||||
|
addActionListener(al);
|
||||||
|
setFocusPainted(false);
|
||||||
|
setFocusable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,15 +7,15 @@ import java.awt.event.*;
|
|||||||
|
|
||||||
public class MainToolBar extends JToolBar {
|
public class MainToolBar extends JToolBar {
|
||||||
|
|
||||||
JButton newBook;
|
JButtonSpacePlay newBook;
|
||||||
JButton openBook;
|
JButtonSpacePlay openBook;
|
||||||
JButton saveBook;
|
JButtonSpacePlay saveBook;
|
||||||
JButton newChapter;
|
JButtonSpacePlay newChapter;
|
||||||
JButton recordRoomNoise;
|
JButtonSpacePlay recordRoomNoise;
|
||||||
JButton playSentence;
|
JButtonSpacePlay playSentence;
|
||||||
JButton playonSentence;
|
JButtonSpacePlay playonSentence;
|
||||||
JButton stopPlaying;
|
JButtonSpacePlay stopPlaying;
|
||||||
JButton eq;
|
JButtonSpacePlay eq;
|
||||||
JToggleButton mic;
|
JToggleButton mic;
|
||||||
|
|
||||||
AudiobookRecorder root;
|
AudiobookRecorder root;
|
||||||
@@ -25,27 +25,21 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
root = r;
|
root = r;
|
||||||
|
|
||||||
newBook = new JButton(Icons.newBook);
|
newBook = new JButtonSpacePlay(Icons.newBook, "New Book", new ActionListener() {
|
||||||
newBook.setToolTipText("New Book");
|
|
||||||
newBook.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.createNewBook();
|
root.createNewBook();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(newBook);
|
add(newBook);
|
||||||
|
|
||||||
openBook = new JButton(Icons.openBook);
|
openBook = new JButtonSpacePlay(Icons.openBook, "Open Book", new ActionListener() {
|
||||||
openBook.setToolTipText("Open Book");
|
|
||||||
openBook.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.openBook();
|
root.openBook();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(openBook);
|
add(openBook);
|
||||||
|
|
||||||
saveBook = new JButton(Icons.save);
|
saveBook = new JButtonSpacePlay(Icons.save, "Save Book", new ActionListener() {
|
||||||
saveBook.setToolTipText("Save Book");
|
|
||||||
saveBook.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.saveBookStructure();
|
root.saveBookStructure();
|
||||||
}
|
}
|
||||||
@@ -54,18 +48,14 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
newChapter = new JButton(Icons.newChapter);
|
newChapter = new JButtonSpacePlay(Icons.newChapter, "New Chapter", new ActionListener() {
|
||||||
newChapter.setToolTipText("New Chapter");
|
|
||||||
newChapter.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.addChapter();
|
root.addChapter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(newChapter);
|
add(newChapter);
|
||||||
|
|
||||||
recordRoomNoise = new JButton(Icons.recordRoom);
|
recordRoomNoise = new JButtonSpacePlay(Icons.recordRoom, "Record Room Noise", new ActionListener() {
|
||||||
recordRoomNoise.setToolTipText("Record Room Noise");
|
|
||||||
recordRoomNoise.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.recordRoomNoise();
|
root.recordRoomNoise();
|
||||||
}
|
}
|
||||||
@@ -74,27 +64,21 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
playSentence = new JButton(Icons.play);
|
playSentence = new JButtonSpacePlay(Icons.play, "Play sentence", new ActionListener() {
|
||||||
playSentence.setToolTipText("Play sentence");
|
|
||||||
playSentence.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.playSelectedSentence();
|
root.playSelectedSentence();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(playSentence);
|
add(playSentence);
|
||||||
|
|
||||||
playonSentence = new JButton(Icons.playon);
|
playonSentence = new JButtonSpacePlay(Icons.playon, "Play from sentence", new ActionListener() {
|
||||||
playonSentence.setToolTipText("Play from sentence");
|
|
||||||
playonSentence.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.playFromSelectedSentence();
|
root.playFromSelectedSentence();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(playonSentence);
|
add(playonSentence);
|
||||||
|
|
||||||
stopPlaying = new JButton(Icons.stop);
|
stopPlaying = new JButtonSpacePlay(Icons.stop, "Stop playing", new ActionListener() {
|
||||||
stopPlaying.setToolTipText("Stop playing / recording");
|
|
||||||
stopPlaying.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.stopPlaying();
|
root.stopPlaying();
|
||||||
}
|
}
|
||||||
@@ -102,9 +86,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
add(stopPlaying);
|
add(stopPlaying);
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
eq = new JButton(Icons.eq);
|
eq = new JButtonSpacePlay(Icons.eq, "Equaliser", new ActionListener() {
|
||||||
eq.setToolTipText("Equaliser");
|
|
||||||
eq.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.showEqualiser();
|
root.showEqualiser();
|
||||||
}
|
}
|
||||||
@@ -114,9 +96,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
mic = new JToggleButton(Icons.mic);
|
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
||||||
mic.setToolTipText("Enable/disable microphone");
|
|
||||||
mic.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JToggleButton b = (JToggleButton)e.getSource();
|
JToggleButton b = (JToggleButton)e.getSource();
|
||||||
if (b.isSelected()) {
|
if (b.isSelected()) {
|
||||||
|
|||||||
@@ -558,10 +558,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
playing = true;
|
playing = true;
|
||||||
while ((pos < crossEndOffset * frameSize) && playing) {
|
while ((pos < crossEndOffset * frameSize) && playing) {
|
||||||
|
AudiobookRecorder.window.sampleWaveform.setPlayMarker(pos / frameSize);
|
||||||
int nr = eq.read(buffer);
|
int nr = eq.read(buffer);
|
||||||
pos += nr;
|
pos += nr;
|
||||||
|
|
||||||
AudiobookRecorder.window.sampleWaveform.setPlayMarker(pos / frameSize);
|
|
||||||
|
|
||||||
play.write(buffer, 0, nr);
|
play.write(buffer, 0, nr);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user