From d3ec4f66eba5857d08663a091851e77109c29e11 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 27 Feb 2022 12:50:59 +0100 Subject: [PATCH 1/6] [fixes #1166] Use [{motors}] for flight config motors placeholder --- .../file/openrocket/savers/RocketSaver.java | 2 +- .../rocketcomponent/FlightConfiguration.java | 39 +++++++++++++------ .../sf/openrocket/rocketcomponent/Rocket.java | 2 +- .../RenameConfigDialog.java | 2 +- .../FlightConfigurationPanel.java | 2 +- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java index d2630b6c7..fb03fe8ee 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java @@ -55,7 +55,7 @@ public class RocketSaver extends RocketComponentSaver { } if (flightConfig.isNameOverridden()){ - str += ">" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getName()) + str += ">" + net.sf.openrocket.util.TextUtil.escapeXML(flightConfig.getNameRaw()) + ""; } else { str += "/>"; diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 49377e579..1b116e4c9 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -34,7 +34,8 @@ public class FlightConfiguration implements FlightConfigurableParameter Date: Sun, 27 Feb 2022 12:57:34 +0100 Subject: [PATCH 2/6] Also copy configuration name upon config copy --- .../net/sf/openrocket/rocketcomponent/FlightConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 1b116e4c9..2ec435327 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -716,6 +716,7 @@ public class FlightConfiguration implements FlightConfigurableParameter Date: Sun, 27 Feb 2022 16:23:32 +0100 Subject: [PATCH 3/6] [fixes #1181] Fix initial motor select in MotorChooserDialog Ensures that a table selection in the motor chooser gets translated to an actual motor selection --- .../gui/dialogs/motor/MotorChooserDialog.java | 20 ++++++++-- .../ThrustCurveMotorSelectionPanel.java | 38 +++++++++---------- .../MotorConfigurationPanel.java | 2 +- .../net/sf/openrocket/gui/util/GUIUtil.java | 18 ++++++++- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java index ada3cb748..0148738f9 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java @@ -6,6 +6,8 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; @@ -73,7 +75,13 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { this.setModal(true); this.pack(); this.setLocationByPlatform(true); - GUIUtil.installEscapeCloseOperation(this); + Action closeAction = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent event) { + close(false); + } + }; + GUIUtil.installEscapeCloseOperation(this, closeAction); JComponent focus = selectionPanel.getDefaultFocus(); if (focus != null) { @@ -107,9 +115,13 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { public double getSelectedDelay() { return selectionPanel.getSelectedDelay(); } - - - + + public void open() { + // Update the motor selection based on the motor table value that was already selected in a previous session. + selectionPanel.selectMotorFromTable(); + setVisible(true); + } + @Override public void close(boolean ok) { okClicked = ok; diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index 8605ace7b..9bf036f25 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -112,14 +112,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec setMotorMountAndConfig( fcid, mount ); } - - /** - * Sole constructor. - * - * @param current the currently selected ThrustCurveMotor, or null for none. - * @param delay the currently selected ejection charge delay. - * @param diameter the diameter of the motor mount. - */ + public ThrustCurveMotorSelectionPanel() { super(new MigLayout("fill", "[grow][]")); @@ -264,17 +257,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - int row = table.getSelectedRow(); - if (row >= 0) { - row = table.convertRowIndexToModel(row); - ThrustCurveMotorSet motorSet = model.getMotorSet(row); - log.info(Markers.USER_MARKER, "Selected table row " + row + ": " + motorSet); - if (motorSet != selectedMotorSet) { - select(selectMotor(motorSet)); - } - } else { - log.info(Markers.USER_MARKER, "Selected table row " + row + ", nothing selected"); - } + selectMotorFromTable(); } }); table.addMouseListener(new MouseAdapter() { @@ -608,6 +591,23 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec return list.get(0); } + /** + * Selects a new motor based on the selection in the motor table + */ + public void selectMotorFromTable() { + int row = table.getSelectedRow(); + if (row >= 0) { + row = table.convertRowIndexToModel(row); + ThrustCurveMotorSet motorSet = model.getMotorSet(row); + log.info(Markers.USER_MARKER, "Selected table row " + row + ": " + motorSet); + if (motorSet != selectedMotorSet) { + select(selectMotor(motorSet)); + } + } else { + log.info(Markers.USER_MARKER, "Selected table row " + row + ", nothing selected"); + } + } + /** * Set the values in the delay combo box. If reset is true diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index b96d05cd3..ad3c0f40b 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -288,7 +288,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel double initDelay = initMount.getMotorConfig(initFcId).getEjectionDelay(); motorChooserDialog.setMotorMountAndConfig(initFcId, initMount); - motorChooserDialog.setVisible(true); + motorChooserDialog.open(); Motor mtr = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); diff --git a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java index ba657497f..24234a846 100644 --- a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java +++ b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java @@ -157,9 +157,22 @@ public class GUIUtil { * @param dialog the dialog for which to install the action. */ public static void installEscapeCloseOperation(final JDialog dialog) { + installEscapeCloseOperation(dialog, null); + } + + /** + * Add the correct action to close a JDialog when the ESC key is pressed. + * The dialog is closed by sending it a WINDOW_CLOSING event. + * + * An additional action can be passed which will be executed upon the close action key. + * + * @param dialog the dialog for which to install the action. + * @param action action to execute upon the close action + */ + public static void installEscapeCloseOperation(final JDialog dialog, Action action) { Action dispatchClosing = new AbstractAction() { /** - * + * */ private static final long serialVersionUID = 9196153713666242274L; @@ -172,6 +185,9 @@ public class GUIUtil { JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE, CLOSE_ACTION_KEY); root.getActionMap().put(CLOSE_ACTION_KEY, dispatchClosing); + if (action != null) { + root.getActionMap().put(CLOSE_ACTION_KEY, action); + } } From 7b09634760ca6a830988661fde36fac6bdb9472d Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 28 Feb 2022 17:14:06 +0100 Subject: [PATCH 4/6] [fixes #1190] Fix ConfigDialog Close-button cut off --- .../sf/openrocket/gui/configdialog/RocketComponentConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index daed8e7af..55b4dce42 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -149,7 +149,7 @@ public class RocketComponentConfig extends JPanel { updateFields(); - this.add(buttonPanel, "newline, spanx, growx, height 32!"); + this.add(buttonPanel, "newline, spanx, growx"); } From 6ca76c4e436e7870b52e1011010fc211f3dcb509 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 28 Feb 2022 18:03:40 +0100 Subject: [PATCH 5/6] [fixes #1078] Add opacity slider to appearance config --- core/resources/l10n/messages.properties | 1 + .../appearance/AppearanceBuilder.java | 28 +++++++++++++++ .../gui/configdialog/AppearancePanel.java | 35 ++++++++++++++----- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 038159462..650a40db7 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -826,6 +826,7 @@ AppearanceCfg.but.edit = Edit AppearanceCfg.but.savedefault = Save as default appearance AppearanceCfg.lbl.Texture = Texture: AppearanceCfg.lbl.shine = Shine: +AppearanceCfg.lbl.opacity = Opacity: AppearanceCfg.lbl.color.Color = Color: AppearanceCfg.lbl.color.diffuse = Diffuse Color: AppearanceCfg.lbl.color.ambient = Ambient Color: diff --git a/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java b/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java index f7becf700..08bdd6724 100644 --- a/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java +++ b/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java @@ -161,6 +161,34 @@ public class AppearanceBuilder extends AbstractChangeSource { this.shine = shine; fireChangeEvent(); } + + /** + * Returns the opacity of the paint color, expressed in percentages, where 0 is fully transparent and 1 is fully opaque + * @return opacity value of the pain color, expressed in a percentage + */ + public double getOpacity() { + if (this.paint == null) { + return 100; + } + return (double) this.paint.getAlpha() / 255; + } + + /** + * Sets the opacity/alpha of the paint color. + * + * @param opacity new opacity value expressed in a percentage, where 0 is fully transparent and 1 is fully opaque + */ + public void setOpacity(double opacity) { + if (this.paint == null) { + return; + } + + // Clamp opacity between 0 and 1 + opacity = Math.max(0, Math.min(1, opacity)); + + this.paint.setAlpha((int) (opacity * 255)); + fireChangeEvent(); + } /** * gets the current offset axis U used diff --git a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 308cdebe5..4455876ff 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -581,15 +581,22 @@ public class AppearancePanel extends JPanel { mDefault.addEnableComponent(offsetV, false); panel.add(offsetV, "wrap, w 40"); - // Repeat - panel.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(builder, - "EdgeMode", list)); - mDefault.addEnableComponent(combo, false); - panel.add(combo); + // Opacity + panel.add(new JLabel(trans.get("AppearanceCfg.lbl.opacity"))); + DoubleModel opacityModel = new DoubleModel(builder, "Opacity", + UnitGroup.UNITS_RELATIVE); + JSpinner spinOpacity = new JSpinner(opacityModel.getSpinnerModel()); + spinOpacity.setEditor(new SpinnerEditor(spinOpacity)); + JSlider slideOpacity = new JSlider(opacityModel.getSliderModel(0, 1)); + UnitSelector unitOpacity = new UnitSelector(opacityModel); + + mDefault.addEnableComponent(slideOpacity, false); + mDefault.addEnableComponent(spinOpacity, false); + mDefault.addEnableComponent(unitOpacity, false); + + panel.add(spinOpacity, "split 3, w 50"); + panel.add(unitOpacity); + panel.add(slideOpacity, "w 50"); // Rotation panel.add(new JLabel(trans.get("AppearanceCfg.lbl.texture.rotation"))); @@ -604,5 +611,15 @@ public class AppearancePanel extends JPanel { -Math.PI, Math.PI)); mDefault.addEnableComponent(bs, false); panel.add(bs, "w 50, wrap"); + + // Repeat + panel.add(new JLabel(trans.get("AppearanceCfg.lbl.texture.repeat")), "skip 2"); + EdgeMode[] list = new EdgeMode[EdgeMode.values().length]; + System.arraycopy(EdgeMode.values(), 0, list, 0, + EdgeMode.values().length); + JComboBox combo = new JComboBox(new EnumModel(builder, + "EdgeMode", list)); + mDefault.addEnableComponent(combo, false); + panel.add(combo, "wrap"); } } From 791757640409e91ac7e14e24ea902a1c463da84a Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 28 Feb 2022 10:09:36 -0700 Subject: [PATCH 6/6] Don't save backward-compatible radialdirection for ParallelStage --- .../file/openrocket/savers/RocketComponentSaver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index c4c37c13a..182612544 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -111,7 +111,9 @@ public class RocketComponentSaver { if (c instanceof FinSet || c instanceof TubeFinSet) { elements.add("" + angleOffset + ""); } - else if (!(c instanceof RailButton) && !(c instanceof PodSet)) { + else if (!(c instanceof ParallelStage) && + !(c instanceof PodSet) && + !(c instanceof RailButton)) { elements.add("" + angleOffset + ""); } }