Removed display tab for now. Preference reorganization complete.

This commit is contained in:
Craig Earls 2014-12-24 18:07:13 -08:00
parent ff2f68962c
commit ba2590ee04
6 changed files with 174 additions and 111 deletions

View File

@ -81,7 +81,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
private double launchTemperature = preferences.getDouble(Preferences.LAUNCH_TEMPERATURE, ExtendedISAModel.STANDARD_TEMPERATURE);
private double launchPressure = preferences.getDouble(Preferences.LAUNCH_PRESSURE, ExtendedISAModel.STANDARD_PRESSURE);
private double timeStep = RK4SimulationStepper.RECOMMENDED_TIME_STEP;
private double timeStep = preferences.getDouble(Preferences.SIMULATION_TIME_STEP, RK4SimulationStepper.RECOMMENDED_TIME_STEP);
private double maximumAngle = RK4SimulationStepper.RECOMMENDED_ANGLE_STEP;
private int randomSeed = new Random().nextInt();
@ -91,8 +91,6 @@ public class SimulationOptions implements ChangeSource, Cloneable {
private List<EventListener> listeners = new ArrayList<EventListener>();
public SimulationOptions(Rocket rocket) {
this.rocket = rocket;
}

View File

@ -20,10 +20,12 @@ import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.simulation.RK4SimulationStepper;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.BuildProperties;
import net.sf.openrocket.util.ChangeSource;
import net.sf.openrocket.util.Color;
import net.sf.openrocket.util.GeodeticComputationStrategy;
import net.sf.openrocket.util.LineStyle;
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.StateChangeListener;
@ -84,6 +86,7 @@ public abstract class Preferences implements ChangeSource {
public static final String LAUNCH_PRESSURE = "LaunchPressure";
public static final String LAUNCH_USE_ISA = "LaunchUseISA";
public static final String SIMULATION_TIME_STEP = "SimulationTimeStep";
public static final String GEODETIC_COMPUTATION = "GeodeticComputationStrategy";
private static final AtmosphericModel ISA_ATMOSPHERIC_MODEL = new ExtendedISAModel();
@ -377,7 +380,7 @@ public abstract class Preferences implements ChangeSource {
*
* @return an AtmosphericModel object.
*/
private AtmosphericModel getAtmosphericModel() {
public AtmosphericModel getAtmosphericModel() {
if (this.getBoolean(LAUNCH_USE_ISA, true)) {
return ISA_ATMOSPHERIC_MODEL;
}
@ -385,13 +388,20 @@ public abstract class Preferences implements ChangeSource {
this.getDouble(LAUNCH_PRESSURE, ExtendedISAModel.STANDARD_PRESSURE));
}
public GeodeticComputationStrategy getGeodeticComputation() {
return this.getEnum(GEODETIC_COMPUTATION, GeodeticComputationStrategy.SPHERICAL);
}
public void setGeodeticComputation(GeodeticComputationStrategy gcs) {
this.putEnum(GEODETIC_COMPUTATION, gcs);
}
public double getTimeStep() {
return this.getDouble(this.SIMULATION_TIME_STEP, 0.05);
return this.getDouble(Preferences.SIMULATION_TIME_STEP, RK4SimulationStepper.RECOMMENDED_TIME_STEP);
}
public void setTimeStep(double timeStep) {
if (MathUtil.equals(this.getDouble(SIMULATION_TIME_STEP, 0.05), timeStep))
if (MathUtil.equals(this.getDouble(SIMULATION_TIME_STEP, RK4SimulationStepper.RECOMMENDED_TIME_STEP), timeStep))
return;
this.putDouble(SIMULATION_TIME_STEP, timeStep);
fireChangeEvent();
@ -727,6 +737,7 @@ public abstract class Preferences implements ChangeSource {
DEFAULT_LINE_STYLES.put(RocketComponent.class, LineStyle.SOLID.name());
DEFAULT_LINE_STYLES.put(MassObject.class, LineStyle.DASHED.name());
}
private static final HashMap<Class<?>, String> DEFAULT_COLORS = new HashMap<Class<?>, String>();
static {
DEFAULT_COLORS.put(BodyComponent.class, "0,0,240");

View File

@ -47,7 +47,7 @@ public enum GeodeticComputationStrategy {
},
/**
* Perform geodetic computations with a spherical Earch approximation.
* Perform geodetic computations with a spherical Earth approximation.
*/
SPHERICAL {

View File

@ -52,21 +52,24 @@ import net.sf.openrocket.util.StateChangeListener;
public class AppearancePanel extends JPanel {
private static final Translator trans = Application.getTranslator();
private EditDecalHelper editDecalHelper = Application.getInjector().getInstance(EditDecalHelper.class);
private EditDecalHelper editDecalHelper = Application.getInjector()
.getInstance(EditDecalHelper.class);
private AppearanceBuilder ab;
// We hang on to the user selected appearance when switching to default appearance.
// We hang on to the user selected appearance when switching to default
// appearance.
// this appearance is restored if the user unchecks the "default" button.
private Appearance previousUserSelectedAppearance = null;
// We cache the default appearance for this component to make switching faster.
// We cache the default appearance for this component to make switching
// faster.
private Appearance defaultAppearance = null;
/**
* A non-unit that adjusts by a small amount, suitable for
* values that are on the 0-1 scale
* A non-unit that adjusts by a small amount, suitable for values that are
* on the 0-1 scale
*/
private final static UnitGroup TEXTURE_UNIT = new UnitGroup();
static {
@ -75,46 +78,52 @@ public class AppearancePanel extends JPanel {
public double getNextValue(double value) {
return value + .1;
}
@Override
public double getPreviousValue(double value) {
return value - .1;
}
};
TEXTURE_UNIT.addUnit(no_unit);
}
private static final JColorChooser colorChooser = new JColorChooser();
private class ColorActionListener implements ActionListener {
private final String valueName;
private final Object o;
ColorActionListener(final Object o, final String valueName) {
this.valueName = valueName;
this.o = o;
}
@Override
public void actionPerformed(ActionEvent colorClickEvent) {
try {
final Method getMethod = o.getClass().getMethod("get" + valueName);
final Method setMethod = o.getClass().getMethod("set" + valueName, net.sf.openrocket.util.Color.class);
net.sf.openrocket.util.Color c = (net.sf.openrocket.util.Color) getMethod.invoke(o);
final Method getMethod = o.getClass().getMethod(
"get" + valueName);
final Method setMethod = o.getClass().getMethod(
"set" + valueName, net.sf.openrocket.util.Color.class);
net.sf.openrocket.util.Color c = (net.sf.openrocket.util.Color) getMethod
.invoke(o);
Color awtColor = ColorConversion.toAwtColor(c);
colorChooser.setColor(awtColor);
JDialog d = JColorChooser.createDialog(AppearancePanel.this,
trans.get("RocketCompCfg.lbl.Choosecolor"), true, colorChooser, new ActionListener() {
trans.get("RocketCompCfg.lbl.Choosecolor"), true,
colorChooser, new ActionListener() {
@Override
public void actionPerformed(ActionEvent okEvent) {
Color selected = colorChooser.getColor();
if (selected == null)
return;
try {
setMethod.invoke(o, ColorConversion.fromAwtColor(selected));
setMethod.invoke(o, ColorConversion
.fromAwtColor(selected));
} catch (Throwable e1) {
Application.getExceptionHandler().handleErrorCondition(e1);
Application.getExceptionHandler()
.handleErrorCondition(e1);
}
}
}, null);
@ -124,30 +133,34 @@ public class AppearancePanel extends JPanel {
}
}
}
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
public AppearancePanel(final OpenRocketDocument document,
final RocketComponent c) {
super(new MigLayout("fill", "[150][grow][150][grow]"));
previousUserSelectedAppearance = c.getAppearance();
defaultAppearance = DefaultAppearance.getDefaultAppearance(c);
if (previousUserSelectedAppearance == null) {
previousUserSelectedAppearance = new AppearanceBuilder().getAppearance();
previousUserSelectedAppearance = new AppearanceBuilder()
.getAppearance();
ab = new AppearanceBuilder(defaultAppearance);
} else {
ab = new AppearanceBuilder(previousUserSelectedAppearance);
}
net.sf.openrocket.util.Color figureColor = c.getColor();
if (figureColor == null) {
figureColor = Application.getPreferences().getDefaultColor(c.getClass());
figureColor = Application.getPreferences().getDefaultColor(
c.getClass());
}
final JButton figureColorButton = new JButton(new ColorIcon(figureColor));
final JButton figureColorButton = new JButton(
new ColorIcon(figureColor));
final JButton colorButton = new JButton(new ColorIcon(ab.getPaint()));
final DecalModel decalModel = new DecalModel(this, document, ab);
final JComboBox textureDropDown = new JComboBox(decalModel);
ab.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
@ -157,25 +170,26 @@ public class AppearancePanel extends JPanel {
decalModel.refresh();
}
});
c.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
net.sf.openrocket.util.Color col = c.getColor();
if (col == null) {
col = Application.getPreferences().getDefaultColor(c.getClass());
col = Application.getPreferences().getDefaultColor(
c.getClass());
}
figureColorButton.setIcon(new ColorIcon(col));
}
});
figureColorButton.addActionListener(new ColorActionListener(c, "Color"));
figureColorButton
.addActionListener(new ColorActionListener(c, "Color"));
colorButton.addActionListener(new ColorActionListener(ab, "Paint"));
BooleanModel mDefault = new BooleanModel(c.getAppearance() == null);
BooleanModel fDefault = new BooleanModel(c.getColor() == null);
{// Style Header Row
final JCheckBox colorDefault = new JCheckBox(fDefault);
colorDefault.addActionListener(new ActionListener() {
@ -185,25 +199,33 @@ public class AppearancePanel extends JPanel {
c.setColor(null);
c.setLineStyle(null);
} else {
c.setColor(((SwingPreferences) Application.getPreferences()).getDefaultColor(c.getClass()));
c.setLineStyle(((SwingPreferences) Application.getPreferences()).getDefaultLineStyle(c.getClass()));
c.setColor(((SwingPreferences) Application
.getPreferences()).getDefaultColor(c.getClass()));
c.setLineStyle(((SwingPreferences) Application
.getPreferences()).getDefaultLineStyle(c
.getClass()));
}
}
});
colorDefault.setText(trans.get("RocketCompCfg.checkbox.Usedefaultcolor"));
add(new StyledLabel(trans.get("RocketCompCfg.lbl.Figurestyle"), Style.BOLD));
colorDefault.setText(trans
.get("RocketCompCfg.checkbox.Usedefaultcolor"));
add(new StyledLabel(trans.get("RocketCompCfg.lbl.Figurestyle"),
Style.BOLD));
add(colorDefault);
JButton button = new JButton(trans.get("RocketCompCfg.but.Saveasdefstyle"));
JButton button = new JButton(
trans.get("RocketCompCfg.but.Saveasdefstyle"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (c.getColor() != null) {
((SwingPreferences) Application.getPreferences()).setDefaultColor(c.getClass(), c.getColor());
((SwingPreferences) Application.getPreferences())
.setDefaultColor(c.getClass(), c.getColor());
c.setColor(null);
}
if (c.getLineStyle() != null) {
Application.getPreferences().setDefaultLineStyle(c.getClass(), c.getLineStyle());
Application.getPreferences().setDefaultLineStyle(
c.getClass(), c.getLineStyle());
c.setLineStyle(null);
}
}
@ -211,39 +233,43 @@ public class AppearancePanel extends JPanel {
fDefault.addEnableComponent(button, false);
add(button, "span 2, align right, wrap");
}
{// Figure Color
add(new JLabel(trans.get("RocketCompCfg.lbl.Componentcolor")));
fDefault.addEnableComponent(figureColorButton, false);
add(figureColorButton);
}
{// Line Style
add(new JLabel(trans.get("RocketCompCfg.lbl.Complinestyle")));
LineStyle[] list = new LineStyle[LineStyle.values().length + 1];
System.arraycopy(LineStyle.values(), 0, list, 1, LineStyle.values().length);
JComboBox combo = new JComboBox(new EnumModel<LineStyle>(c, "LineStyle",
//// Default style
System.arraycopy(LineStyle.values(), 0, list, 1,
LineStyle.values().length);
JComboBox combo = new JComboBox(new EnumModel<LineStyle>(c,
"LineStyle",
// // Default style
list, trans.get("LineStyle.Defaultstyle")));
fDefault.addEnableComponent(combo, false);
add(combo, "wrap");
}
add(new JSeparator(SwingConstants.HORIZONTAL), "span, wrap, growx");
{// Texture Header Row
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD));
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"),
Style.BOLD));
final JCheckBox materialDefault = new JCheckBox(mDefault);
materialDefault.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (materialDefault.isSelected()) {
previousUserSelectedAppearance = (ab == null) ? null : ab.getAppearance();
previousUserSelectedAppearance = (ab == null) ? null
: ab.getAppearance();
ab.setAppearance(defaultAppearance);
} else {
ab.setAppearance(previousUserSelectedAppearance);
@ -253,16 +279,18 @@ public class AppearancePanel extends JPanel {
materialDefault.setText(trans.get("AppearanceCfg.lbl.Usedefault"));
add(materialDefault, "wrap");
}
{// Texture File
add(new JLabel(trans.get("AppearanceCfg.lbl.Texture")));
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
mDefault.addEnableComponent(textureDropDown, false);
p.add(textureDropDown, "grow");
add(p, "span 3, growx, wrap");
final JButton editBtn = new JButton(trans.get("AppearanceCfg.but.edit"));
final JButton editBtn = new JButton(
trans.get("AppearanceCfg.but.edit"));
editBtn.setEnabled(ab.getImage() != null);
// Enable the editBtn only when the appearance builder has an Image assigned to it.
// Enable the editBtn only when the appearance builder has an Image
// assigned to it.
ab.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
@ -270,100 +298,110 @@ public class AppearancePanel extends JPanel {
}
});
editBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
DecalImage newImage = editDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage());
DecalImage newImage = editDecalHelper.editDecal(
SwingUtilities
.getWindowAncestor(AppearancePanel.this),
document, c, ab.getImage());
ab.setImage(newImage);
} catch (EditDecalHelperException ex) {
JOptionPane.showMessageDialog(AppearancePanel.this, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(AppearancePanel.this,
ex.getMessage(), "", JOptionPane.ERROR_MESSAGE);
}
}
});
p.add(editBtn);
}
{ // Color
add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color")));
mDefault.addEnableComponent(colorButton, false);
add(colorButton);
}
{ // Scale
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale")));
add(new JLabel("x:"), "split 4");
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX", TEXTURE_UNIT).getSpinnerModel());
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX",
TEXTURE_UNIT).getSpinnerModel());
scaleU.setEditor(new SpinnerEditor(scaleU));
mDefault.addEnableComponent(scaleU, false);
add(scaleU, "w 40");
add(new JLabel("y:"));
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY", TEXTURE_UNIT).getSpinnerModel());
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY",
TEXTURE_UNIT).getSpinnerModel());
scaleV.setEditor(new SpinnerEditor(scaleV));
mDefault.addEnableComponent(scaleV, false);
add(scaleV, "wrap, w 40");
}
{// Shine
add(new JLabel(trans.get("AppearanceCfg.lbl.shine")));
DoubleModel shineModel = new DoubleModel(ab, "Shine", UnitGroup.UNITS_RELATIVE);
DoubleModel shineModel = new DoubleModel(ab, "Shine",
UnitGroup.UNITS_RELATIVE);
JSpinner spin = new JSpinner(shineModel.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
JSlider slide = new JSlider(shineModel.getSliderModel(0, 1));
UnitSelector unit = new UnitSelector(shineModel);
mDefault.addEnableComponent(slide, false);
mDefault.addEnableComponent(spin, false);
mDefault.addEnableComponent(unit, false);
add(spin, "split 3, w 50");
add(unit);
add(slide, "w 50");
}
{ // Offset
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset")));
add(new JLabel("x:"), "split 4");
JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU", TEXTURE_UNIT).getSpinnerModel());
JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU",
TEXTURE_UNIT).getSpinnerModel());
offsetU.setEditor(new SpinnerEditor(offsetU));
mDefault.addEnableComponent(offsetU, false);
add(offsetU, "w 40");
add(new JLabel("y:"));
JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV", TEXTURE_UNIT).getSpinnerModel());
JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV",
TEXTURE_UNIT).getSpinnerModel());
offsetV.setEditor(new SpinnerEditor(offsetV));
mDefault.addEnableComponent(offsetV, false);
add(offsetV, "wrap, w 40");
}
{ // Repeat
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.repeat")));
EdgeMode[] list = new EdgeMode[EdgeMode.values().length];
System.arraycopy(EdgeMode.values(), 0, list, 0, EdgeMode.values().length);
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab, "EdgeMode", list));
System.arraycopy(EdgeMode.values(), 0, list, 0,
EdgeMode.values().length);
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab,
"EdgeMode", list));
mDefault.addEnableComponent(combo, false);
add(combo);
}
{ // Rotation
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.rotation")));
DoubleModel rotationModel = new DoubleModel(ab, "Rotation", UnitGroup.UNITS_ANGLE);
DoubleModel rotationModel = new DoubleModel(ab, "Rotation",
UnitGroup.UNITS_ANGLE);
JSpinner rotation = new JSpinner(rotationModel.getSpinnerModel());
rotation.setEditor(new SpinnerEditor(rotation));
mDefault.addEnableComponent(rotation, false);
add(rotation, "split 3, w 50");
add(new UnitSelector(rotationModel));
BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI));
BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(
-Math.PI, Math.PI));
mDefault.addEnableComponent(bs, false);
add(bs, "w 50, wrap");
}
}
}

View File

@ -33,6 +33,21 @@ public class DesignPreferencesPanel extends PreferencesPanel {
.get("pref.dlg.PrefChoiseSelector3"))),
"wrap para, growx, sg combos");
// Font size of information in panel window
this.add(new JLabel(trans.get("pref.dlg.lbl.Rocketinfofontsize")),
"gapright para");
this.add(
new JComboBox<Object>(new PrefChoiceSelector(
Preferences.ROCKET_INFO_FONT_SIZE,
// // Small
// // Medium
// // Large
trans.get("pref.dlg.PrefFontSmall"), trans
.get("pref.dlg.PrefFontMedium"), trans
.get("pref.dlg.PrefFontLarge"))),
"wrap para, growx, sg combos");
// // Default Mach number
JLabel dfn = new JLabel(trans.get("pref.dlg.lbl.DefaultMach"));
this.add(dfn, "gapright para");

View File

@ -43,36 +43,37 @@ public class PreferencesDialog extends JDialog {
JTabbedPane tabbedPane = new JTabbedPane();
panel.add(tabbedPane, "grow, wrap");
// // Options and Miscellaneous options
// Options and Miscellaneous options
tabbedPane.addTab(trans.get("pref.dlg.tab.Options"), null,
new GeneralPreferencesPanel(this),
trans.get("pref.dlg.tab.Miscellaneousoptions"));
// // Designer options
// Designer options
tabbedPane.addTab(trans.get("pref.dlg.tab.Design"), null,
new DesignPreferencesPanel(), trans.get("pref.dlg.tab.Design"));
// // Simulation options
// Simulation options
tabbedPane.addTab(trans.get("pref.dlg.tab.Simulation"), null,
new SimulationPreferencesPanel(),
trans.get("pref.dlg.tab.Design"));
// // Launch options
// Launch options
tabbedPane.addTab(trans.get("pref.dlg.tab.Launch"), null,
new LaunchPreferencesPanel(), trans.get("pref.dlg.tab.Launch"));
// // Units and Default units
// Units and Default units
tabbedPane.addTab(trans.get("pref.dlg.tab.Units"), null,
new UnitsPreferencesPanel(this),
trans.get("pref.dlg.tab.Defaultunits"));
// // Materials and Custom materials
// Materials and Custom materials
tabbedPane.addTab(trans.get("pref.dlg.tab.Materials"), null,
new MaterialEditPanel(),
trans.get("pref.dlg.tab.Custommaterials"));
// // Decal Editor selection
// Decal Editor selection
tabbedPane.addTab(trans.get("pref.dlg.tab.Graphics"),
new GraphicsPreferencesPanel(this));
// // Default Colors Preferences
tabbedPane.addTab(trans.get("pref.dlg.tab.Colors"),
new DisplayPreferencesPanel());
// // Close button
// Default Colors Preferences
// tabbedPane.addTab(trans.get("pref.dlg.tab.Colors"),
// new DisplayPreferencesPanel());
// Close button
JButton close = new JButton(trans.get("dlg.but.close"));
close.addActionListener(new ActionListener() {
@Override