[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:
parent
3362c03279
commit
915d401370
@ -43,7 +43,8 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet<MotorC
|
|||||||
public String toDebug(){
|
public String toDebug(){
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
final MotorMount mnt = this.getDefault().getMount();
|
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()){
|
for( FlightConfigurationId loopFCID : this.map.keySet()){
|
||||||
MotorConfiguration curConfig = this.map.get(loopFCID);
|
MotorConfiguration curConfig = this.map.get(loopFCID);
|
||||||
|
@ -724,6 +724,12 @@ public class Rocket extends RocketComponent {
|
|||||||
|
|
||||||
public void setSelectedConfiguration(final FlightConfigurationId selectId) {
|
public void setSelectedConfiguration(final FlightConfigurationId selectId) {
|
||||||
checkState();
|
checkState();
|
||||||
|
|
||||||
|
if( selectId.equals( selectedConfiguration.getFlightConfigurationID())){
|
||||||
|
// if desired configuration is already selected, skip the event
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selectedConfiguration = this.configSet.get( selectId );
|
this.selectedConfiguration = this.configSet.get( selectId );
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||||
}
|
}
|
||||||
@ -744,6 +750,9 @@ public class Rocket extends RocketComponent {
|
|||||||
|
|
||||||
if (null == newConfig){
|
if (null == newConfig){
|
||||||
configSet.reset( fcid);
|
configSet.reset( fcid);
|
||||||
|
}else if( fcid.equals( configSet.get(fcid).getFlightConfigurationID())){
|
||||||
|
// this mapping already exists; skip the event
|
||||||
|
return;
|
||||||
}else{
|
}else{
|
||||||
configSet.set(fcid, newConfig);
|
configSet.set(fcid, newConfig);
|
||||||
}
|
}
|
||||||
@ -829,7 +838,8 @@ public class Rocket extends RocketComponent {
|
|||||||
|
|
||||||
public String toDebugConfigs(){
|
public String toDebugConfigs(){
|
||||||
StringBuilder buf = new StringBuilder();
|
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";
|
final String fmt = " [%12s]: %s\n";
|
||||||
for( FlightConfiguration config : this.configSet ){
|
for( FlightConfiguration config : this.configSet ){
|
||||||
String shortKey = config.getId().toShortKey();
|
String shortKey = config.getId().toShortKey();
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
import javax.swing.table.TableRowSorter;
|
import javax.swing.table.TableRowSorter;
|
||||||
|
|
||||||
public class ColumnTableRowSorter extends TableRowSorter {
|
public class ColumnTableRowSorter extends TableRowSorter<ColumnTableModel> {
|
||||||
|
|
||||||
private final ColumnTableModel columnTableModel;
|
private final ColumnTableModel columnTableModel;
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ public class ColumnTableRowSorter extends TableRowSorter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Comparator getComparator(int column) {
|
public Comparator<?> getComparator(int column) {
|
||||||
Comparator c = columnTableModel.getColumn(column).getComparator();
|
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
|
||||||
return (c!= null) ? c : super.getComparator(column);
|
return (c!= null) ? c : super.getComparator(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class ColumnTableRowSorter extends TableRowSorter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean useToString(int column) {
|
protected boolean useToString(int column) {
|
||||||
Comparator c = columnTableModel.getColumn(column).getComparator();
|
Comparator<?> c = columnTableModel.getColumn(column).getComparator();
|
||||||
return ( c != null ) ? false : super.useToString(column);
|
return ( c != null ) ? false : super.useToString(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,18 +13,17 @@ import java.util.EventObject;
|
|||||||
public class ConfigurationModel implements ComboBoxModel<FlightConfiguration>, StateChangeListener {
|
public class ConfigurationModel implements ComboBoxModel<FlightConfiguration>, StateChangeListener {
|
||||||
|
|
||||||
private final Rocket rkt;
|
private final Rocket rkt;
|
||||||
|
private final JComboBox<FlightConfiguration> combo;
|
||||||
|
|
||||||
//private FlightConfigurationSelector(){}
|
public ConfigurationModel( final Rocket _rkt, final JComboBox<FlightConfiguration> _combo) {
|
||||||
|
this.rkt = _rkt;
|
||||||
public ConfigurationModel( final Rocket _rkt) {
|
this.combo = _combo;
|
||||||
rkt = _rkt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(EventObject e) {
|
public void stateChanged(EventObject eo) {
|
||||||
// FlightConfiguration newConfig = (FlightConfiguration)this.getSelectedItem();
|
combo.revalidate();
|
||||||
// rkt.setSelectedConfiguration( newConfig.getId());
|
combo.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import javax.swing.JButton;
|
|||||||
*
|
*
|
||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
public class FlatButton extends JButton {
|
public class FlatButton extends JButton {
|
||||||
|
|
||||||
public FlatButton() {
|
public FlatButton() {
|
||||||
|
@ -11,6 +11,7 @@ import javax.swing.JLabel;
|
|||||||
*
|
*
|
||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
public class HtmlLabel extends JLabel {
|
public class HtmlLabel extends JLabel {
|
||||||
|
|
||||||
public HtmlLabel() {
|
public HtmlLabel() {
|
||||||
|
@ -177,8 +177,9 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
|||||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||||
panel.add(label, "growx, right");
|
panel.add(label, "growx, right");
|
||||||
|
|
||||||
final ConfigurationModel configModel = new ConfigurationModel(rkt);
|
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
|
||||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
|
||||||
|
configComboBox.setModel( configModel);
|
||||||
panel.add( configComboBox, "wrap");
|
panel.add( configComboBox, "wrap");
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
public class EditDecalDialog extends JDialog {
|
public class EditDecalDialog extends JDialog {
|
||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
@ -137,6 +137,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
}
|
}
|
||||||
Object tableValue = table.getModel().getValueAt(row, col);
|
Object tableValue = table.getModel().getValueAt(row, col);
|
||||||
if ( tableValue instanceof Pair ) {
|
if ( tableValue instanceof Pair ) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
|
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
|
||||||
return selectedComponent.getV();
|
return selectedComponent.getV();
|
||||||
}
|
}
|
||||||
@ -151,6 +152,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
}
|
}
|
||||||
Object tableValue = table.getModel().getValueAt(row, col);
|
Object tableValue = table.getModel().getValueAt(row, col);
|
||||||
if ( tableValue instanceof Pair ) {
|
if ( tableValue instanceof Pair ) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
|
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
|
||||||
FlightConfigurationId fcid = selectedComponent.getU();
|
FlightConfigurationId fcid = selectedComponent.getU();
|
||||||
return fcid;
|
return fcid;
|
||||||
|
@ -159,6 +159,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
|||||||
FlightConfigurationId currentId = this.motorConfigurationPanel.getSelectedConfigurationId();
|
FlightConfigurationId currentId = this.motorConfigurationPanel.getSelectedConfigurationId();
|
||||||
if (currentId == null)
|
if (currentId == null)
|
||||||
return;
|
return;
|
||||||
|
System.err.println(this.rocket.toDebugConfigs());
|
||||||
document.removeFlightConfigurationAndSimulations(currentId);
|
document.removeFlightConfigurationAndSimulations(currentId);
|
||||||
configurationChanged();
|
configurationChanged();
|
||||||
}
|
}
|
||||||
|
@ -320,9 +320,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||||
add(label, "growx, right");
|
add(label, "growx, right");
|
||||||
|
|
||||||
final ConfigurationModel configModel = new ConfigurationModel(rkt);
|
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
|
||||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
|
||||||
rkt.addChangeListener( configModel );
|
rkt.addChangeListener( configModel );
|
||||||
|
configComboBox.setModel(configModel);
|
||||||
add(configComboBox, "wrap, width 16%, wmin 100");
|
add(configComboBox, "wrap, width 16%, wmin 100");
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,9 +148,9 @@ public class SimulationEditDialog extends JDialog {
|
|||||||
panel.add(label, "growx 0, gapright para");
|
panel.add(label, "growx 0, gapright para");
|
||||||
|
|
||||||
final Rocket rkt = document.getRocket();
|
final Rocket rkt = document.getRocket();
|
||||||
final ConfigurationModel configModel = new ConfigurationModel( rkt);
|
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>();
|
||||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox);
|
||||||
configComboBox.setSelectedItem( rkt.getSelectedConfiguration().getId() );
|
configComboBox.setModel( configModel);
|
||||||
|
|
||||||
//// Select the motor configuration to use.
|
//// Select the motor configuration to use.
|
||||||
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user