From 25f619aa1962dcae8e5badcc5eb99f392af59c0b Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Fri, 19 Oct 2012 14:34:44 -0500 Subject: [PATCH] Added button and dialog to select the ignition for a given motor. --- core/resources/l10n/messages.properties | 1 + .../MotorConfigurationPanel.java | 34 +++++- .../SelectIgnitionConfigDialog.java | 105 ++++++++++++++++++ 3 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SelectIgnitionConfigDialog.java diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 642c0c09e..c9d39a86c 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -179,6 +179,7 @@ edtmotorconfdlg.but.Removeconfiguration = Remove edtmotorconfdlg.but.Renameconfiguration = Rename edtmotorconfdlg.but.Newconfiguration = New edtmotorconfdlg.but.Copyconfiguration = Copy +edtmotorconfdlg.but.Selectignition = Select ignition edtmotorconfdlg.lbl.Motormounts = Motor mounts: edtmotorconfdlg.title.Editmotorconf = Edit motor configurations edtmotorconfdlg.selectcomp = Select which components function as motor mounts: diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java index f67d9708c..785da48f1 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java @@ -32,7 +32,7 @@ public class MotorConfigurationPanel extends JPanel { private final Rocket rocket; private final MotorConfigurationTableModel configurationTableModel; - private final JButton selectMotorButton, removeMotorButton; + private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton; private MotorMount currentMount = null; final MotorMount[] mounts; @@ -86,9 +86,8 @@ public class MotorConfigurationPanel extends JPanel { @Override public void mouseClicked(MouseEvent e) { int row = configurationTable.getSelectedRow(); - int column = configurationTable.getSelectedColumn(); - if ( row >= 0 & column == 1) { + if ( row >= 0 ) { currentMount = findMount(row); } else { currentMount = null; @@ -130,7 +129,17 @@ public class MotorConfigurationPanel extends JPanel { removeMotor(); } }); - this.add(removeMotorButton,"sizegroup button, wrap"); + this.add(removeMotorButton,"sizegroup button"); + + //// Select Ignition button + selectIgnitionButton = new JButton(FlightConfigurationDialog.trans.get("edtmotorconfdlg.but.Selectignition")); + selectIgnitionButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + selectIgnition(); + } + }); + this.add(selectIgnitionButton,"sizegroup button, wrap"); } @@ -144,6 +153,7 @@ public class MotorConfigurationPanel extends JPanel { String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); selectMotorButton.setEnabled(currentMount != null && currentID != null); removeMotorButton.setEnabled(currentMount != null && currentID != null); + selectIgnitionButton.setEnabled(currentMount != null && currentID != null); } @@ -182,6 +192,22 @@ public class MotorConfigurationPanel extends JPanel { configurationTableModel.fireTableDataChanged(); updateButtonState(); } + + private void selectIgnition() { + String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); + if (currentID == null || currentMount == null) + return; + + SelectIgnitionConfigDialog dialog = new SelectIgnitionConfigDialog( + this.flightConfigurationDialog, + rocket, + currentMount ); + dialog.setVisible(true); + + flightConfigurationDialog.fireContentsUpdated(); + configurationTableModel.fireTableDataChanged(); + updateButtonState(); + } public void makeMotorMount( MotorMount mount, boolean isMotorMount ) { mount.setMotorMount( isMotorMount ); diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SelectIgnitionConfigDialog.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SelectIgnitionConfigDialog.java new file mode 100644 index 000000000..f3525a049 --- /dev/null +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SelectIgnitionConfigDialog.java @@ -0,0 +1,105 @@ +package net.sf.openrocket.gui.dialogs.flightconfiguration; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSpinner; + +import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.gui.SpinnerEditor; +import net.sf.openrocket.gui.adaptors.BasicEnumModel; +import net.sf.openrocket.gui.adaptors.DoubleModel; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration.IgnitionEvent; +import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.unit.UnitGroup; + +public class SelectIgnitionConfigDialog extends JDialog { + + MotorConfiguration newConfiguration; + + SelectIgnitionConfigDialog(JDialog parent,final Rocket rocket, final MotorMount component ) { + super(parent); + super.setModal(true); + final String configId = rocket.getDefaultConfiguration().getFlightConfigurationID(); + + newConfiguration = component.getFlightConfiguration(configId); + if ( newConfiguration == null ) { + newConfiguration = component.getDefaultFlightConfiguration().clone(); + } else { + // Clone the existing so cancel works. When the user selects OK, this configuration + // is put back in there. + newConfiguration = newConfiguration.clone(); + } + + JPanel panel = new JPanel(new MigLayout("fill")); + + // Select ignition event + //// Ignition at: + panel.add(new JLabel(FlightConfigurationDialog.trans.get("MotorCfg.lbl.Ignitionat")), ""); + + final JComboBox event = new JComboBox(new BasicEnumModel(IgnitionEvent.class)); + event.setSelectedItem( newConfiguration.getIgnitionEvent() ); + //FIXME set selection based on newConfiguration.getIgnitionEvent(); + panel.add(event, "growx, wrap"); + + // ... and delay + //// plus + panel.add(new JLabel(FlightConfigurationDialog.trans.get("MotorCfg.lbl.plus")), "gap indent, skip 1, span, split"); + + Double delayValue = newConfiguration.getIgnitionDelay(); + final DoubleModel delay = new DoubleModel((delayValue==null?0:delayValue.doubleValue()), UnitGroup.UNITS_NONE, 0d); + JSpinner spin = new JSpinner(delay.getSpinnerModel()); + spin.setEditor(new SpinnerEditor(spin,3)); + panel.add(spin, "gap rel rel"); + + //// seconds + panel.add(new JLabel(FlightConfigurationDialog.trans.get("MotorCfg.lbl.seconds")), "wrap unrel"); + + JButton okButton = new JButton(FlightConfigurationDialog.trans.get("button.ok")); + okButton.addActionListener( new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + + //// extract ignition event type; + IgnitionEvent ignitionEvent = (IgnitionEvent) event.getSelectedItem(); + newConfiguration.setIgnitionEvent(ignitionEvent); + + //// extract ignition delay time; + double ignitionDelay = delay.getValue(); + newConfiguration.setIgnitionDelay(ignitionDelay); + + component.setFlightConfiguration(configId, newConfiguration); + + SelectIgnitionConfigDialog.this.setVisible(false); + } + + }); + + panel.add( okButton ); + + JButton cancel = new JButton(FlightConfigurationDialog.trans.get("button.cancel")); + cancel.addActionListener( new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + SelectIgnitionConfigDialog.this.setVisible(false); + } + + }); + + panel.add( cancel ); + + this.setContentPane(panel); + this.validate(); + this.pack(); + + } +}