Add option to switch (time) flight event markers to icons

This commit is contained in:
SiboVG 2022-12-29 23:29:52 +01:00
parent 447a025545
commit 7b88cb468e
4 changed files with 72 additions and 6 deletions

View File

@ -719,6 +719,11 @@ simplotpanel.RIGHT_NAME = Right
simplotpanel.CUSTOM = Custom
SimulationPlotPanel.error.noPlotSelected = Please add one or more variables to plot on the Y-axis.
SimulationPlotPanel.error.noPlotSelected.title = Nothing to plot
simplotpanel.MarkerStyle.lbl.MarkerStyle = Marker style:
simplotpanel.MarkerStyle.lbl.MarkerStyle.ttip = Style of the flight event marker (how it's drawn in the simulation plot)
simplotpanel.MarkerStyle.btn.VerticalMarker = Vertical marker
simplotpanel.MarkerStyle.btn.Icon = Icon
simplotpanel.MarkerStyle.OnlyInTime = Only available for time domain, other domains only support icon markers
! Component add buttons
compaddbuttons.AxialStage = Stage

View File

@ -76,6 +76,7 @@ public abstract class Preferences implements ChangeSource {
public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors";
private static final String AUTO_OPEN_LAST_DESIGN = "AUTO_OPEN_LAST_DESIGN";
private static final String OPEN_LEFTMOST_DESIGN_TAB = "OPEN_LEFTMOST_DESIGN_TAB";
public static final String MARKER_STYLE_ICON = "MARKER_STYLE_ICON";
private static final String SHOW_MARKERS = "SHOW_MARKERS";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING";

View File

@ -20,9 +20,12 @@ import java.util.regex.Pattern;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.simulation.SimulationPlotPanel;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.LinearInterpolator;
@ -65,6 +68,8 @@ import org.jfree.ui.TextAnchor;
*/
@SuppressWarnings("serial")
public class SimulationPlot {
private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
private static final float PLOT_STROKE_WIDTH = 1.5f;
@ -79,7 +84,7 @@ public class SimulationPlot {
private final LegendItems legendItems;
int branchCount;
private int branchCount;
void setShowPoints(boolean showPoints) {
for (ModifiedXYItemRenderer r : renderers) {
@ -457,7 +462,7 @@ public class SimulationPlot {
}
// Plot the markers
if (config.getDomainAxisType() == FlightDataType.TYPE_TIME) {
if (config.getDomainAxisType() == FlightDataType.TYPE_TIME && !preferences.getBoolean(Preferences.MARKER_STYLE_ICON, false)) {
double markerWidth = 0.01 * plot.getDomainAxis().getUpperBound();
// Domain time is plotted as vertical markers

View File

@ -9,12 +9,15 @@ import java.util.Arrays;
import java.util.EnumSet;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
@ -29,11 +32,13 @@ import net.sf.openrocket.gui.plot.PlotConfiguration;
import net.sf.openrocket.gui.plot.SimulationPlotDialog;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.util.Utils;
import net.sf.openrocket.gui.widgets.SelectColorButton;
@ -47,6 +52,7 @@ public class SimulationPlotPanel extends JPanel {
private static final long serialVersionUID = -2227129713185477998L;
private static final Translator trans = Application.getTranslator();
private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
// TODO: LOW: Should these be somewhere else?
public static final int AUTO = -1;
@ -201,7 +207,7 @@ public class SimulationPlotPanel extends JPanel {
typeSelectorPanel = new JPanel(new MigLayout("gapy rel"));
JScrollPane scroll = new JScrollPane(typeSelectorPanel);
this.add(scroll, "spany 2, height 10px, wmin 400lp, grow 100, gapright para");
this.add(scroll, "spany 3, height 10px, wmin 400lp, grow 100, gapright para");
//// Flight events
@ -244,10 +250,46 @@ public class SimulationPlotPanel extends JPanel {
eventTableModel.fireTableDataChanged();
}
});
this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap para");
this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap");
//// Style event marker
JLabel styleEventMarker = new JLabel(trans.get("simplotpanel.MarkerStyle.lbl.MarkerStyle"));
JRadioButton radioVerticalMarker = new JRadioButton(trans.get("simplotpanel.MarkerStyle.btn.VerticalMarker"));
JRadioButton radioIcon = new JRadioButton(trans.get("simplotpanel.MarkerStyle.btn.Icon"));
ButtonGroup bg = new ButtonGroup();
bg.add(radioVerticalMarker);
bg.add(radioIcon);
boolean useIcon = preferences.getBoolean(Preferences.MARKER_STYLE_ICON, false);
if (useIcon) {
radioIcon.setSelected(true);
} else {
radioVerticalMarker.setSelected(true);
}
radioIcon.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (modifying > 0)
return;
preferences.putBoolean(Preferences.MARKER_STYLE_ICON, radioIcon.isSelected());
}
});
domainTypeSelector.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateStyleEventWidgets(styleEventMarker, radioVerticalMarker, radioIcon);
}
});
updateStyleEventWidgets(styleEventMarker, radioVerticalMarker, radioIcon);
this.add(styleEventMarker, "split 3, growx");
this.add(radioVerticalMarker);
this.add(radioIcon, "wrap para");
//// New Y axis plot type
button = new SelectColorButton(trans.get("simplotpanel.but.NewYaxisplottype"));
button.addActionListener(new ActionListener() {
@ -322,6 +364,19 @@ public class SimulationPlotPanel extends JPanel {
*/
updatePlots();
}
private void updateStyleEventWidgets(JLabel styleEventMarker, JRadioButton radioVerticalMarker, JRadioButton radioIcon) {
if (modifying > 0)
return;
FlightDataType type = (FlightDataType) domainTypeSelector.getSelectedItem();
boolean isTime = type == FlightDataType.TYPE_TIME;
styleEventMarker.setEnabled(isTime);
radioVerticalMarker.setEnabled(isTime);
radioIcon.setEnabled(isTime);
styleEventMarker.setToolTipText(isTime ? trans.get("simplotpanel.MarkerStyle.lbl.MarkerStyle.ttip") : trans.get("simplotpanel.MarkerStyle.OnlyInTime"));
radioVerticalMarker.setToolTipText(isTime ? null : trans.get("simplotpanel.MarkerStyle.OnlyInTime"));
radioIcon.setToolTipText(isTime ? null : trans.get("simplotpanel.MarkerStyle.OnlyInTime"));
}
public JDialog doPlot(Window parent) {
if (configuration.getTypeCount() == 0) {