Split types into X and Y

This commit is contained in:
SiboVG 2024-08-15 17:46:50 +02:00
parent 809a50dd7c
commit 9554bf3fe2
2 changed files with 14 additions and 11 deletions

View File

@ -41,7 +41,9 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
private PlotConfiguration<T, B> defaultConfiguration; private PlotConfiguration<T, B> defaultConfiguration;
private final T[] types; // Data types for the x and y axis + plot configuration
private final T[] typesX;
private final T[] typesY;
protected PlotConfiguration<T, B> configuration; protected PlotConfiguration<T, B> configuration;
private JComboBox<PlotConfiguration<T, B>> configurationSelector; private JComboBox<PlotConfiguration<T, B>> configurationSelector;
@ -53,7 +55,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
protected int modifying = 0; protected int modifying = 0;
public PlotPanel(T[] types, PlotConfiguration<T, B> customConfiguration, PlotConfiguration<T, B>[] presets, public PlotPanel(T[] typesX, T[] typesY, PlotConfiguration<T, B> customConfiguration, PlotConfiguration<T, B>[] presets,
PlotConfiguration<T, B> defaultConfiguration, PlotConfiguration<T, B> defaultConfiguration,
Component[] extraWidgetsX, Component[] extraWidgetsY) { Component[] extraWidgetsX, Component[] extraWidgetsY) {
super(new MigLayout("fill")); super(new MigLayout("fill"));
@ -61,7 +63,8 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
this.customConfiguration = customConfiguration; this.customConfiguration = customConfiguration;
this.presetArray = presets; this.presetArray = presets;
this.defaultConfiguration = defaultConfiguration; this.defaultConfiguration = defaultConfiguration;
this.types = types; this.typesX = typesX;
this.typesY = typesY;
setConfiguration(defaultConfiguration); setConfiguration(defaultConfiguration);
@ -108,7 +111,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
//// X axis type: //// X axis type:
this.add(new JLabel(trans.get("simplotpanel.lbl.Xaxistype")), "spanx, split"); this.add(new JLabel(trans.get("simplotpanel.lbl.Xaxistype")), "spanx, split");
domainTypeSelector = new GroupableAndSearchableComboBox<>(Arrays.asList(types), trans.get("FlightDataComboBox.placeholder")); domainTypeSelector = new GroupableAndSearchableComboBox<>(Arrays.asList(typesX), trans.get("FlightDataComboBox.placeholder"));
domainTypeSelector.setSelectedItem(configuration.getDomainAxisType()); domainTypeSelector.setSelectedItem(configuration.getDomainAxisType());
domainTypeSelector.addItemListener(new ItemListener() { domainTypeSelector.addItemListener(new ItemListener() {
@Override @Override
@ -192,7 +195,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
// Select new type smartly // Select new type smartly
T type = null; T type = null;
for (T t : types) { for (T t : typesY) {
boolean used = false; boolean used = false;
if (configuration.getDomainAxisType().equals(t)) { if (configuration.getDomainAxisType().equals(t)) {
@ -212,7 +215,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
} }
} }
if (type == null) { if (type == null) {
type = types[0]; type = typesY[0];
} }
// Add new type // Add new type
@ -232,13 +235,13 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
boolean modified = false; boolean modified = false;
configuration = conf.clone(); configuration = conf.clone();
if (!Utils.contains(types, configuration.getDomainAxisType())) { if (!Utils.contains(typesX, configuration.getDomainAxisType())) {
configuration.setDomainAxisType(types[0]); configuration.setDomainAxisType(typesX[0]);
modified = true; modified = true;
} }
for (int i = 0; i < configuration.getTypeCount(); i++) { for (int i = 0; i < configuration.getTypeCount(); i++) {
if (!Utils.contains(types, configuration.getType(i))) { if (!Utils.contains(typesY, configuration.getType(i))) {
configuration.removePlotDataType(i); configuration.removePlotDataType(i);
i--; i--;
modified = true; modified = true;
@ -278,7 +281,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
Unit unit = configuration.getUnit(i); Unit unit = configuration.getUnit(i);
int axis = configuration.getAxis(i); int axis = configuration.getAxis(i);
PlotTypeSelector<G, T> selector = new PlotTypeSelector<>(i, type, unit, axis, Arrays.asList(types)); PlotTypeSelector<G, T> selector = new PlotTypeSelector<>(i, type, unit, axis, Arrays.asList(typesY));
int finalI = i; int finalI = i;
selector.addTypeSelectionListener(e -> { selector.addTypeSelectionListener(e -> {
if (modifying > 0) return; if (modifying > 0) return;

View File

@ -84,7 +84,7 @@ public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBra
private SimulationPlotPanel(final Simulation simulation, FlightDataType[] types, private SimulationPlotPanel(final Simulation simulation, FlightDataType[] types,
final DescriptionArea simPlotPanelDesc, final DescriptionArea simPlotPanelDesc,
Component[] extraWidgetsX, JPanel selectorPanel, Component[] extraWidgetsY) { Component[] extraWidgetsX, JPanel selectorPanel, Component[] extraWidgetsY) {
super(types, CUSTOM_CONFIGURATION, PRESET_ARRAY, DEFAULT_CONFIGURATION, extraWidgetsX, extraWidgetsY); super(types, types, CUSTOM_CONFIGURATION, PRESET_ARRAY, DEFAULT_CONFIGURATION, extraWidgetsX, extraWidgetsY);
this.simulation = simulation; this.simulation = simulation;