Update domain type on configuration change

This commit is contained in:
SiboVG 2024-08-27 00:33:59 +02:00
parent b53f4e4f5a
commit f392760c0e
2 changed files with 24 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import info.openrocket.core.startup.Application;
import info.openrocket.swing.gui.adaptors.DoubleModel;
import info.openrocket.swing.gui.components.EditableSpinner;
import info.openrocket.swing.gui.components.UnitSelector;
import info.openrocket.swing.gui.plot.PlotPanel;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -35,7 +36,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ComponentAnalysisPlotExportPanel extends JPanel {
public class ComponentAnalysisPlotExportPanel extends JPanel implements PlotPanel.PlotConfigurationListener<CAPlotConfiguration> {
private static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(ComponentAnalysisPlotExportPanel.class);
@ -83,6 +84,7 @@ public class ComponentAnalysisPlotExportPanel extends JPanel {
//// Plot data
this.plotTab = CAPlotPanel.create(this, types);
this.tabbedPane.addTab(trans.get("CAPlotExportDialog.tab.Plot"), null, this.plotTab);
this.plotTab.addPlotConfigurationListener(this);
//// Export data
this.exportTab = CAExportPanel.create(this, types);
@ -322,4 +324,9 @@ public class ComponentAnalysisPlotExportPanel extends JPanel {
}
}
@Override
public void onPlotConfigurationChanged(CAPlotConfiguration newConfiguration) {
CADomainDataType type = (CADomainDataType) newConfiguration.getDomainAxisType();
this.parameterSelector.setSelectedItem(type);
}
}

View File

@ -26,7 +26,9 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PlotPanel<T extends DataType & Groupable<G>,
B extends DataBranch<T>,
@ -44,13 +46,14 @@ public class PlotPanel<T extends DataType & Groupable<G>,
private final C[] presetArray;
private C defaultConfiguration;
private final List<PlotConfigurationListener<C>> configurationListeners = new ArrayList<>();
// Data types for the x and y axis + plot configuration
protected final T[] typesX;
protected final T[] typesY;
protected C configuration;
private final JComboBox<C> configurationSelector;
protected final JComboBox<C> configurationSelector;
protected JComboBox<T> domainTypeSelector;
private UnitSelector domainUnitSelector;
private final JPanel typeSelectorPanel;
@ -265,6 +268,10 @@ public class PlotPanel<T extends DataType & Groupable<G>,
if (modified) {
configuration.setName(CUSTOM);
}
for (PlotConfigurationListener<C> listener : configurationListeners) {
listener.onPlotConfigurationChanged(configuration);
}
}
protected void setDefaultConfiguration(C newConfiguration) {
@ -341,4 +348,12 @@ public class PlotPanel<T extends DataType & Groupable<G>,
updatePlots();
});
}
public void addPlotConfigurationListener(PlotConfigurationListener<C> listener) {
this.configurationListeners.add(listener);
}
public interface PlotConfigurationListener<C extends PlotConfiguration<?, ?>> {
void onPlotConfigurationChanged(C newConfiguration);
}
}