Use template class for plot configuration
This commit is contained in:
parent
627abcd87e
commit
0fd1a93f5f
@ -29,33 +29,33 @@ import java.awt.event.ItemListener;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T>, G extends Group,
|
public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T>, G extends Group,
|
||||||
S extends PlotTypeSelector<G, T>> extends JPanel {
|
C extends PlotConfiguration<T, B>, S extends PlotTypeSelector<G, T>> extends JPanel {
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
//// Custom
|
//// Custom
|
||||||
protected static final String CUSTOM = trans.get("simplotpanel.CUSTOM");
|
protected static final String CUSTOM = trans.get("simplotpanel.CUSTOM");
|
||||||
/** The "Custom" configuration - not to be used for anything other than the title. */
|
/** The "Custom" configuration - not to be used for anything other than the title. */
|
||||||
private final PlotConfiguration<T, B> customConfiguration;
|
private final C customConfiguration;
|
||||||
|
|
||||||
/** The array of presets for the combo box. */
|
/** The array of presets for the combo box. */
|
||||||
private final PlotConfiguration<T, B>[] presetArray;
|
private final C[] presetArray;
|
||||||
|
|
||||||
private PlotConfiguration<T, B> defaultConfiguration;
|
private C defaultConfiguration;
|
||||||
|
|
||||||
// Data types for the x and y axis + plot configuration
|
// Data types for the x and y axis + plot configuration
|
||||||
private final T[] typesX;
|
private final T[] typesX;
|
||||||
private final T[] typesY;
|
private final T[] typesY;
|
||||||
protected PlotConfiguration<T, B> configuration;
|
protected C configuration;
|
||||||
|
|
||||||
private final JComboBox<PlotConfiguration<T, B>> configurationSelector;
|
private final JComboBox<C> configurationSelector;
|
||||||
protected JComboBox<T> domainTypeSelector;
|
protected JComboBox<T> domainTypeSelector;
|
||||||
private UnitSelector domainUnitSelector;
|
private UnitSelector domainUnitSelector;
|
||||||
private final JPanel typeSelectorPanel;
|
private final JPanel typeSelectorPanel;
|
||||||
|
|
||||||
protected int modifying = 0;
|
protected int modifying = 0;
|
||||||
|
|
||||||
public PlotPanel(T[] typesX, T[] typesY, PlotConfiguration<T, B> customConfiguration, PlotConfiguration<T, B>[] presets,
|
public PlotPanel(T[] typesX, T[] typesY, C customConfiguration, C[] presets,
|
||||||
PlotConfiguration<T, B> defaultConfiguration, Component[] extraWidgetsX, Component[] extraWidgetsY) {
|
C defaultConfiguration, Component[] extraWidgetsX, Component[] extraWidgetsY) {
|
||||||
super(new MigLayout("fill"));
|
super(new MigLayout("fill"));
|
||||||
|
|
||||||
this.customConfiguration = customConfiguration;
|
this.customConfiguration = customConfiguration;
|
||||||
@ -70,7 +70,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
|
|||||||
|
|
||||||
// Setup the combo box
|
// Setup the combo box
|
||||||
configurationSelector = new JComboBox<>(presetArray);
|
configurationSelector = new JComboBox<>(presetArray);
|
||||||
for (PlotConfiguration<T, B> config : presetArray) {
|
for (C config : presetArray) {
|
||||||
if (config.getName().equals(configuration.getName())) {
|
if (config.getName().equals(configuration.getName())) {
|
||||||
configurationSelector.setSelectedItem(config);
|
configurationSelector.setSelectedItem(config);
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
|
|||||||
}
|
}
|
||||||
if (modifying > 0)
|
if (modifying > 0)
|
||||||
return;
|
return;
|
||||||
PlotConfiguration<T, B> conf = (PlotConfiguration<T, B>) configurationSelector.getSelectedItem();
|
C conf = (C) configurationSelector.getSelectedItem();
|
||||||
if (conf == null || conf == customConfiguration)
|
if (conf == null || conf == customConfiguration)
|
||||||
return;
|
return;
|
||||||
modifying++;
|
modifying++;
|
||||||
@ -238,14 +238,14 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
|
|||||||
return typeSelectorPanel;
|
return typeSelectorPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PlotConfiguration<T, B> getConfiguration() {
|
protected C getConfiguration() {
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setConfiguration(PlotConfiguration<T, B> conf) {
|
protected void setConfiguration(C conf) {
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
|
|
||||||
configuration = conf.clone();
|
configuration = (C) conf.clone();
|
||||||
if (!Utils.contains(typesX, configuration.getDomainAxisType())) {
|
if (!Utils.contains(typesX, configuration.getDomainAxisType())) {
|
||||||
configuration.setDomainAxisType(typesX[0]);
|
configuration.setDomainAxisType(typesX[0]);
|
||||||
modified = true;
|
modified = true;
|
||||||
@ -264,11 +264,10 @@ public class PlotPanel<T extends DataType & Groupable<G>, B extends DataBranch<T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDefaultConfiguration(PlotConfiguration<T, B> newConfiguration) {
|
protected void setDefaultConfiguration(C newConfiguration) {
|
||||||
defaultConfiguration = newConfiguration;
|
defaultConfiguration = newConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setToCustom() {
|
protected void setToCustom() {
|
||||||
modifying++;
|
modifying++;
|
||||||
configuration.setName(CUSTOM);
|
configuration.setName(CUSTOM);
|
||||||
|
@ -33,7 +33,6 @@ import info.openrocket.core.simulation.FlightEvent;
|
|||||||
import info.openrocket.core.startup.Application;
|
import info.openrocket.core.startup.Application;
|
||||||
import info.openrocket.core.preferences.ApplicationPreferences;
|
import info.openrocket.core.preferences.ApplicationPreferences;
|
||||||
|
|
||||||
import info.openrocket.swing.gui.plot.PlotConfiguration;
|
|
||||||
import info.openrocket.swing.gui.plot.PlotPanel;
|
import info.openrocket.swing.gui.plot.PlotPanel;
|
||||||
import info.openrocket.swing.gui.plot.PlotTypeSelector;
|
import info.openrocket.swing.gui.plot.PlotTypeSelector;
|
||||||
import info.openrocket.swing.gui.plot.SimulationPlotConfiguration;
|
import info.openrocket.swing.gui.plot.SimulationPlotConfiguration;
|
||||||
@ -50,7 +49,7 @@ import info.openrocket.swing.gui.theme.UITheme;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBranch, FlightDataTypeGroup,
|
public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBranch, FlightDataTypeGroup,
|
||||||
PlotTypeSelector<FlightDataTypeGroup, FlightDataType>> {
|
SimulationPlotConfiguration, PlotTypeSelector<FlightDataTypeGroup, FlightDataType>> {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = -2227129713185477998L;
|
private static final long serialVersionUID = -2227129713185477998L;
|
||||||
|
|
||||||
@ -154,9 +153,9 @@ public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBra
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setDefaultConfiguration(PlotConfiguration<FlightDataType, FlightDataBranch> newConfiguration) {
|
protected void setDefaultConfiguration(SimulationPlotConfiguration newConfiguration) {
|
||||||
super.setDefaultConfiguration(newConfiguration);
|
super.setDefaultConfiguration(newConfiguration);
|
||||||
DEFAULT_CONFIGURATION = (SimulationPlotConfiguration) newConfiguration;
|
DEFAULT_CONFIGURATION = newConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFlightEventsSelectorWidgets(JPanel selectorPanel) {
|
private void addFlightEventsSelectorWidgets(JPanel selectorPanel) {
|
||||||
@ -184,7 +183,7 @@ public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBra
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
for (FlightEvent.Type t : FlightEvent.Type.values()) {
|
for (FlightEvent.Type t : FlightEvent.Type.values()) {
|
||||||
SimulationPlotConfiguration configuration = (SimulationPlotConfiguration) getConfiguration();
|
SimulationPlotConfiguration configuration = getConfiguration();
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
configuration.setEvent(t, true);
|
configuration.setEvent(t, true);
|
||||||
}
|
}
|
||||||
@ -271,7 +270,7 @@ public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBra
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
setDefaultConfiguration(configuration.clone());
|
setDefaultConfiguration(configuration.clone());
|
||||||
return SimulationPlotDialog.getPlot(parent, simulation, (SimulationPlotConfiguration) configuration);
|
return SimulationPlotDialog.getPlot(parent, simulation, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -326,7 +325,7 @@ public class SimulationPlotPanel extends PlotPanel<FlightDataType, FlightDataBra
|
|||||||
@Override
|
@Override
|
||||||
public Object getValueAt(int row, int column) {
|
public Object getValueAt(int row, int column) {
|
||||||
return switch (column) {
|
return switch (column) {
|
||||||
case 0 -> ((SimulationPlotConfiguration) configuration).isEventActive(eventTypes[row]);
|
case 0 -> configuration.isEventActive(eventTypes[row]);
|
||||||
case 1 -> eventTypes[row].toString();
|
case 1 -> eventTypes[row].toString();
|
||||||
default -> throw new IndexOutOfBoundsException("column=" + column);
|
default -> throw new IndexOutOfBoundsException("column=" + column);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user