diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 336dd9dc5..8246fd703 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -52,7 +52,6 @@ RocketPanel.FigTypeAct.Unfinished = 3D Unfinished RocketPanel.lbl.Flightcfg = Flight configuration: -RocketPanel.but.FlightcfgEdit = Edit RocketPanel.lbl.infoMessage = Click to select    Shift+click to select other    Double-click to edit    Click+drag to move RocketPanel.lbl.ViewType = View Type: @@ -327,7 +326,6 @@ simedtdlg.tab.Plotdata = Plot data simedtdlg.tab.CustomExpressions = Custom expressions simedtdlg.tab.Exportdata = Export data simedtdlg.lbl.Flightcfg = Flight configuration: -simedtdlg.but.FlightcfgEdit = Edit simedtdlg.lbl.ttip.Flightcfg = Select the flight configuration to use. simedtdlg.combo.ttip.Flightcfg = Select the flight configuration to use. simedtdlg.lbl.Wind = Wind @@ -1066,9 +1064,6 @@ TrapezoidFinSetCfg.lbl.plus = plus TrapezoidFinSetCfg.tab.General = General TrapezoidFinSetCfg.tab.Generalproperties = General properties -!MotorConfigurationModel -MotorCfgModel.Editcfg = Edit configurations - ! StorageOptionChooser StorageOptChooser.lbl.Simdatatostore = Simulated data to store: StorageOptChooser.rdbut.Allsimdata = All simulated data diff --git a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java index e37c488db..a0717117c 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java @@ -6,14 +6,11 @@ import java.util.HashMap; import java.util.Map; import javax.swing.ComboBoxModel; -import javax.swing.SwingUtilities; import javax.swing.event.EventListenerList; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import net.sf.openrocket.formatting.RocketDescriptor; -import net.sf.openrocket.gui.dialogs.flightconfiguration.FlightConfigurationDialog; -import net.sf.openrocket.gui.main.BasicFrame; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.Configuration; @@ -28,8 +25,6 @@ import net.sf.openrocket.util.StateChangeListener; public class FlightConfigurationModel implements ComboBoxModel, StateChangeListener { private static final Translator trans = Application.getTranslator(); - private static final String EDIT = trans.get("MotorCfgModel.Editcfg"); - private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); @@ -37,20 +32,13 @@ 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, true); - } - - - public FlightConfigurationModel(Configuration config, boolean showEditElement) { this.config = config; this.rocket = config.getRocket(); - this.showEditElement = showEditElement; config.addChangeListener(this); } @@ -61,23 +49,15 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe if (index < 0) return null; - if ((showEditElement && index > ids.length) || - (!showEditElement && index >= ids.length)) + if ( index >= ids.length) return null; - if (index == ids.length) - return EDIT; - return get(ids[index]); } @Override public int getSize() { - if (showEditElement) { - return rocket.getFlightConfigurationIDs().length + 1; - } else { - return rocket.getFlightConfigurationIDs().length; - } + return rocket.getFlightConfigurationIDs().length; } @Override @@ -91,19 +71,6 @@ public class FlightConfigurationModel implements ComboBoxModel, StateChangeListe // Clear selection - huh? return; } - if (item == EDIT) { - - // Open edit dialog in the future, after combo box has closed - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - new FlightConfigurationDialog(rocket, BasicFrame.findFrame(rocket)) - .setVisible(true); - } - }); - - return; - } if (!(item instanceof ID)) { throw new IllegalArgumentException("MotorConfigurationModel item=" + item); } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java deleted file mode 100644 index 487b0ac66..000000000 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java +++ /dev/null @@ -1,231 +0,0 @@ -package net.sf.openrocket.gui.dialogs.flightconfiguration; - -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTabbedPane; - -import net.miginfocom.swing.MigLayout; -import net.sf.openrocket.document.OpenRocketDocument; -import net.sf.openrocket.document.Simulation; -import net.sf.openrocket.gui.adaptors.FlightConfigurationModel; -import net.sf.openrocket.gui.main.BasicFrame; -import net.sf.openrocket.gui.util.GUIUtil; -import net.sf.openrocket.l10n.Translator; -import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; -import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.startup.Application; - -/** - * Dialog for configuring all flight-configuration specific properties. - * Content of individual tabs are in separate classes. - */ -public class FlightConfigurationDialog extends JDialog { - - private static final Translator trans = Application.getTranslator(); - - private final Rocket rocket; - - private FlightConfigurationModel flightConfigurationModel; - - private final JButton renameConfButton, removeConfButton, copyConfButton; - - private final MotorConfigurationPanel motorConfigurationPanel; - private final RecoveryConfigurationPanel recoveryConfigurationPanel; - private final SeparationConfigurationPanel separationConfigurationPanel; - - - public FlightConfigurationDialog(final Rocket rocket, Window parent) { - //// Edit motor configurations - super(parent, trans.get("edtmotorconfdlg.title.Editmotorconf"), ModalityType.APPLICATION_MODAL); - - if (parent != null) - this.setModalityType(ModalityType.DOCUMENT_MODAL); - else - this.setModalityType(ModalityType.APPLICATION_MODAL); - - this.rocket = rocket; - - JPanel panel = new JPanel(new MigLayout("fill")); - - JLabel label = new JLabel(trans.get("edtmotorconfdlg.lbl.Selectedconf")); - panel.add(label, "span, split"); - - flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration(), false); - JComboBox configSelector = new JComboBox(flightConfigurationModel); - configSelector.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - configurationChanged(); - } - }); - - panel.add(configSelector, "growx, gapright para"); - - JButton newConfButton = new JButton(trans.get("edtmotorconfdlg.but.Newconfiguration")); - newConfButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - addConfiguration(); - } - - }); - - panel.add(newConfButton); - - renameConfButton = new JButton(trans.get("edtmotorconfdlg.but.Renameconfiguration")); - renameConfButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - renameConfiguration(); - } - }); - panel.add(renameConfButton); - - removeConfButton = new JButton(trans.get("edtmotorconfdlg.but.Removeconfiguration")); - removeConfButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - removeConfiguration(); - } - }); - panel.add(removeConfButton); - - copyConfButton = new JButton(trans.get("edtmotorconfdlg.but.Copyconfiguration")); - copyConfButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - copyConfiguration(); - } - }); - panel.add(copyConfButton, "wrap para"); - - - //// Tabs for advanced view. - JTabbedPane tabs = new JTabbedPane(); - panel.add(tabs, "grow, spanx, w 700lp, h 500lp, wrap"); - - //// Motor tabs - motorConfigurationPanel = new MotorConfigurationPanel(this, rocket); - tabs.add(trans.get("edtmotorconfdlg.lbl.Motortab"), motorConfigurationPanel); - //// Recovery tab - recoveryConfigurationPanel = new RecoveryConfigurationPanel(this, rocket); - tabs.add(trans.get("edtmotorconfdlg.lbl.Recoverytab"), recoveryConfigurationPanel); - - //// Stage tab - separationConfigurationPanel = new SeparationConfigurationPanel(this, rocket); - if (rocket.getStageCount() > 1) { - tabs.add(trans.get("edtmotorconfdlg.lbl.Stagetab"), separationConfigurationPanel); - } - - - //// Close button - JButton close = new JButton(trans.get("dlg.but.close")); - close.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - FlightConfigurationDialog.this.dispose(); - } - }); - panel.add(close, "spanx, right"); - - this.add(panel); - this.validate(); - this.pack(); - - updateButtonState(); - - this.setLocationByPlatform(true); - GUIUtil.setDisposableDialogOptions(this, close); - - // Undo description - final OpenRocketDocument document = BasicFrame.findDocument(rocket); - if (document != null) { - //// Edit motor configurations - document.startUndo(trans.get("edtmotorconfdlg.title.Editmotorconf")); - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosed(WindowEvent e) { - document.stopUndo(); - } - }); - } - } - - private void configurationChanged() { - motorConfigurationPanel.fireTableDataChanged(); - recoveryConfigurationPanel.fireTableDataChanged(); - separationConfigurationPanel.fireTableDataChanged(); - updateButtonState(); - } - - private void addConfiguration() { - String newId = rocket.newFlightConfigurationID(); - rocket.getDefaultConfiguration().setFlightConfigurationID(newId); - - // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); - - configurationChanged(); - } - - private void copyConfiguration() { - String currentId = rocket.getDefaultConfiguration().getFlightConfigurationID(); - - // currentID is the currently selected configuration. - String newConfigId = rocket.newFlightConfigurationID(); - String oldName = rocket.getFlightConfigurationName(currentId); - - for (RocketComponent c : rocket) { - if (c instanceof FlightConfigurableComponent) { - ((FlightConfigurableComponent) c).cloneFlightConfiguration(currentId, newConfigId); - } - } - rocket.setFlightConfigurationName(currentId, oldName); - rocket.getDefaultConfiguration().setFlightConfigurationID(newConfigId); - - // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); - - configurationChanged(); - } - - /** - * prereq - assumes that the new configuration has been set as the default configuration. - */ - private void createSimulationForNewConfiguration() { - Simulation newSim = new Simulation(rocket); - OpenRocketDocument doc = BasicFrame.findDocument(rocket); - newSim.setName(doc.getNextSimulationName()); - doc.addSimulation(newSim); - } - - private void renameConfiguration() { - new RenameConfigDialog(this, rocket).setVisible(true); - } - - private void removeConfiguration() { - String currentId = rocket.getDefaultConfiguration().getFlightConfigurationID(); - if (currentId == null) - return; - rocket.removeFlightConfigurationID(currentId); - rocket.getDefaultConfiguration().setFlightConfigurationID(null); - configurationChanged(); - } - - private void updateButtonState() { - String currentId = rocket.getDefaultConfiguration().getFlightConfigurationID(); - removeConfButton.setEnabled(currentId != null); - renameConfButton.setEnabled(currentId != null); - } - -} diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java deleted file mode 100644 index 95692a29b..000000000 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java +++ /dev/null @@ -1,309 +0,0 @@ -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; -import java.awt.event.MouseEvent; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; - -import net.miginfocom.swing.MigLayout; -import net.sf.openrocket.gui.components.DescriptionArea; -import net.sf.openrocket.gui.components.StyledLabel; -import net.sf.openrocket.gui.components.StyledLabel.Style; -import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog; -import net.sf.openrocket.gui.util.GUIUtil; -import net.sf.openrocket.l10n.Translator; -import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.rocketcomponent.MotorConfiguration; -import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.startup.Application; - -public class MotorConfigurationPanel extends JPanel { - - private static final Translator trans = Application.getTranslator(); - - private final FlightConfigurationDialog flightConfigurationDialog; - private final Rocket rocket; - - private final JTable configurationTable; - private final MotorConfigurationTableModel configurationTableModel; - private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton; - - private final MotorChooserDialog dialog; - - MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) { - super(new MigLayout("fill")); - dialog = new MotorChooserDialog(flightConfigurationDialog); - this.flightConfigurationDialog = flightConfigurationDialog; - this.rocket = rocket; - - DescriptionArea desc = new DescriptionArea(trans.get("description"), 3, -1); - this.add(desc, "spanx, growx, wrap para"); - - - //// Motor mount selection - JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD); - this.add(label, ""); - - //// Motor selection - label = new StyledLabel(trans.get("lbl.motorConfiguration"), Style.BOLD); - this.add(label, "wrap rel"); - - - //// Motor Mount selection - { - MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) { - @Override - public void onDataChanged() { - MotorConfigurationPanel.this.fireTableDataChanged(); - - } - }; - this.add(mountConfigPanel, "w 200lp, h 150lp, grow"); - } - - //// Motor selection table. - configurationTableModel = new MotorConfigurationTableModel(rocket); - configurationTable = new JTable(configurationTableModel); - configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - configurationTable.setRowSelectionAllowed(true); - configurationTable.setDefaultRenderer(Object.class, new MotorTableCellRenderer()); - - configurationTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - updateButtonState(); - int selectedColumn = configurationTable.getSelectedColumn(); - if (e.getClickCount() == 2) { - if (selectedColumn == 2) { - // user double clicked in ignition column - selectIgnition(); - } else { - // Double-click edits motor - selectMotor(); - } - } - } - }); - - JScrollPane scroll = new JScrollPane(configurationTable); - this.add(scroll, "w 500lp, h 150lp, grow, wrap"); - - //// Select motor - selectMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectMotor")); - selectMotorButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectMotor(); - } - }); - this.add(selectMotorButton, "skip, split, sizegroup button"); - - //// Remove motor button - removeMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.removeMotor")); - removeMotorButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - removeMotor(); - } - }); - this.add(removeMotorButton, "sizegroup button"); - - //// Select Ignition button - selectIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectIgnition")); - selectIgnitionButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectIgnition(); - } - }); - this.add(selectIgnitionButton, "sizegroup button"); - - //// Reset Ignition button - resetIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.resetIgnition")); - resetIgnitionButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - resetIgnition(); - } - }); - this.add(resetIgnitionButton, "sizegroup button, wrap"); - - } - - public void fireTableDataChanged() { - int selected = configurationTable.getSelectedRow(); - configurationTableModel.fireTableDataChanged(); - if (selected >= 0) { - selected = Math.min(selected, configurationTable.getRowCount() - 1); - configurationTable.getSelectionModel().setSelectionInterval(selected, selected); - } - updateButtonState(); - } - - private void updateButtonState() { - String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getCurrentMount(); - selectMotorButton.setEnabled(currentMount != null && currentID != null); - removeMotorButton.setEnabled(currentMount != null && currentID != null); - selectIgnitionButton.setEnabled(currentMount != null && currentID != null); - resetIgnitionButton.setEnabled(currentMount != null && currentID != null); - } - - - private MotorMount getCurrentMount() { - int row = configurationTable.getSelectedRow(); - if (row < 0) { - return null; - } - - return getMount(row); - } - - - private MotorMount getMount(int row) { - int count = 0; - for (RocketComponent c : rocket) { - if (c instanceof MotorMount) { - MotorMount mount = (MotorMount) c; - if (mount.isMotorMount()) { - count++; - } - if (count > row) { - return mount; - } - } - } - - throw new IndexOutOfBoundsException("Invalid row, row=" + row + " count=" + count); - } - - - - private void selectMotor() { - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount mount = getCurrentMount(); - if (id == null || mount == null) - return; - - MotorConfiguration config = mount.getMotorConfiguration().get(id); - - dialog.setMotorMountAndConfig(mount, id); - dialog.setVisible(true); - Motor m = dialog.getSelectedMotor(); - double d = dialog.getSelectedDelay(); - - if (m != null) { - config = new MotorConfiguration(); - config.setMotor(m); - config.setEjectionDelay(d); - mount.getMotorConfiguration().set(id, config); - } - - fireTableDataChanged(); - } - - private void removeMotor() { - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount mount = getCurrentMount(); - if (id == null || mount == null) - return; - - mount.getMotorConfiguration().resetDefault(id); - - fireTableDataChanged(); - } - - private void selectIgnition() { - String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getCurrentMount(); - if (currentID == null || currentMount == null) - return; - - IgnitionSelectionDialog dialog = new IgnitionSelectionDialog( - this.flightConfigurationDialog, - rocket, - currentMount); - dialog.setVisible(true); - - fireTableDataChanged(); - } - - - private void resetIgnition() { - String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getCurrentMount(); - if (currentID == null || currentMount == null) - return; - - currentMount.getIgnitionConfiguration().resetDefault(currentID); - - fireTableDataChanged(); - } - - - private class MotorTableCellRenderer 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; - - MotorMount mount = getMount(row); - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - - switch (column) { - case 0: - regular(label); - break; - - case 1: - if (mount.getMotorConfiguration().get(id).getMotor() != null) { - regular(label); - } else { - shaded(label); - } - break; - - case 2: - if (mount.getIgnitionConfiguration().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/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java deleted file mode 100644 index ce900e72f..000000000 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java +++ /dev/null @@ -1,146 +0,0 @@ -package net.sf.openrocket.gui.dialogs.flightconfiguration; - -import javax.swing.table.AbstractTableModel; - -import net.sf.openrocket.l10n.Translator; -import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.rocketcomponent.IgnitionConfiguration; -import net.sf.openrocket.rocketcomponent.MotorConfiguration; -import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.startup.Application; -import net.sf.openrocket.unit.UnitGroup; -import net.sf.openrocket.util.Chars; -import net.sf.openrocket.util.Coordinate; - -/** - * The table model for selecting and editing the motor configurations. - */ -class MotorConfigurationTableModel extends AbstractTableModel { - - private static final Translator trans = Application.getTranslator(); - - private static final String NONE = trans.get("edtmotorconfdlg.tbl.None"); - private static final String MOTOR_MOUNT = trans.get("edtmotorconfdlg.tbl.Mountheader"); - private static final String MOTOR = trans.get("edtmotorconfdlg.tbl.Motorheader"); - private static final String IGNITION = trans.get("edtmotorconfdlg.tbl.Ignitionheader"); - - private final Rocket rocket; - - - public MotorConfigurationTableModel(Rocket rocket) { - this.rocket = rocket; - } - - @Override - public int getColumnCount() { - return 3; - } - - @Override - public int getRowCount() { - int count = 0; - for (RocketComponent c : rocket) { - if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) { - count++; - } - } - return count; - } - - @Override - public Object getValueAt(int row, int column) { - switch (column) { - case 0: { - MotorMount mount = findMount(row); - String name = mount.toString(); - int count = getMountMultiplicity(mount); - if (count > 1) { - name = name + " (" + Chars.TIMES + count + ")"; - } - return name; - } - case 1: { - MotorMount mount = findMount(row); - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorConfiguration config = mount.getMotorConfiguration().get(id); - Motor motor = config.getMotor(); - - if (motor == null) - return NONE; - - String str = motor.getDesignation(config.getEjectionDelay()); - int count = getMountMultiplicity(mount); - if (count > 1) { - str = "" + count + Chars.TIMES + " " + str; - } - return str; - } - case 2: { - return getIgnitionEventString(row); - - } - default: - throw new IndexOutOfBoundsException("column=" + column); - } - } - - - - @Override - public String getColumnName(int column) { - switch (column) { - case 0: - return MOTOR_MOUNT; - case 1: - return MOTOR; - case 2: - return IGNITION; - default: - throw new IndexOutOfBoundsException("column=" + column); - } - } - - - private MotorMount findMount(int row) { - int count = row; - for (RocketComponent c : rocket) { - if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) { - count--; - if (count < 0) { - return (MotorMount) c; - } - } - } - throw new IndexOutOfBoundsException("Requesting row=" + row + " but only " + getRowCount() + " rows exist"); - } - - - private int getMountMultiplicity(MotorMount mount) { - RocketComponent c = (RocketComponent) mount; - return c.toAbsolute(Coordinate.NUL).length; - } - - - - private String getIgnitionEventString(int row) { - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount mount = findMount(row); - IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(id); - - IgnitionConfiguration.IgnitionEvent ignitionEvent = ignitionConfig.getIgnitionEvent(); - Double ignitionDelay = ignitionConfig.getIgnitionDelay(); - boolean isDefault = mount.getIgnitionConfiguration().isDefault(id); - - String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name()); - if (ignitionDelay > 0.001) { - str = str + " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(ignitionDelay); - } - if (isDefault) { - String def = trans.get("table.ignition.default"); - str = def.replace("{0}", str); - } - return str; - } -} \ No newline at end of file diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java deleted file mode 100644 index 42b974c1c..000000000 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/RecoveryConfigurationPanel.java +++ /dev/null @@ -1,264 +0,0 @@ -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; -import java.awt.event.MouseEvent; -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; -import net.sf.openrocket.rocketcomponent.RecoveryDevice; -import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.startup.Application; -import net.sf.openrocket.unit.UnitGroup; - -public class RecoveryConfigurationPanel extends JPanel { - - private Translator trans = Application.getTranslator(); - - - private final FlightConfigurationDialog flightConfigurationDialog; - private final Rocket rocket; - - private final RecoveryTableModel recoveryTableModel; - private final JTable recoveryTable; - private final JButton selectDeploymentButton; - private final JButton resetDeploymentButton; - - - RecoveryConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) { - super(new MigLayout("fill")); - this.flightConfigurationDialog = flightConfigurationDialog; - this.rocket = rocket; - - //// Recovery selection - recoveryTableModel = new RecoveryTableModel(); - recoveryTable = new JTable(recoveryTableModel); - recoveryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - recoveryTable.setRowSelectionAllowed(true); - recoveryTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - updateButtonState(); - - if (e.getClickCount() == 2) { - // Double-click edits - selectDeployment(); - } - } - }); - recoveryTable.setDefaultRenderer(Object.class, new RecoveryTableCellRenderer()); - - JScrollPane scroll = new JScrollPane(recoveryTable); - this.add(scroll, "span, grow, wrap"); - - //// Select deployment - selectDeploymentButton = new JButton(trans.get("edtmotorconfdlg.but.Selectdeployment")); - selectDeploymentButton.setEnabled(false); - selectDeploymentButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectDeployment(); - } - }); - this.add(selectDeploymentButton, "skip, split, sizegroup button"); - - //// Reset deployment - resetDeploymentButton = new JButton(trans.get("edtmotorconfdlg.but.Resetdeployment")); - resetDeploymentButton.setEnabled(false); - resetDeploymentButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - resetDeployment(); - } - }); - this.add(resetDeploymentButton, "sizegroup button, wrap"); - } - - 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(); - } - - private void selectDeployment() { - RecoveryDevice c = getSelectedComponent(); - if (c == null) { - return; - } - JDialog d = new DeploymentSelectionDialog(flightConfigurationDialog, rocket, c); - d.setVisible(true); - fireTableDataChanged(); - } - - private void resetDeployment() { - RecoveryDevice c = getSelectedComponent(); - if (c == null) { - return; - } - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - c.getDeploymentConfiguration().resetDefault(id); - fireTableDataChanged(); - } - - public void updateButtonState() { - boolean componentSelected = getSelectedComponent() != null; - selectDeploymentButton.setEnabled(componentSelected); - resetDeploymentButton.setEnabled(componentSelected); - } - - - private RecoveryDevice getSelectedComponent() { - int row = recoveryTable.getSelectedRow(); - return findRecoveryDevice(row); - } - - private RecoveryDevice findRecoveryDevice(int count) { - RecoveryDevice d = null; - Iterator it = rocket.iterator(); - while (it.hasNext() && count >= 0) { - RocketComponent c = it.next(); - if (c instanceof RecoveryDevice) { - d = (RecoveryDevice) c; - count--; - } - } - return d; - } - - - - private class RecoveryTableModel extends AbstractTableModel { - - @Override - public int getRowCount() { - int count = 0; - Iterator it = rocket.iterator(); - while (it.hasNext()) { - RocketComponent c = it.next(); - if (c instanceof RecoveryDevice) { - count++; - } - } - return count; - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - RecoveryDevice d = findRecoveryDevice(rowIndex); - switch (columnIndex) { - case 0: - return d.getName(); - case 1: - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - DeploymentConfiguration config = d.getDeploymentConfiguration().get(id); - boolean isDefault = d.getDeploymentConfiguration().isDefault(id); - - String str; - - str = trans.get("RecoveryDevice.DeployEvent.short." + config.getDeployEvent().name()); - if (config.getDeployEvent() == DeployEvent.ALTITUDE) { - str += " " + UnitGroup.UNITS_DISTANCE.toStringUnit(config.getDeployAltitude()); - } - if (config.getDeployDelay() > 0.001) { - str += " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(config.getDeployDelay()); - } - - - if (isDefault) { - String def = trans.get("table.deployment.default"); - str = def.replace("{0}", str); - } - return str; - - default: - throw new IndexOutOfBoundsException("columnIndex=" + columnIndex); - } - - } - - @Override - public String getColumnName(int column) { - switch (column) { - case 0: - return trans.get("edtmotorconfdlg.tbl.Recoveryheader"); - case 1: - return trans.get("edtmotorconfdlg.tbl.Deploymentheader"); - default: - return ""; - } - } - - } - - - 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/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java deleted file mode 100644 index 8094a35d0..000000000 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationConfigurationPanel.java +++ /dev/null @@ -1,259 +0,0 @@ -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; -import java.awt.event.MouseEvent; -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; -import net.sf.openrocket.rocketcomponent.Stage; -import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; -import net.sf.openrocket.startup.Application; -import net.sf.openrocket.unit.UnitGroup; - -public class SeparationConfigurationPanel extends JPanel { - - private static final Translator trans = Application.getTranslator(); - - private final FlightConfigurationDialog flightConfigurationDialog; - private final Rocket rocket; - private final Stage[] stages; - - private final JTable separationTable; - private final SeparationTableModel separationTableModel; - private final JButton selectSeparationButton; - private final JButton resetDeploymentButton; - - - SeparationConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) { - super(new MigLayout("fill")); - this.flightConfigurationDialog = flightConfigurationDialog; - this.rocket = rocket; - - - int stageCount = rocket.getStageCount() - 1; - stages = new Stage[stageCount]; - Iterator it = rocket.iterator(); - { - int stageIndex = -1; - while (it.hasNext()) { - RocketComponent c = it.next(); - if (c instanceof Stage) { - if (stageIndex >= 0) { - stages[stageIndex] = (Stage) c; - } - stageIndex++; - } - } - } - - //// Recovery selection - separationTableModel = new SeparationTableModel(); - separationTable = new JTable(separationTableModel); - separationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - separationTable.setRowSelectionAllowed(true); - separationTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - updateButtonState(); - if (e.getClickCount() == 2) { - // Double-click edits - selectDeployment(); - } - } - }); - separationTable.setDefaultRenderer(Object.class, new SeparationTableCellRenderer()); - - JScrollPane scroll = new JScrollPane(separationTable); - this.add(scroll, "span, grow, wrap"); - - //// Select deployment - selectSeparationButton = new JButton(trans.get("edtmotorconfdlg.but.Selectseparation")); - selectSeparationButton.setEnabled(false); - selectSeparationButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectDeployment(); - } - }); - this.add(selectSeparationButton, "skip, split, sizegroup button"); - - //// Reset deployment - resetDeploymentButton = new JButton(trans.get("edtmotorconfdlg.but.Resetseparation")); - resetDeploymentButton.setEnabled(false); - resetDeploymentButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - resetDeployment(); - } - }); - this.add(resetDeploymentButton, "sizegroup button, wrap"); - - } - - 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]; - } - return null; - } - - private void selectDeployment() { - Stage stage = getSelectedStage(); - if (stage == null) { - return; - } - JDialog d = new SeparationSelectionDialog(flightConfigurationDialog, rocket, stage); - d.setVisible(true); - fireTableDataChanged(); - } - - private void resetDeployment() { - Stage stage = getSelectedStage(); - if (stage == null) { - return; - } - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - stage.getStageSeparationConfiguration().resetDefault(id); - fireTableDataChanged(); - } - - public void updateButtonState() { - boolean componentSelected = getSelectedStage() != null; - selectSeparationButton.setEnabled(componentSelected); - resetDeploymentButton.setEnabled(componentSelected); - } - - private class SeparationTableModel extends AbstractTableModel { - - @Override - public int getRowCount() { - return stages.length; - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - Stage d = SeparationConfigurationPanel.this.stages[rowIndex]; - switch (columnIndex) { - case 0: - return d.getName(); - case 1: - String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - StageSeparationConfiguration config = d.getStageSeparationConfiguration().get(id); - - String str; - - str = config.getSeparationEvent().toString(); - if (config.getSeparationDelay() > 0.001) { - str += " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(config.getSeparationDelay()); - } - - if (d.getStageSeparationConfiguration().isDefault(id)) { - String def = trans.get("SeparationConfigurationPanel.table.separation.default"); - str = def.replace("{0}", str); - } - - return str; - - default: - throw new IndexOutOfBoundsException("column=" + columnIndex); - } - - } - - @Override - public String getColumnName(int column) { - switch (column) { - case 0: - return trans.get("edtmotorconfdlg.tbl.Stageheader"); - case 1: - return trans.get("edtmotorconfdlg.tbl.Separationheader"); - default: - 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/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 5ae1d1581..c458b8e66 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -6,7 +6,6 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Point; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -22,9 +21,7 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; import javax.swing.JComboBox; -import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; @@ -48,7 +45,6 @@ import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.configdialog.ComponentConfigDialog; -import net.sf.openrocket.gui.dialogs.flightconfiguration.FlightConfigurationDialog; import net.sf.openrocket.gui.figure3d.RocketFigure3d; import net.sf.openrocket.gui.figureelements.CGCaret; import net.sf.openrocket.gui.figureelements.CPCaret; @@ -323,20 +319,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg")); label.setHorizontalAlignment(JLabel.RIGHT); add(label, "growx, right"); - add(new JComboBox(new FlightConfigurationModel(configuration)), ""); - - //// Edit button - JButton button = new JButton(trans.get("RocketPanel.but.FlightcfgEdit")); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JDialog configDialog = new FlightConfigurationDialog(document.getRocket(), SwingUtilities.windowForComponent(RocketPanel.this)); - configDialog.show(); - } - }); - add(button, "wrap"); - - + add(new JComboBox(new FlightConfigurationModel(configuration)), "wrap"); // Create slider and scroll pane diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index ae0784c30..53468bb61 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -13,7 +13,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; -import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@ -23,7 +22,6 @@ import net.miginfocom.swing.MigLayout; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.Simulation; import net.sf.openrocket.gui.adaptors.FlightConfigurationModel; -import net.sf.openrocket.gui.dialogs.flightconfiguration.FlightConfigurationDialog; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.Configuration; @@ -158,18 +156,7 @@ public class SimulationEditDialog extends JDialog { conditions.setMotorConfigurationID(configuration.getFlightConfigurationID()); } }); - panel.add(combo, "span, split"); - - //// Edit button - JButton button = new JButton(trans.get("simedtdlg.but.FlightcfgEdit")); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JDialog configDialog = new FlightConfigurationDialog(SimulationEditDialog.this.document.getRocket(), SwingUtilities.windowForComponent(SimulationEditDialog.this)); - configDialog.setVisible(true); - } - }); - panel.add(button, "align left"); + panel.add(combo, "span"); panel.add(new JPanel(), "growx, wrap");