Fix multi-comp deployment editing
This commit is contained in:
parent
c026441a47
commit
1ed7354337
@ -30,8 +30,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations;
|
||||
|
||||
public RecoveryDevice() {
|
||||
this.deploymentConfigurations =
|
||||
new FlightConfigurableParameterSet<DeploymentConfiguration>( new DeploymentConfiguration());
|
||||
this.deploymentConfigurations = new FlightConfigurableParameterSet<>( new DeploymentConfiguration());
|
||||
defaultMaterial = (Material.Surface) Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE);
|
||||
setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE));
|
||||
}
|
||||
@ -148,7 +147,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
@Override
|
||||
protected RocketComponent copyWithOriginalID() {
|
||||
RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID();
|
||||
copy.deploymentConfigurations = new FlightConfigurableParameterSet<DeploymentConfiguration>(deploymentConfigurations);
|
||||
copy.deploymentConfigurations = new FlightConfigurableParameterSet<>(deploymentConfigurations);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
@ -46,6 +47,8 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
private final JSpinner altSpinner;
|
||||
private final UnitSelector altUnit;
|
||||
private final JSlider altSlider;
|
||||
|
||||
private boolean isOverrideDefault;
|
||||
|
||||
public DeploymentSelectionDialog(Window parent, final Rocket rocket, final FlightConfigurationId id, final RecoveryDevice component) {
|
||||
super(parent, trans.get("edtmotorconfdlg.title.Selectdeploymentconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
@ -59,7 +62,9 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
panel.add(defaultButton, "span, gapleft para, wrap rel");
|
||||
String str = trans.get("DeploymentSelectionDialog.opt.override");
|
||||
str = str.replace("{0}", descriptor.format(rocket, id));
|
||||
final JRadioButton overrideButton = new JRadioButton(str, false);
|
||||
final JRadioButton overrideButton = new JRadioButton(str);
|
||||
overrideButton.addItemListener(e -> isOverrideDefault = e.getStateChange() == ItemEvent.SELECTED);
|
||||
overrideButton.setSelected(false);
|
||||
panel.add(overrideButton, "span, gapleft para, wrap para");
|
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
@ -156,6 +161,12 @@ public class DeploymentSelectionDialog extends JDialog {
|
||||
altUnit.setEnabled(enabled);
|
||||
altSlider.setEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this dialog was used to override the default configuration.
|
||||
* @return true if this dialog was used to override the default configuration.
|
||||
*/
|
||||
public boolean isOverrideDefault() {
|
||||
return isOverrideDefault;
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,10 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
if (tableValue instanceof Pair) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<String, T> selectedComponent = (Pair<String, T>) tableValue;
|
||||
components.add(selectedComponent.getV());
|
||||
T comp = selectedComponent.getV();
|
||||
if (!components.contains(comp)) {
|
||||
components.add(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,11 +295,17 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<FlightConfigurationId, T> selectedComponent = (Pair<FlightConfigurationId, T>) tableValue;
|
||||
FlightConfigurationId fcid = selectedComponent.getU();
|
||||
Ids.add(fcid);
|
||||
if (!Ids.contains(fcid)) {
|
||||
Ids.add(fcid);
|
||||
}
|
||||
} else if (tableValue instanceof FlightConfigurationId) {
|
||||
Ids.add((FlightConfigurationId) tableValue);
|
||||
if (!Ids.contains(tableValue)) {
|
||||
Ids.add((FlightConfigurationId) tableValue);
|
||||
}
|
||||
} else {
|
||||
Ids.add(FlightConfigurationId.ERROR_FCID);
|
||||
if (!Ids.contains(FlightConfigurationId.ERROR_FCID)) {
|
||||
Ids.add(FlightConfigurationId.ERROR_FCID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
||||
document.addUndoPosition("Select deployment");
|
||||
|
||||
// Open the configuration dialog
|
||||
JDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId, initDevice);
|
||||
DeploymentSelectionDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId, initDevice);
|
||||
d.setVisible(true);
|
||||
|
||||
final DeploymentConfiguration modifiedConfig = initDevice.getDeploymentConfigurations().get(initFcId);
|
||||
@ -190,6 +190,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
||||
double deployDelay = modifiedConfig.getDeployDelay();
|
||||
double deployAltitude = modifiedConfig.getDeployAltitude();
|
||||
DeployEvent deployEvent = modifiedConfig.getDeployEvent();
|
||||
boolean isOverrideDefault = d.isOverrideDefault();
|
||||
|
||||
for (RecoveryDevice device : devices) {
|
||||
for (FlightConfigurationId fcId : fcIds) {
|
||||
@ -197,6 +198,11 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
||||
if ((device == initDevice) && (fcId == initFcId))
|
||||
continue;
|
||||
|
||||
// It could be that the current config is the default config, but the user has selected to override it.
|
||||
if (isOverrideDefault && !device.getDeploymentConfigurations().containsId(fcId)) {
|
||||
device.getDeploymentConfigurations().set(fcId, device.getDeploymentConfigurations().getDefault().clone());
|
||||
}
|
||||
|
||||
DeploymentConfiguration currentConfig = device.getDeploymentConfigurations().get(fcId);
|
||||
|
||||
if (currentConfig.equals(modifiedConfig)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user