From 5b93c923f596b50cda22f26788fca7471ea82b34 Mon Sep 17 00:00:00 2001 From: Sampo Niskanen Date: Wed, 27 Mar 2013 07:55:42 +0200 Subject: [PATCH] Flight configuration dialogs --- core/resources/l10n/messages.properties | 2 +- .../adaptors/FlightConfigurationModel.java | 28 +++++++-- .../FlightConfigurationDialog.java | 2 +- .../IgnitionSelectionDialog.java | 3 +- .../RecoveryConfigurationPanel.java | 58 ++++++++++++++++- .../SeparationConfigurationPanel.java | 62 ++++++++++++++++++- .../SeparationSelectionDialog.java | 22 +++++++ 7 files changed, 163 insertions(+), 14 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 764ef721c..0e2dcb161 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1856,6 +1856,6 @@ SeparationSelectionDialog.opt.title = Which flight configurations are affected: SeparationSelectionDialog.opt.default = Change all configuration using the default separation event SeparationSelectionDialog.opt.override = Override for the {0} flight configuration only -MotorConfigurationPanel.description = Select the motors and motor ignition events of your rocket.
Motor mounts: Select which components function as motor mounts.
Motor configurations: Select the motor and ignition event for each motor mount. +MotorConfigurationPanel.description = Select the motors and motor ignition events of the selected flight configuration.
Motor mounts: Select which components function as motor mounts.
Motor configurations: Select the motor and ignition event for each motor mount. MotorDescriptionSubstitutor.description = Motors in the configuration diff --git a/core/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java b/core/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java index 88e226db5..e37c488db 100644 --- a/core/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java +++ b/core/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java @@ -21,6 +21,10 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.StateChangeListener; +/** + * A ComboBoxModel that contains a list of flight configurations. The list can + * optionally contain a last element that opens up the configuration edit dialog. + */ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListener { private static final Translator trans = Application.getTranslator(); @@ -33,22 +37,32 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe private final Configuration config; private final Rocket rocket; + private final boolean showEditElement; private Map map = new HashMap(); public FlightConfigurationModel(Configuration config) { - this.config = config; - this.rocket = config.getRocket(); - config.addChangeListener(this); + this(config, true); } + public FlightConfigurationModel(Configuration config, boolean showEditElement) { + this.config = config; + this.rocket = config.getRocket(); + this.showEditElement = showEditElement; + config.addChangeListener(this); + } + @Override public Object getElementAt(int index) { String[] ids = rocket.getFlightConfigurationIDs(); - if (index < 0 || index > ids.length) + + if (index < 0) + return null; + if ((showEditElement && index > ids.length) || + (!showEditElement && index >= ids.length)) return null; if (index == ids.length) @@ -59,7 +73,11 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe @Override public int getSize() { - return rocket.getFlightConfigurationIDs().length + 1; + if (showEditElement) { + return rocket.getFlightConfigurationIDs().length + 1; + } else { + return rocket.getFlightConfigurationIDs().length; + } } @Override diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java index 0b906162e..a460c409e 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java @@ -60,7 +60,7 @@ public class FlightConfigurationDialog extends JDialog { JLabel label = new JLabel("Selected flight configuration:"); panel.add(label, "span, split"); - flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration()); + flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration(), false); JComboBox configSelector = new JComboBox(flightConfigurationModel); configSelector.addActionListener(new ActionListener() { @Override diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java index b6dc0e31b..92cdb2bbf 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java @@ -36,7 +36,7 @@ public class IgnitionSelectionDialog extends JDialog { private IgnitionConfiguration newConfiguration; - IgnitionSelectionDialog(JDialog parent, final Rocket rocket, final MotorMount component) { + public IgnitionSelectionDialog(JDialog parent, final Rocket rocket, final MotorMount component) { super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL); final String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); @@ -44,6 +44,7 @@ public class IgnitionSelectionDialog extends JDialog { JPanel panel = new JPanel(new MigLayout("fill")); + // Edit default or override option boolean isDefault = component.getIgnitionConfiguration().isDefault(id); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel"); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java index 343c55415..42b974c1c 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java @@ -1,5 +1,8 @@ package net.sf.openrocket.gui.dialogs.flightconfiguration; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -8,13 +11,16 @@ import java.util.Iterator; import javax.swing.JButton; import javax.swing.JDialog; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent; @@ -26,8 +32,6 @@ import net.sf.openrocket.unit.UnitGroup; public class RecoveryConfigurationPanel extends JPanel { - // FIXME: Gray italics for default selection - private Translator trans = Application.getTranslator(); @@ -53,7 +57,6 @@ public class RecoveryConfigurationPanel extends JPanel { recoveryTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - JTable table = (JTable) e.getComponent(); updateButtonState(); if (e.getClickCount() == 2) { @@ -62,6 +65,7 @@ public class RecoveryConfigurationPanel extends JPanel { } } }); + recoveryTable.setDefaultRenderer(Object.class, new RecoveryTableCellRenderer()); JScrollPane scroll = new JScrollPane(recoveryTable); this.add(scroll, "span, grow, wrap"); @@ -90,7 +94,12 @@ public class RecoveryConfigurationPanel extends JPanel { } public void fireTableDataChanged() { + int selected = recoveryTable.getSelectedRow(); recoveryTableModel.fireTableDataChanged(); + if (selected >= 0) { + selected = Math.min(selected, recoveryTable.getRowCount() - 1); + recoveryTable.getSelectionModel().setSelectionInterval(selected, selected); + } updateButtonState(); } @@ -209,4 +218,47 @@ public class RecoveryConfigurationPanel extends JPanel { } + + private class RecoveryTableCellRenderer extends DefaultTableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (!(c instanceof JLabel)) { + return c; + } + JLabel label = (JLabel) c; + + RecoveryDevice recoveryDevice = findRecoveryDevice(row); + String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); + + switch (column) { + case 0: + regular(label); + break; + + case 1: + if (recoveryDevice.getDeploymentConfiguration().isDefault(id)) { + shaded(label); + } else { + regular(label); + } + break; + } + + return label; + } + + private void shaded(JLabel label) { + GUIUtil.changeFontStyle(label, Font.ITALIC); + label.setForeground(Color.GRAY); + } + + private void regular(JLabel label) { + GUIUtil.changeFontStyle(label, Font.PLAIN); + label.setForeground(Color.BLACK); + } + + } + } diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java index aff0b9108..f4075e8d6 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java @@ -1,5 +1,8 @@ package net.sf.openrocket.gui.dialogs.flightconfiguration; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -8,13 +11,16 @@ import java.util.Iterator; import javax.swing.JButton; import javax.swing.JDialog; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -25,9 +31,6 @@ import net.sf.openrocket.unit.UnitGroup; public class SeparationConfigurationPanel extends JPanel { - // FIXME: Gray italics for default selection - - private static final Translator trans = Application.getTranslator(); private final FlightConfigurationDialog flightConfigurationDialog; @@ -80,6 +83,7 @@ public class SeparationConfigurationPanel extends JPanel { } } }); + separationTable.setDefaultRenderer(Object.class, new SeparationTableCellRenderer()); JScrollPane scroll = new JScrollPane(separationTable); this.add(scroll, "span, grow, wrap"); @@ -109,12 +113,21 @@ public class SeparationConfigurationPanel extends JPanel { } public void fireTableDataChanged() { + int selected = separationTable.getSelectedRow(); separationTableModel.fireTableDataChanged(); + if (selected >= 0) { + selected = Math.min(selected, separationTable.getRowCount() - 1); + separationTable.getSelectionModel().setSelectionInterval(selected, selected); + } updateButtonState(); } private Stage getSelectedStage() { int row = separationTable.getSelectedRow(); + return getStage(row); + } + + private Stage getStage(int row) { if (row >= 0 && row < stages.length) { return stages[row]; } @@ -200,7 +213,50 @@ public class SeparationConfigurationPanel extends JPanel { return ""; } } + } + + + private class SeparationTableCellRenderer extends DefaultTableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (!(c instanceof JLabel)) { + return c; + } + JLabel label = (JLabel) c; + + Stage stage = getStage(row); + String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); + + switch (column) { + case 0: + regular(label); + break; + + case 1: + if (stage.getStageSeparationConfiguration().isDefault(id)) { + shaded(label); + } else { + regular(label); + } + break; + } + + return label; + } + + private void shaded(JLabel label) { + GUIUtil.changeFontStyle(label, Font.ITALIC); + label.setForeground(Color.GRAY); + } + + private void regular(JLabel label) { + GUIUtil.changeFontStyle(label, Font.PLAIN); + label.setForeground(Color.BLACK); + } } + } diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java index daf6afddb..6232cb441 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java @@ -4,14 +4,17 @@ import java.awt.Dialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JSpinner; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.EnumModel; @@ -28,6 +31,8 @@ public class SeparationSelectionDialog extends JDialog { private static final Translator trans = Application.getTranslator(); + private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); + private StageSeparationConfiguration newConfiguration; SeparationSelectionDialog(JDialog parent, final Rocket rocket, final Stage component) { @@ -41,6 +46,23 @@ public class SeparationSelectionDialog extends JDialog { // FIXME: Edit Default or override option + + // Edit default or override option + boolean isDefault = component.getStageSeparationConfiguration().isDefault(id); + panel.add(new JLabel(trans.get("SeparationSelectionDialog.opt.title")), "span, wrap rel"); + final JRadioButton defaultButton = new JRadioButton(trans.get("SeparationSelectionDialog.opt.default"), isDefault); + panel.add(defaultButton, "span, gapleft para, wrap rel"); + String str = trans.get("SeparationSelectionDialog.opt.override"); + str = str.replace("{0}", descriptor.format(rocket, id)); + final JRadioButton overrideButton = new JRadioButton(str, !isDefault); + panel.add(overrideButton, "span, gapleft para, wrap para"); + + ButtonGroup buttonGroup = new ButtonGroup(); + buttonGroup.add(defaultButton); + buttonGroup.add(overrideButton); + // FIXME: Make buttons work + + // Select separation event panel.add(new JLabel(trans.get("SeparationSelectionDialog.lbl.separation")), "");