📄 abxdialog.java
字号:
package abchr.gui;
import abchr.*;
import abchr.audio.PlaybackThread;
import abchr.audio.Sample;
import guiutils.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class ABXDialog extends JDialog {
private ABXModule abxModule;
private PlaybackThread playbackThread=PlaybackThread.getInstance();
private ABXTest currentTest=null;
private JComboBox aComboBox=new JComboBox();
private JComboBox bComboBox=new JComboBox();
private JRadioButton trainingRadioButton;
private JRadioButton testingRadioButton;
private boolean trainingMode;
private ABXControlPanel abxPanel;
private ABXResultsPanel resultsPanel;
private ABXListener listener=new ABXListener() {
public void changed(ABXTest source) {
if(trainingMode) {
resultsPanel.setTest(currentTest);
} else {
updateLabels();
}
}
};
private NameWrapper[] samples;
private PlaybackRangeSelectBar rangeBar;
private TimeLineModule timeLineModule;
private SavedRangesModule savedRangesModule;
private ComponentGroup testingGroup=new ComponentGroup();
private boolean comboBoxesInited=false;
private JLabel trialsCompletedLabel;
private JLabel correctNeededLabel;
public ABXDialog(Frame owner,ABXModule abxModule) {
super(owner,"ABX",false);
this.abxModule=abxModule;
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){stop();}
});
if(abxModule!=null){setModule(abxModule);}
aComboBox.setEditable(false);
bComboBox.setEditable(false);
ActionListener l=new ActionListener() {
public void actionPerformed(ActionEvent e){comboBoxSelect();}
};
aComboBox.addActionListener(l);
bComboBox.addActionListener(l);
JPanel setupPanel=new JPanel(new LineLayout());
setupPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Setup"),
BorderFactory.createEmptyBorder(5,5,5,5)
));
setupPanel.add(new JLabel("Sample A:"));
setupPanel.add(aComboBox);
setupPanel.add(LineLayout.lineBreak());
setupPanel.add(new JLabel("Sample B:"));
setupPanel.add(bComboBox);
setupPanel.add(LineLayout.lineBreak());
ButtonGroup modeGroup=new ButtonGroup();
trainingRadioButton=new JRadioButton("Training Mode");
ActionListener listener=new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(trainingRadioButton.isSelected()==trainingMode){return;}
setMode(trainingRadioButton.isSelected());
}
};
trainingRadioButton.addActionListener(listener);
testingRadioButton=new JRadioButton("Testing Mode");
testingRadioButton.addActionListener(listener);
modeGroup.add(trainingRadioButton);
modeGroup.add(testingRadioButton);
setupPanel.add(trainingRadioButton);
setupPanel.add(testingRadioButton);
setupPanel.add(LineLayout.lineBreak());
JLabel completedLabel=new JLabel("Completed: ");
testingGroup.add(completedLabel);
setupPanel.add(completedLabel);
trialsCompletedLabel=new JLabel("0");
testingGroup.add(trialsCompletedLabel);
setupPanel.add(trialsCompletedLabel);
setupPanel.add(LineLayout.lineBreak());
JLabel neededLabel=new JLabel("Correct Trials Needed: ");
testingGroup.add(neededLabel);
setupPanel.add(neededLabel);
correctNeededLabel=new JLabel("--");
testingGroup.add(correctNeededLabel);
setupPanel.add(correctNeededLabel);
setupPanel.add(LineLayout.lineBreak());
JButton resetButton=new JButton("Reset");
testingGroup.add(resetButton);
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){reset();}
});
setupPanel.add(resetButton);
JButton finishButton=new JButton("Finish");
testingGroup.add(finishButton);
finishButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){finish();}
});
setupPanel.add(finishButton);
trainingRadioButton.setSelected(true);
testingGroup.setEnabled(false);
JPanel centerPanel=new JPanel(new FlexibleGridLayout(10,3,10,5,true));
centerPanel.add(setupPanel);
abxPanel=new ABXControlPanel();
abxPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"ABX"),
BorderFactory.createEmptyBorder(5,5,5,5)
));
centerPanel.add(abxPanel);
resultsPanel=new ABXResultsPanel(false);
resultsPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Results"),
BorderFactory.createEmptyBorder(5,5,5,5)
));
centerPanel.add(resultsPanel);
Container contentPane=this.getContentPane();
JPanel contentPanel=new JPanel(new BorderLayout());
contentPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
contentPanel.add(centerPanel,BorderLayout.CENTER);
RangeSelectBarPanel rangePanel=new RangeSelectBarPanel();
rangeBar=rangePanel.getRangeBar();
contentPanel.add(rangePanel,BorderLayout.SOUTH);
contentPane.add(contentPanel);
}
private void updateLabels() {
int n=currentTest.getNumTrials();
trialsCompletedLabel.setText(Integer.toString(n));
if(ABXTestImpl.pVal(n,n)>=abxModule.getPValThreshold()) {
correctNeededLabel.setText("--");
} else {
int i=n;
while(ABXTestImpl.pVal(n,i)<abxModule.getPValThreshold() && i>0){i--;}
correctNeededLabel.setText(Integer.toString(i+1));
}
}
private void finish() {
resultsPanel.setTest(currentTest);
abxModule.setFinished(aComboBox.getSelectedIndex(),bComboBox.getSelectedIndex(),true);
abxPanel.setTest(null);
testingGroup.setEnabled(false);
}
private void reset() {
if(!trainingMode) {
abxModule.resetTest(aSample,bSample);
}
setMode(trainingMode);
}
private Sample aSample,bSample;
private void setMode(boolean training) {
trainingMode=training;
if(trainingMode==true) {
ABXTest abxTest=new ABXTestImpl(aSample,bSample);
ListenableABXTest labxTest=new ListenableABXTest(abxTest);
labxTest.addListener(listener);
abxPanel.setTest(labxTest);
resultsPanel.setTest(null);
testingGroup.setEnabled(false);
currentTest=labxTest;
} else {
/*if(!abxModule.isFinished(aComboBox.getSelectedIndex(),bComboBox.getSelectedIndex())) {
abxModule.resetTest(aSample,bSample);
}*/
ABXTest test=abxModule.getTest(aSample,bSample);
ListenableABXTest abxTest=new ListenableABXTest(test);
abxTest.addListener(listener);
if(abxModule.isFinished(aComboBox.getSelectedIndex(),bComboBox.getSelectedIndex())) {
abxPanel.setTest(null);
testingGroup.setEnabled(false);
resultsPanel.setTest(abxTest);
} else {
abxPanel.setTest(abxTest,aSample,bSample);
testingGroup.setEnabled(true);
resultsPanel.setTest(null);
}
currentTest=abxTest;
updateLabels();
}
}
public ABXDialog(Frame owner){this(owner,null);}
private void stop(){playbackThread.stopPlayback();}
private void comboBoxSelect() {
int aIndex=aComboBox.getSelectedIndex();
int bIndex=bComboBox.getSelectedIndex();
if(aIndex!=-1 && bIndex!=-1 && aIndex!=bIndex) {
//if(aIndex>bIndex){aComboBox.setSelectedIndex(bIndex);bComboBox.setSelectedIndex(aIndex);}
aSample=(Sample)((NameWrapper)aComboBox.getSelectedItem()).getObject();
bSample=(Sample)((NameWrapper)bComboBox.getSelectedItem()).getObject();
trainingRadioButton.setEnabled(true);
testingRadioButton.setEnabled(true);
setMode(true);
trainingRadioButton.setSelected(true);
} else {
aSample=null;bSample=null;
trainingRadioButton.setEnabled(false);
testingRadioButton.setEnabled(false);
testingGroup.setEnabled(false);
abxPanel.setTest(null);
currentTest=null;
}
resultsPanel.setTest(currentTest);
}
public void show() {
playbackThread.stopPlayback();
rangeBar.setModel(timeLineModule.getRangeModel());
rangeBar.setPosMarker(playbackThread.getPosMarker());
rangeBar.setSavedRanges(savedRangesModule.getSavedRanges());
Dimension size=getContentPane().getPreferredSize();
Insets insets=getOwner().getInsets();
this.setBounds(this.getOwner().getX()+20,this.getOwner().getY()+20,size.width+insets.left+insets.right,size.height+insets.top+insets.bottom);
initComboBoxes();
super.show();
}
private void initComboBoxes() {
if(comboBoxesInited){return;}
if(abxModule==null){return;}
SampleConfigModule sampleConfig=abxModule.getSampleConfig();
if(sampleConfig==null){return;}
samples=new NameWrapper[sampleConfig.getSampleCount()+1];
samples[0]=new NameWrapper("Original",sampleConfig.getOriginalSample());
for(int i=0;i<sampleConfig.getSampleCount();i++){samples[i+1]=new NameWrapper("Sample "+(i+1),sampleConfig.getSample(i));}
aComboBox.setModel(new DefaultComboBoxModel(samples));
bComboBox.setModel(new DefaultComboBoxModel(samples));
comboBoxSelect();
comboBoxesInited=true;
}
public void setModule(ABXModule abxModule) {
this.abxModule=abxModule;
comboBoxesInited=false;
}
public void setTimeLineModule(TimeLineModule timeLineModule) {
this.timeLineModule=timeLineModule;
}
public void setSavedRangesModule(SavedRangesModule savedRangesModule) {
this.savedRangesModule=savedRangesModule;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -