cleaned up gui components in StageConfig

This commit is contained in:
Daniel_M_Williams 2015-08-24 10:53:50 -04:00
parent 29430218d5
commit c1c882eb00

View File

@ -1,17 +1,13 @@
package net.sf.openrocket.gui.configdialog; package net.sf.openrocket.gui.configdialog;
import javax.swing.ComboBoxModel; import javax.swing.ComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSpinner; import javax.swing.JSpinner;
import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.BooleanModel;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.adaptors.EnumModel; import net.sf.openrocket.gui.adaptors.EnumModel;
import net.sf.openrocket.gui.adaptors.IntegerModel; import net.sf.openrocket.gui.adaptors.IntegerModel;
@ -19,7 +15,6 @@ import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.components.StyledLabel.Style; import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.OutsideComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Stage; import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
@ -27,8 +22,8 @@ import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
public class StageConfig extends RocketComponentConfig { public class StageConfig extends RocketComponentConfig {
private static final long serialVersionUID = -944969957186522471L;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
public StageConfig(OpenRocketDocument document, RocketComponent component) { public StageConfig(OpenRocketDocument document, RocketComponent component) {
super(document, component); super(document, component);
@ -40,8 +35,8 @@ public class StageConfig extends RocketComponentConfig {
trans.get("tab.Separation.ttip"), 1); trans.get("tab.Separation.ttip"), 1);
} }
// all stage instances should qualify here... // only stages which are actually off-centerline will get the dialog here:
if( component instanceof OutsideComponent ){ if( ! component.isCenterline()){
tabbedPane.insertTab( trans.get("RocketCompCfg.tab.Parallel"), null, parallelTab( (Stage) component ), trans.get("RocketCompCfg.tab.ParallelComment"), 2); tabbedPane.insertTab( trans.get("RocketCompCfg.tab.Parallel"), null, parallelTab( (Stage) component ), trans.get("RocketCompCfg.tab.ParallelComment"), 2);
} }
} }
@ -49,57 +44,40 @@ public class StageConfig extends RocketComponentConfig {
private JPanel parallelTab( final Stage stage ){ private JPanel parallelTab( final Stage stage ){
JPanel motherPanel = new JPanel( new MigLayout("fill")); JPanel motherPanel = new JPanel( new MigLayout("fill"));
// enable parallel staging
motherPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "spanx 3, growx, wrap");
BooleanModel parallelEnabledModel = new BooleanModel( component, "Outside");
parallelEnabledModel.setValue( stage.getOutside());
JCheckBox parallelEnabled = new JCheckBox( parallelEnabledModel);
parallelEnabled.setText(trans.get("Stage.parallel.toggle"));
motherPanel.add(parallelEnabled, "wrap");
// set radial distance // set radial distance
JLabel radiusLabel = new JLabel(trans.get("Stage.parallel.radius")); JLabel radiusLabel = new JLabel(trans.get("Stage.parallel.radius"));
motherPanel.add( radiusLabel , "align left"); motherPanel.add( radiusLabel , "align left");
parallelEnabledModel.addEnableComponent( radiusLabel, true);
DoubleModel radiusModel = new DoubleModel( stage, "RadialOffset", UnitGroup.UNITS_LENGTH, 0); DoubleModel radiusModel = new DoubleModel( stage, "RadialOffset", UnitGroup.UNITS_LENGTH, 0);
//radiusModel.setCurrentUnit( UnitGroup.UNITS_LENGTH.getUnit("cm")); //radiusModel.setCurrentUnit( UnitGroup.UNITS_LENGTH.getUnit("cm"));
JSpinner radiusSpinner = new JSpinner( radiusModel.getSpinnerModel()); JSpinner radiusSpinner = new JSpinner( radiusModel.getSpinnerModel());
radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner )); radiusSpinner.setEditor(new SpinnerEditor(radiusSpinner ));
motherPanel.add(radiusSpinner , "growx 1, align right"); motherPanel.add(radiusSpinner , "growx 1, align right");
parallelEnabledModel.addEnableComponent( radiusSpinner, true);
UnitSelector radiusUnitSelector = new UnitSelector(radiusModel); UnitSelector radiusUnitSelector = new UnitSelector(radiusModel);
motherPanel.add(radiusUnitSelector, "growx 1, wrap"); motherPanel.add(radiusUnitSelector, "growx 1, wrap");
parallelEnabledModel.addEnableComponent( radiusUnitSelector , true);
// set location angle around the primary stage // set location angle around the primary stage
JLabel angleLabel = new JLabel(trans.get("Stage.parallel.angle")); JLabel angleLabel = new JLabel(trans.get("Stage.parallel.angle"));
motherPanel.add( angleLabel, "align left"); motherPanel.add( angleLabel, "align left");
parallelEnabledModel.addEnableComponent( angleLabel, true);
DoubleModel angleModel = new DoubleModel( stage, "AngularOffset", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2); DoubleModel angleModel = new DoubleModel( stage, "AngularOffset", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2);
angleModel.setCurrentUnit( UnitGroup.UNITS_ANGLE.getUnit("rad")); angleModel.setCurrentUnit( UnitGroup.UNITS_ANGLE.getUnit("rad"));
JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel()); JSpinner angleSpinner = new JSpinner(angleModel.getSpinnerModel());
angleSpinner.setEditor(new SpinnerEditor(angleSpinner)); angleSpinner.setEditor(new SpinnerEditor(angleSpinner));
motherPanel.add(angleSpinner, "growx 1"); motherPanel.add(angleSpinner, "growx 1");
parallelEnabledModel.addEnableComponent( angleSpinner, true);
UnitSelector angleUnitSelector = new UnitSelector(angleModel); UnitSelector angleUnitSelector = new UnitSelector(angleModel);
motherPanel.add( angleUnitSelector, "growx 1, wrap"); motherPanel.add( angleUnitSelector, "growx 1, wrap");
parallelEnabledModel.addEnableComponent( angleUnitSelector , true);
// set multiplicity // set multiplicity
JLabel countLabel = new JLabel(trans.get("Stage.parallel.count")); JLabel countLabel = new JLabel(trans.get("Stage.parallel.count"));
motherPanel.add( countLabel, "align left"); motherPanel.add( countLabel, "align left");
parallelEnabledModel.addEnableComponent( countLabel, true);
IntegerModel countModel = new IntegerModel( stage, "InstanceCount", 2); IntegerModel countModel = new IntegerModel( stage, "InstanceCount", 2);
JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel()); JSpinner countSpinner = new JSpinner(countModel.getSpinnerModel());
countSpinner.setEditor(new SpinnerEditor(countSpinner)); countSpinner.setEditor(new SpinnerEditor(countSpinner));
motherPanel.add(countSpinner, "growx 1, wrap"); motherPanel.add(countSpinner, "growx 1, wrap");
parallelEnabledModel.addEnableComponent( countSpinner, true);
// setPositions relative to parent component // setPositions relative to parent component
JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")); JLabel positionLabel = new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto"));
motherPanel.add( positionLabel); motherPanel.add( positionLabel);
parallelEnabledModel.addEnableComponent( positionLabel, true);
// EnumModel(ChangeSource source, String valueName, Enum<T>[] values) { // EnumModel(ChangeSource source, String valueName, Enum<T>[] values) {
ComboBoxModel<RocketComponent.Position> relativePositionMethodModel = new EnumModel<RocketComponent.Position>(component, "RelativePositionMethod", ComboBoxModel<RocketComponent.Position> relativePositionMethodModel = new EnumModel<RocketComponent.Position>(component, "RelativePositionMethod",
@ -111,21 +89,17 @@ public class StageConfig extends RocketComponentConfig {
}); });
JComboBox<?> positionMethodCombo = new JComboBox<RocketComponent.Position>( relativePositionMethodModel ); JComboBox<?> positionMethodCombo = new JComboBox<RocketComponent.Position>( relativePositionMethodModel );
motherPanel.add(positionMethodCombo, "spanx 2, growx, wrap"); motherPanel.add(positionMethodCombo, "spanx 2, growx, wrap");
parallelEnabledModel.addEnableComponent( positionMethodCombo, true);
// relative offset labels // relative offset labels
JLabel positionPlusLabel = new JLabel(trans.get("Stage.parallel.offset")); JLabel positionPlusLabel = new JLabel(trans.get("Stage.parallel.offset"));
motherPanel.add( positionPlusLabel ); motherPanel.add( positionPlusLabel );
parallelEnabledModel.addEnableComponent( positionPlusLabel, true );
DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH); DoubleModel axialOffsetModel = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
axialOffsetModel.setCurrentUnit(UnitGroup.UNITS_LENGTH.getUnit("cm")); axialOffsetModel.setCurrentUnit(UnitGroup.UNITS_LENGTH.getUnit("cm"));
JSpinner axPosSpin= new JSpinner( axialOffsetModel.getSpinnerModel()); JSpinner axPosSpin= new JSpinner( axialOffsetModel.getSpinnerModel());
axPosSpin.setEditor(new SpinnerEditor(axPosSpin)); axPosSpin.setEditor(new SpinnerEditor(axPosSpin));
motherPanel.add(axPosSpin, "growx"); motherPanel.add(axPosSpin, "growx");
parallelEnabledModel.addEnableComponent( axPosSpin, true );
UnitSelector axialOffsetUnitSelector = new UnitSelector(axialOffsetModel); UnitSelector axialOffsetUnitSelector = new UnitSelector(axialOffsetModel);
motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap"); motherPanel.add(axialOffsetUnitSelector, "growx 1, wrap");
parallelEnabledModel.addEnableComponent( axialOffsetUnitSelector , true);
// For DEBUG purposes // For DEBUG purposes
//System.err.println(stage.getRocket().toDebugTree()); //System.err.println(stage.getRocket().toDebugTree());