Add preference for marker visibility

This commit is contained in:
SiboVG 2022-07-18 00:28:05 +02:00
parent 391dc37e9b
commit d0be2e5e07
6 changed files with 58 additions and 6 deletions

View File

@ -294,6 +294,8 @@ pref.dlg.lbl.PositiontoinsertStages = Position to insert new stages:
pref.dlg.lbl.Confirmdeletion = Confirm deletion of simulations.
pref.dlg.checkbox.Runsimulations = Run out-dated simulations when you open the simulation tab.
pref.dlg.checkbox.Updateestimates = Update estimated flight parameters in design window
pref.dlg.checkbox.Markers = Only show pod set/booster markers when the pod set/booster is selected
pref.dlg.checkbox.Markers.ttip = <html>If checked, pod set/booster markers will only be shown when the pod set/booster is selected.<br>If unchecked, pod set/booster markers will always be shown.</html>
pref.dlg.checkbox.AlwaysOpenLeftmost = Always open leftmost tab when opening a component edit dialog
pref.dlg.checkbox.AlwaysOpenLeftmost.ttip = <html>If checked, a component edit dialog will always pop up with the first tab selected.<br>If unchecked, the previous selected tab will be used.</html>
pref.dlg.lbl.User-definedthrust = User-defined thrust curves:

View File

@ -68,6 +68,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";
private static final String SHOW_MARKERS = "SHOW_MARKERS";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING";
//Preferences related to 3D graphics
@ -469,7 +470,26 @@ public abstract class Preferences implements ChangeSource {
public final boolean isAlwaysOpenLeftmostTab() {
return this.getBoolean(OPEN_LEFTMOST_DESIGN_TAB, false);
}
/**
* Set whether pod set/booster markers should only be displayed when the pod set/booster is selected.
* @param enabled true if pod set/booster markers should only be displayed when the pod set/booster is selected,
* false if they should be displayed permanently.
*/
public final void setShowMarkers(boolean enabled) {
this.putBoolean(SHOW_MARKERS, enabled);
}
/**
* Answer if pod set/booster markers should only be displayed when the pod set/booster is selected
*
* @return true if pod set/booster markers should only be displayed when the pod set/booster is selected,
* false if they should be displayed permanently.
*/
public final boolean isShowMarkers() {
return this.getBoolean(SHOW_MARKERS, false);
}
/**
* Return the OpenRocket unique ID.
*

View File

@ -11,6 +11,7 @@ import javax.swing.JSpinner;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.main.BasicFrame;
import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.UnitGroup;
@ -93,7 +94,6 @@ public class DesignPreferencesPanel extends PreferencesPanel {
// // Always open leftmost tab when opening a component edit dialog
final JCheckBox alwaysOpenLeftmostTab = new JCheckBox(
trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost"));
alwaysOpenLeftmostTab.setSelected(preferences.isAlwaysOpenLeftmostTab());
alwaysOpenLeftmostTab.setToolTipText(trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost.ttip"));
alwaysOpenLeftmostTab.addActionListener(new ActionListener() {
@ -103,7 +103,7 @@ public class DesignPreferencesPanel extends PreferencesPanel {
.isSelected());
}
});
this.add(alwaysOpenLeftmostTab, "wrap, growx, span 2");
this.add(alwaysOpenLeftmostTab, "wrap, growx, spanx");
// // Update flight estimates in the design window
final JCheckBox updateEstimates = new JCheckBox(
@ -117,5 +117,23 @@ public class DesignPreferencesPanel extends PreferencesPanel {
}
});
this.add(updateEstimates, "wrap, growx, sg combos ");
// // Only show pod set/booster markers when they are selected
final JCheckBox showMarkers = new JCheckBox(
trans.get("pref.dlg.checkbox.Markers"));
showMarkers.setToolTipText(trans.get("pref.dlg.checkbox.Markers.ttip"));
showMarkers.setSelected(preferences.isShowMarkers());
showMarkers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
preferences.setShowMarkers(showMarkers
.isSelected());
// Update all BasicFrame rocket panel figures because it can change due to the preference change
for (BasicFrame frame : BasicFrame.getAllFrames()) {
frame.getRocketPanel().updateFigures();
}
}
});
this.add(showMarkers, "wrap, growx, spanx");
}
}

View File

@ -117,7 +117,7 @@ public class BasicFrame extends JFrame {
* List of currently open frames. When the list goes empty
* it is time to exit the application.
*/
private static final ArrayList<BasicFrame> frames = new ArrayList<BasicFrame>();
private static final List<BasicFrame> frames = new ArrayList<BasicFrame>();
private static BasicFrame startupFrame = null; // the frame that was created at startup
@ -490,6 +490,10 @@ public class BasicFrame extends JFrame {
return result;
}
public RocketPanel getRocketPanel() {
return rocketpanel;
}
/**
* Creates the menu for the window.
*/
@ -1890,6 +1894,13 @@ public class BasicFrame extends JFrame {
return null;
}
/**
* Return all BasicFrame instances
*/
public static List<BasicFrame> getAllFrames() {
return frames;
}
/**
* Checks whether all the BasicFrames are closed.
* @return true if all the BasicFrames are closed, false if not

View File

@ -54,6 +54,7 @@ import net.sf.openrocket.util.Transformation;
public class RocketFigure extends AbstractScaleFigure {
private final static Logger log = LoggerFactory.getLogger(FinPointFigure.class);
protected final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure";
private static final String ROCKET_FIGURE_SUFFIX = "Shapes";
@ -382,7 +383,7 @@ public class RocketFigure extends AbstractScaleFigure {
final RocketComponent comp = entry.getKey();
// Only draw podsets when they are selected
if (comp instanceof PodSet || comp instanceof ParallelStage) {
if ((comp instanceof PodSet || comp instanceof ParallelStage) && preferences.isShowMarkers()) {
boolean selected = false;
// Check if component is in the selection

View File

@ -252,7 +252,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
});
}
private void updateFigures() {
public void updateFigures() {
if (!is3d)
figure.updateFigure();
else