Merge pull request #1180 from SiboVG/issue-1166

[fixes #1166] Use [{motors}] for flight config motors placeholder
This commit is contained in:
Joe Pfeiffer 2022-02-28 10:27:19 -07:00 committed by GitHub
commit 804d9bad0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 15 deletions

View File

@ -55,7 +55,7 @@ public class RocketSaver extends RocketComponentSaver {
}
if (flightConfig.isNameOverridden()){
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getName())
str += "><name>" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getNameRaw())
+ "</name></motorconfiguration>";
} else {
str += "/>";

View File

@ -34,7 +34,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
private static final Translator trans = Application.getTranslator();
private String configurationName=null;
private String configurationName;
public static String DEFAULT_CONFIG_NAME = "[{motors}]";
protected final Rocket rocket;
protected final FlightConfigurationId fcid;
@ -94,7 +95,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.fcid = _fcid;
}
this.rocket = rocket;
this.configurationName = null;
this.configurationName = DEFAULT_CONFIG_NAME;
this.configurationInstanceId = configurationInstanceCount++;
updateStages();
@ -414,15 +415,31 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
}
public boolean isNameOverridden(){
return (null != this.configurationName );
return (!DEFAULT_CONFIG_NAME.equals(this.configurationName));
}
/**
* Return the name of this configuration, with DEFAULT_CONFIG_NAME replaced by a one line motor description.
* If configurationName is null, the one line motor description is returned.
* @return the flight configuration name
*/
public String getName() {
if( null == configurationName){
return this.getOneLineMotorDescription();
}else{
return configurationName;
if (configurationName == null) {
return getOneLineMotorDescription();
}
return configurationName.replace(DEFAULT_CONFIG_NAME, getOneLineMotorDescription());
}
/**
* Return the raw configuration name, without replacing DEFAULT_CONFIG_NAME.
* If the configurationName is null, DEFAULT_CONFIG_NAME is returned.
* @return raw flight configuration name
*/
public String getNameRaw() {
if (configurationName == null) {
return DEFAULT_CONFIG_NAME;
}
return configurationName;
}
private String getOneLineMotorDescription(){
@ -699,6 +716,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
copy.modID = this.modID;
copy.boundsModID = -1;
copy.refLengthModID = -1;
copy.configurationName = configurationName;
return copy;
}
@ -713,9 +731,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return id;
}
public void setName( final String newName) {
if(( null == newName ) ||( "".equals(newName))){
this.configurationName = null;
public void setName(final String newName) {
if ((newName == null) || ("".equals(newName))) {
this.configurationName = DEFAULT_CONFIG_NAME;
return;
}else if( ! this.getId().isValid()){
return;

View File

@ -861,7 +861,7 @@ public class Rocket extends ComponentAssembly {
if( this.selectedConfiguration.equals( config)){
shortKey = "=>" + shortKey;
}
buf.append(String.format(fmt, shortKey, config.getName() ));
buf.append(String.format(fmt, shortKey, config.getNameRaw() ));
}
return buf.toString();
}

View File

@ -30,7 +30,7 @@ public class RenameConfigDialog extends JDialog {
panel.add(new JLabel(trans.get("RenameConfigDialog.lbl.name")), "span, wrap rel");
final JTextField textbox = new JTextField(rocket.getFlightConfiguration(fcid).getName());
final JTextField textbox = new JTextField(rocket.getFlightConfiguration(fcid).getNameRaw());
panel.add(textbox, "span, w 200lp, growx, wrap para");
panel.add(new JPanel(), "growx");

View File

@ -220,7 +220,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
if (fcIds == null) return;
FlightConfigurationId initFcId = fcIds.get(0);
new RenameConfigDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId).setVisible(true);
String newName = rocket.getFlightConfiguration(initFcId).getName();
String newName = rocket.getFlightConfiguration(initFcId).getNameRaw();
for (int i = 1; i < fcIds.size(); i++) {
rocket.getFlightConfiguration(fcIds.get(i)).setName(newName);
}