Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #115 (SED Stacker GUI norm params not binding correctly.) #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* and open the template in the editor.
*/

/* TODO: cleanup unused code for binding the Y-unit values to the integration
* Y-unit dropdown menu
*/
package cfa.vo.sed.science.stacker;

import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -73,7 +76,14 @@ public void setIntegrate(boolean integrate) {
this.integrate = integrate;
propertyChangeSupport.firePropertyChange(PROP_INTEGRATE, oldIntegrate, integrate);
// disable Y value text box if not normalizing at a point and using "Value" for the statistic.
setAtPointYTextEnabled(false);
if (this.integrate) {
setAtPointYTextEnabled(false);
if(this.stats.equals("Value")) {
setIntegrateYTextEnabled(true);
}
} else {
setIntegrateYTextEnabled(false);
}
}

private transient final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
Expand Down Expand Up @@ -166,6 +176,12 @@ public void setStats(String stats) {
String oldStats = this.stats;
this.stats = stats;
propertyChangeSupport.firePropertyChange(PROP_STATS, oldStats, stats);
// disable Y value text box if not normalizing at a point and using "Value" for the statistic.
if (this.stats.equals("Value") && this.integrate) {
setIntegrateYTextEnabled(true);
} else {
setIntegrateYTextEnabled(false);
}
}

private Double yValue = 1.0;
Expand Down Expand Up @@ -363,6 +379,7 @@ public void setAtPointStats(String atPointStats) {
// disable Y value text box if not normalizing at a point and using "Value" for the statistic.
if (atPointStats.equals("Value") && this.atPoint) {
setAtPointYTextEnabled(true);
setIntegrateYTextEnabled(false);
} else {
setAtPointYTextEnabled(false);
}
Expand Down Expand Up @@ -415,8 +432,11 @@ public void setAtPoint(boolean atPoint) {
this.atPoint = atPoint;
propertyChangeSupport.firePropertyChange(PROP_ATPOINT, oldAtPoint, atPoint);
// disable Y value text box if not normalizing at a point and using "Value" for the statistic.
if (this.atPoint && this.atPointStats.equals("Value")) {
setAtPointYTextEnabled(true);
if (this.atPoint) {
setIntegrateYTextEnabled(false);
if (this.atPointStats.equals("Value")) {
setAtPointYTextEnabled(true);
}
} else {
setAtPointYTextEnabled(false);
}
Expand Down Expand Up @@ -460,6 +480,21 @@ public void setAtPointYTextEnabled(boolean atPointYTextEnabled) {
this.atPointYTextEnabled = atPointYTextEnabled;
propertyChangeSupport.firePropertyChange(PROP_ATPOINTYTEXTENABLED, oldAtPointYTextEnabled, atPointYTextEnabled);
}

private boolean integrateYTextEnabled = true;

public static final String PROP_INTEGRATEYTEXTENABLED = "integrateYTextEnabled";

public boolean isIntegrateYTextEnabled() {
return integrateYTextEnabled;
}

// used to disable Y value text box if using Average or Median.
public void setIntegrateYTextEnabled(boolean integrateYTextEnabled) {
boolean oldIntegrateYTextEnabled = this.integrateYTextEnabled;
this.integrateYTextEnabled = integrateYTextEnabled;
propertyChangeSupport.firePropertyChange(PROP_ATPOINTYTEXTENABLED, oldIntegrateYTextEnabled, integrateYTextEnabled);
}

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
<BindingProperty name="text" source="Form" sourcePath="${selectedConfig.normConfiguration.YValue}" target="integrationValueText" targetPath="text" updateStrategy="0" immediately="false">
<BindingParameter name="javax.swing.binding.ParameterKeys.TEXT_CHANGE_STRATEGY" value="javax.swing.binding.TextChangeStrategy.ON_TYPE"/>
</BindingProperty>
<BindingProperty name="enabled" source="jRadioButton1" sourcePath="${selected}" target="integrationValueText" targetPath="enabled" updateStrategy="0" immediately="false"/>
<BindingProperty name="enabled" source="Form" sourcePath="${selectedConfig.normConfiguration.integrateYTextEnabled}" target="integrationValueText" targetPath="enabled" updateStrategy="0" immediately="false"/>
</BindingProperties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import cfa.vo.sedlib.common.SedException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyVetoException;
import java.text.NumberFormat;
import java.text.ParsePosition;
Expand All @@ -55,7 +53,6 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import org.apache.commons.lang.StringUtils;
import org.astrogrid.samp.client.SampException;
Expand Down Expand Up @@ -91,18 +88,73 @@ public SedStackerFrame(IrisApplication app, IWorkspace ws) {
// normalization comboBoxes. Chooses the list of units available
// based on the normalization type chosen (Value, Median, or Average).
// Also disable Y value text box if using Average or Median.

//TODO: cleanup unused code.
integrationNormType.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

String normType = (String) integrationNormType.getSelectedItem();
if (normType.equals("Value")) {
integrationYUnit.setModel(new DefaultComboBoxModel(new String[] {"erg/s/cm2","Jy-Hz","Watt/m2","erg/s","Watt"}));
String [] model;

if (normType.equals("Value") && getSelectedConfig().getNormConfiguration().isIntegrate()) {
model = new String[] {"erg/s/cm2","Jy-Hz","Watt/m2","erg/s","Watt"};
integrationValueText.setEnabled(true);
} else {
model = loadEnum(SPVYUnit.class);
integrationValueText.setEnabled(false);
}

try {
Object yunit = integrationYUnit.getSelectedItem();
integrationYUnit.setModel(new DefaultComboBoxModel(model));
integrationYUnit.setSelectedItem(yunit);
} catch (IllegalArgumentException ex) {
integrationYUnit.setModel(new DefaultComboBoxModel(model));
} catch (Exception ex) {
integrationYUnit.setModel(new DefaultComboBoxModel(model));
}

}
});
// atPointYType.addActionListener( new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
//
// String normType = (String) atPointYType.getSelectedItem();
// if (normType.equals("Value")) {
// atPointYText.setEnabled(true);
// } else {
// atPointYText.setEnabled(false);
// }
//
// }
// });
jRadioButton1.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

boolean selected = jRadioButton1.isSelected();
if (selected && integrationNormType.getSelectedItem().equals("Value")) {
integrationValueText.setEnabled(true);
} else {
integrationYUnit.setModel(new DefaultComboBoxModel(loadEnum(SPVYUnit.class)));
integrationValueText.setEnabled(false);
}

atPointYText.setEnabled(false);
}
});
jRadioButton2.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

boolean selected = jRadioButton2.isSelected();
if (selected && atPointYType.getSelectedItem().equals("Value")) {
atPointYText.setEnabled(true);
} else {
atPointYText.setEnabled(false);
}
integrationValueText.setEnabled(false); // good - keep!
}
});

Expand Down Expand Up @@ -427,7 +479,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedConfig.normConfiguration.YValue}"), integrationValueText, org.jdesktop.beansbinding.BeanProperty.create("text"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jRadioButton1, org.jdesktop.beansbinding.ELProperty.create("${selected}"), integrationValueText, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedConfig.normConfiguration.integrateYTextEnabled}"), integrationValueText, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);

integrationNormType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Value", "Average", "Median" }));
Expand Down