Disable stage selector if stage has no children + ttips

This commit is contained in:
SiboVG 2022-09-19 14:32:46 +02:00
parent 6585e07140
commit 26414da9f7
2 changed files with 22 additions and 1 deletions

View File

@ -64,6 +64,8 @@ RocketPanel.lbl.Stability = Stability:
RocketPanel.checkbox.ShowCGCP = Show CG/CP RocketPanel.checkbox.ShowCGCP = Show CG/CP
RocketPanel.checkbox.ShowCGCP.ttip = Disabling this checkbox hides the CG and CP markings in the rocket view. RocketPanel.checkbox.ShowCGCP.ttip = Disabling this checkbox hides the CG and CP markings in the rocket view.
RocketPanel.lbl.Stages = Stages: RocketPanel.lbl.Stages = Stages:
RocketPanel.btn.Stages.Toggle.ttip = Toggle this button to activate or deactive the corresponding stage in your design.
RocketPanel.btn.Stages.NoChildren.ttip = <html>This stages does not have any child components and is therefore marked as inactive.<br>Add components to the stage to activate it.</html>
RocketPanel.ttip.Rotation = Change the rocket's roll rotation (only affects the rocket view) RocketPanel.ttip.Rotation = Change the rocket's roll rotation (only affects the rocket view)
! BasicFrame ! BasicFrame

View File

@ -11,18 +11,21 @@ import javax.swing.JToggleButton;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.widgets.SelectColorToggleButton; import net.sf.openrocket.gui.widgets.SelectColorToggleButton;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.StateChangeListener;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class StageSelector extends JPanel implements StateChangeListener { public class StageSelector extends JPanel implements StateChangeListener {
private static final Translator trans = Application.getTranslator();
private final Rocket rocket; private final Rocket rocket;
private List<JToggleButton> buttons = new ArrayList<JToggleButton>(); private List<JToggleButton> buttons = new ArrayList<JToggleButton>();
@ -64,6 +67,13 @@ public class StageSelector extends JPanel implements StateChangeListener {
public StageAction(final AxialStage stage) { public StageAction(final AxialStage stage) {
this.stage = stage; this.stage = stage;
if (this.stage.getChildCount() == 0) {
putValue(SHORT_DESCRIPTION, trans.get("RocketPanel.btn.Stages.NoChildren.ttip"));
setEnabled(false);
} else {
putValue(SHORT_DESCRIPTION, trans.get("RocketPanel.btn.Stages.Toggle.ttip"));
}
updateUI();
} }
@Override @Override
@ -77,6 +87,15 @@ public class StageSelector extends JPanel implements StateChangeListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Don't toggle the state if the stage has no children (and is therefore inactive)
if (stage.getChildCount() == 0) {
putValue(SHORT_DESCRIPTION, trans.get("RocketPanel.btn.Stages.NoChildren.ttip"));
setEnabled(false);
return;
} else {
setEnabled(true);
putValue(SHORT_DESCRIPTION, trans.get("RocketPanel.btn.Stages.Toggle.ttip"));
}
rocket.getSelectedConfiguration().toggleStage(stage.getStageNumber()); rocket.getSelectedConfiguration().toggleStage(stage.getStageNumber());
rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE ); rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE );
} }