package org.autoplot.asdatasource;
import java.awt.Window;
import java.util.List;
import java.util.Map;
import javax.swing.JPanel;
import org.das2.util.monitor.ProgressMonitor;
import org.autoplot.datasource.DataSourceEditorPanel;
import org.autoplot.datasource.URISplit;
/**
*
* @author jbf
*/
public class AudioSystemDataSourceEditorPanel extends javax.swing.JPanel implements DataSourceEditorPanel {
/**
* Creates new form AudioSystemDataSourceEditorPanel
*/
public AudioSystemDataSourceEditorPanel() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
jLabel1 = new javax.swing.JLabel();
lenTF = new javax.swing.JFormattedTextField();
fftCB = new javax.swing.JCheckBox();
fftLenComboBox = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
samplingRateCB = new javax.swing.JComboBox<>();
jLabel4 = new javax.swing.JLabel();
jLabel1.setText("Sample Length, Seconds:");
lenTF.setText("1.0");
fftCB.setText("Perform FFT");
fftLenComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "128", "256", "512", "1024" }));
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, fftCB, org.jdesktop.beansbinding.ELProperty.create("${selected}"), fftLenComboBox, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
jLabel2.setText("FFT Length:");
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, fftCB, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jLabel2, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
jLabel3.setText("Sampling Rate (1/Seconds):");
samplingRateCB.setEditable(true);
samplingRateCB.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "8000", "16000", "32000", "64000" }));
jLabel4.setFont(jLabel4.getFont().deriveFont(jLabel4.getFont().getSize()+2f));
jLabel4.setText("A computer's audio system often provides a nice source for data.");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fftLenComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lenTF, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(fftCB)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(samplingRateCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(lenTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fftCB)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(fftLenComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(samplingRateCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(123, Short.MAX_VALUE))
);
bindingGroup.bind();
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox fftCB;
private javax.swing.JComboBox fftLenComboBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JFormattedTextField lenTF;
private javax.swing.JComboBox samplingRateCB;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration//GEN-END:variables
@Override
public boolean reject(String uri) throws Exception {
boolean allowDiscovery= false;
return allowDiscovery;
}
@Override
public boolean prepare(String uri, Window parent, ProgressMonitor mon) throws Exception {
return true;
}
@Override
public void setURI(String uri) {
URISplit split= URISplit.parse(uri);
Map params= URISplit.parseParams(split.params);
String len= params.get("len");
if ( len!=null ) {
this.lenTF.setValue(Float.parseFloat(len));
} else {
this.lenTF.setValue(1.0f);
}
String fft= params.get("spec");
this.fftCB.setSelected(fft!=null);
if ( fft!=null ) {
this.fftLenComboBox.setSelectedItem(fft);
}
String s= params.get("rate");
if ( s!=null ) {
this.samplingRateCB.setSelectedItem(s);
}
}
@Override
public void markProblems(List problems) {
}
@Override
public JPanel getPanel() {
return this;
}
@Override
public String getURI() {
String result= "vap+audiosystem:len="+this.lenTF.getValue();
if ( fftCB.isSelected() ) {
result= result+"&spec="+fftLenComboBox.getSelectedItem();
}
if ( !samplingRateCB.getSelectedItem().equals("8000") ) {
result= result+"&rate="+samplingRateCB.getSelectedItem();
}
return result;
}
}