1 package net.sf.openrocket.gui.components;
3 import java.awt.event.ActionEvent;
4 import java.util.ArrayList;
7 import javax.swing.AbstractAction;
8 import javax.swing.JPanel;
9 import javax.swing.JToggleButton;
10 import javax.swing.event.ChangeEvent;
11 import javax.swing.event.ChangeListener;
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.l10n.Translator;
15 import net.sf.openrocket.rocketcomponent.Configuration;
16 import net.sf.openrocket.startup.Application;
19 public class StageSelector extends JPanel implements ChangeListener {
20 private static final Translator trans = Application.getTranslator();
22 private final Configuration configuration;
24 private List<JToggleButton> buttons = new ArrayList<JToggleButton>();
26 public StageSelector(Configuration configuration) {
27 super(new MigLayout("gap 0!"));
28 this.configuration = configuration;
30 JToggleButton button = new JToggleButton(new StageAction(0));
35 configuration.addChangeListener(this);
38 private void updateButtons() {
39 int stages = configuration.getStageCount();
40 if (buttons.size() == stages)
43 while (buttons.size() > stages) {
44 JToggleButton button = buttons.remove(buttons.size() - 1);
48 while (buttons.size() < stages) {
49 JToggleButton button = new JToggleButton(new StageAction(buttons.size()));
61 public void stateChanged(ChangeEvent e) {
66 private class StageAction extends AbstractAction implements ChangeListener {
67 private final int stage;
69 public StageAction(final int stage) {
71 configuration.addChangeListener(this);
76 public Object getValue(String key) {
77 if (key.equals(NAME)) {
79 return trans.get("StageAction.Stage") + " " + (stage + 1);
81 return super.getValue(key);
85 public void actionPerformed(ActionEvent e) {
86 configuration.setToStage(stage);
88 // boolean state = (Boolean)getValue(SELECTED_KEY);
89 // if (state == true) {
90 // // Was disabled, now enabled
91 // configuration.setToStage(stage);
93 // // Was enabled, check what to do
94 // if (configuration.isStageActive(stage + 1)) {
95 // configuration.setToStage(stage);
98 // configuration.setAllStages();
100 // configuration.setToStage(stage-1);
103 // stateChanged(null);
108 public void stateChanged(ChangeEvent e) {
109 this.putValue(SELECTED_KEY, configuration.isStageActive(stage));