Show stage names instead of stage numbers
This commit is contained in:
parent
fa33c3d823
commit
1bf2ed2a54
swing
Binary file not shown.
@ -15,6 +15,7 @@ import net.sf.openrocket.rocketcomponent.AxialStage;
|
|||||||
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.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.StateChangeListener;
|
import net.sf.openrocket.util.StateChangeListener;
|
||||||
|
|
||||||
@ -36,15 +37,10 @@ public class StageSelector extends JPanel implements StateChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtons( final FlightConfiguration configuration ) {
|
private void updateButtons( final FlightConfiguration configuration ) {
|
||||||
int stages = configuration.getStageCount();
|
|
||||||
if (buttons.size() == stages)
|
|
||||||
return;
|
|
||||||
|
|
||||||
buttons.clear();
|
buttons.clear();
|
||||||
this.removeAll();
|
this.removeAll();
|
||||||
for(AxialStage stage : configuration.getRocket().getStageList()){
|
for(AxialStage stage : configuration.getRocket().getStageList()){
|
||||||
int stageNum = stage.getStageNumber();
|
JToggleButton button = new JToggleButton(new StageAction(stage));
|
||||||
JToggleButton button = new JToggleButton(new StageAction(stageNum));
|
|
||||||
button.setSelected(true);
|
button.setSelected(true);
|
||||||
this.add(button);
|
this.add(button);
|
||||||
buttons.add(button);
|
buttons.add(button);
|
||||||
@ -56,31 +52,31 @@ public class StageSelector extends JPanel implements StateChangeListener {
|
|||||||
@Override
|
@Override
|
||||||
public void stateChanged(EventObject eo) {
|
public void stateChanged(EventObject eo) {
|
||||||
Object source = eo.getSource();
|
Object source = eo.getSource();
|
||||||
if( source instanceof Rocket ){
|
if ((source instanceof Rocket) || (source instanceof AxialStage)) {
|
||||||
Rocket rkt = (Rocket) eo.getSource();
|
Rocket rkt = (Rocket) ((RocketComponent) source).getRoot();
|
||||||
updateButtons( rkt.getSelectedConfiguration() );
|
updateButtons( rkt.getSelectedConfiguration() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StageAction extends AbstractAction {
|
private class StageAction extends AbstractAction {
|
||||||
private final int stageNumber;
|
private final AxialStage stage;
|
||||||
|
|
||||||
public StageAction(final int stage) {
|
public StageAction(final AxialStage stage) {
|
||||||
this.stageNumber = stage;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(String key) {
|
public Object getValue(String key) {
|
||||||
if (key.equals(NAME)) {
|
if (key.equals(NAME)) {
|
||||||
// Stage
|
// Stage
|
||||||
return trans.get("StageAction.Stage") + " " + (stageNumber );
|
return stage.getName();
|
||||||
}
|
}
|
||||||
return super.getValue(key);
|
return super.getValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
rocket.getSelectedConfiguration().toggleStage(stageNumber);
|
rocket.getSelectedConfiguration().toggleStage(stage.getStageNumber());
|
||||||
rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE );
|
rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user