[Bugfix] Configuration Selection ComboBox now correctly updates

- adjusted some type cast warnings
- Added 'ignore if new==current' paths in rocket configuration functions
  -- These if paths break potential infinite loops
- added update code for the main-window selected configuration dropdown
  -- now updates when the currently-selected configuration is removed.
This commit is contained in:
Daniel_M_Williams 2016-04-24 10:15:48 -04:00
parent 3362c03279
commit 915d401370
12 changed files with 40 additions and 22 deletions

View File

@ -43,7 +43,8 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
public String toDebug(){
StringBuilder buffer = new StringBuilder();
final MotorMount mnt = this.getDefault().getMount();
buffer.append("====== Dumping MotorConfigurationSet: "+this.size()+ " motors in "+mnt.getDebugName()+" \n");
buffer.append(String.format(" ====== Dumping MotorConfigurationSet: %d motors in %s ====== ",
this.size(), mnt.getDebugName() ));
for( FlightConfigurationId loopFCID : this.map.keySet()){
MotorConfiguration curConfig = this.map.get(loopFCID);

View File

@ -594,7 +594,7 @@ public class Rocket extends RocketComponent {
if( fcid.hasError() ){
return;
}
if( selectedConfiguration.getId().equals( fcid)){
selectedConfiguration = configSet.getDefault();
}
@ -724,6 +724,12 @@ public class Rocket extends RocketComponent {
public void setSelectedConfiguration(final FlightConfigurationId selectId) {
checkState();
if( selectId.equals( selectedConfiguration.getFlightConfigurationID())){
// if desired configuration is already selected, skip the event
return;
}
this.selectedConfiguration = this.configSet.get( selectId );
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
@ -744,6 +750,9 @@ public class Rocket extends RocketComponent {
if (null == newConfig){
configSet.reset( fcid);
}else if( fcid.equals( configSet.get(fcid).getFlightConfigurationID())){
// this mapping already exists; skip the event
return;
}else{
configSet.set(fcid, newConfig);
}
@ -829,7 +838,8 @@ public class Rocket extends RocketComponent {
public String toDebugConfigs(){
StringBuilder buf = new StringBuilder();
buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName()));
buf.append(String.format("====== Dumping %d Configurations from rocket: %s ======\n",
this.getConfigurationCount(), this.getName()));
final String fmt = " [%12s]: %s\n";
for( FlightConfiguration config : this.configSet ){
String shortKey = config.getId().toShortKey();

View File

@ -4,7 +4,7 @@ import java.util.Comparator;
import javax.swing.table.TableRowSorter;
public class ColumnTableRowSorter extends TableRowSorter {
public class ColumnTableRowSorter extends TableRowSorter<ColumnTableModel> {
private final ColumnTableModel columnTableModel;
@ -14,8 +14,8 @@ public class ColumnTableRowSorter extends TableRowSorter {
}
@Override
public Comparator getComparator(int column) {
Comparator c = columnTableModel.getColumn(column).getComparator();
public Comparator<?> getComparator(int column) {
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
return (c!= null) ? c : super.getComparator(column);
}
@ -30,7 +30,7 @@ public class ColumnTableRowSorter extends TableRowSorter {
*/
@Override
protected boolean useToString(int column) {
Comparator c = columnTableModel.getColumn(column).getComparator();
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
return ( c != null ) ? false : super.useToString(column);
}

View File

@ -13,18 +13,17 @@ import java.util.EventObject;
public class ConfigurationModel implements ComboBoxModel<FlightConfiguration>, StateChangeListener {
private final Rocket rkt;
private final JComboBox<FlightConfiguration> combo;
//private FlightConfigurationSelector(){}
public ConfigurationModel( final Rocket _rkt) {
rkt = _rkt;
public ConfigurationModel( final Rocket _rkt, final JComboBox<FlightConfiguration> _combo) {
this.rkt = _rkt;
this.combo = _combo;
}
@Override
public void stateChanged(EventObject e) {
// FlightConfiguration newConfig = (FlightConfiguration)this.getSelectedItem();
// rkt.setSelectedConfiguration( newConfig.getId());
public void stateChanged(EventObject eo) {
combo.revalidate();
combo.repaint();
}

View File

@ -12,6 +12,7 @@ import javax.swing.JButton;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
@SuppressWarnings("serial")
public class FlatButton extends JButton {
public FlatButton() {

View File

@ -11,6 +11,7 @@ import javax.swing.JLabel;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
@SuppressWarnings("serial")
public class HtmlLabel extends JLabel {
public HtmlLabel() {

View File

@ -177,8 +177,9 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
label.setHorizontalAlignment(JLabel.RIGHT);
panel.add(label, "growx, right");
final ConfigurationModel configModel = new ConfigurationModel(rkt);
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
configComboBox.setModel( configModel);
panel.add( configComboBox, "wrap");

View File

@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application;
@SuppressWarnings("serial")
public class EditDecalDialog extends JDialog {
private static final Translator trans = Application.getTranslator();

View File

@ -137,6 +137,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
return selectedComponent.getV();
}
@ -151,6 +152,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
return fcid;

View File

@ -159,6 +159,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
FlightConfigurationId currentId = this.motorConfigurationPanel.getSelectedConfigurationId();
if (currentId == null)
return;
System.err.println(this.rocket.toDebugConfigs());
document.removeFlightConfigurationAndSimulations(currentId);
configurationChanged();
}

View File

@ -320,9 +320,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
label.setHorizontalAlignment(JLabel.RIGHT);
add(label, "growx, right");
final ConfigurationModel configModel = new ConfigurationModel(rkt);
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
rkt.addChangeListener( configModel );
configComboBox.setModel(configModel);
add(configComboBox, "wrap, width 16%, wmin 100");

View File

@ -148,9 +148,9 @@ public class SimulationEditDialog extends JDialog {
panel.add(label, "growx 0, gapright para");
final Rocket rkt = document.getRocket();
final ConfigurationModel configModel = new ConfigurationModel( rkt);
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
configComboBox.setSelectedItem( rkt.getSelectedConfiguration().getId() );
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
configComboBox.setModel( configModel);
//// Select the motor configuration to use.
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));