diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index 54071c1f1..a0a0f4fc4 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -84,7 +84,7 @@ public abstract class FlightConfigurablePanel 1) ? 1 : 0; + int col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0; for (int row = 0; row < table.getRowCount(); row++) { FlightConfigurationId rowFCID = rocket.getId(row); if (rowFCID.equals(current)) { @@ -107,7 +107,7 @@ public abstract class FlightConfigurablePanel 1) ? 1 : 0; + col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0; } for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) { diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java index 6956ab0b4..5ef22b8e2 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -8,6 +8,8 @@ import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.document.OpenRocketDocument; @@ -74,13 +76,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe newConfButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - - addOrCopyConfiguration(false); - int lastRow = motorConfigurationPanel.table.getRowCount() - 1; - int lastCol = motorConfigurationPanel.table.getColumnCount() - 1; - motorConfigurationPanel.table.setRowSelectionInterval(lastRow, lastRow); - motorConfigurationPanel.table.setColumnSelectionInterval(lastCol, lastCol); - configurationChanged(ComponentChangeEvent.MOTOR_CHANGE); + newOrCopyConfigAction(false); } }); @@ -111,17 +107,56 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe copyConfButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - addOrCopyConfiguration(true); - configurationChanged(ComponentChangeEvent.MOTOR_CHANGE); + newOrCopyConfigAction(true); } }); this.add(copyConfButton, "wrap"); + tabs.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + // Trigger a selection of the motor/recovery/configuration item + switch (tabs.getSelectedIndex()) { + case MOTOR_TAB_INDEX: + motorConfigurationPanel.updateButtonState(); + break; + case RECOVERY_TAB_INDEX: + recoveryConfigurationPanel.updateButtonState(); + break; + case SEPARATION_TAB_INDEX: + separationConfigurationPanel.updateButtonState(); + break; + } + } + }); + updateButtonState(); this.add(tabs, "spanx, grow, wrap rel"); } + /** + * Action for when the new configuration or copy configuration button is pressed. + * @param copy if True, then copy configuration operation, if False then create a new configuration + */ + private void newOrCopyConfigAction(boolean copy) { + addOrCopyConfiguration(copy); + configurationChanged(ComponentChangeEvent.MOTOR_CHANGE); + stateChanged(null); + switch (tabs.getSelectedIndex()) { + case MOTOR_TAB_INDEX: + motorConfigurationPanel.selectMotor(); + break; + case RECOVERY_TAB_INDEX: + recoveryConfigurationPanel.selectDeployment(); + break; + case SEPARATION_TAB_INDEX: + separationConfigurationPanel.selectSeparation(); + break; + } + configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); // Trigger select + } + /** * either create or copy configuration * set new configuration as current 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 1a86911db..b72b58ff5 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -4,16 +4,20 @@ import java.awt.CardLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.AbstractAction; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.event.TableModelEvent; @@ -29,15 +33,12 @@ import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.motor.IgnitionEvent; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; -import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.Chars; @@ -56,7 +57,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel protected FlightConfigurableTableModel configurationTableModel; MotorConfigurationPanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) { - super(flightConfigurationPanel,rocket); + super(flightConfigurationPanel, rocket); motorChooserDialog = new MotorChooserDialog(SwingUtilities.getWindowAncestor(flightConfigurationPanel)); @@ -66,20 +67,20 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD); subpanel.add(label, "wrap"); - MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket); + MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this, rocket); subpanel.add(mountConfigPanel, "grow"); this.add(subpanel, "split, w 200lp, growy"); } cards = new JPanel(new CardLayout()); - this.add( cards ); - + this.add(cards); + JLabel helpText = new JLabel(trans.get("MotorConfigurationPanel.lbl.nomotors")); - cards.add(helpText, HELP_LABEL ); - + cards.add(helpText, HELP_LABEL); + JScrollPane scroll = new JScrollPane(table); - cards.add(scroll, TABLE_LABEL ); - + cards.add(scroll, TABLE_LABEL); + this.add(cards, "grow, wrap"); //// Select motor @@ -122,6 +123,16 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel }); this.add(resetIgnitionButton, "sizegroup button, wrap"); + // Set 'Enter' key action to open the motor selection dialog + table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); + table.getActionMap().put("Enter", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent ae) { + selectMotor(); + } + }); + updateButtonState(); } @@ -204,7 +215,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel } } - private void selectMotor() { + public void selectMotor() { MotorMount curMount = getSelectedComponent(); FlightConfigurationId fcid= getSelectedConfigurationId(); if ( (null == fcid )||( null == curMount )){ diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index 9fd246ec2..5cf62c634 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -2,14 +2,18 @@ package net.sf.openrocket.gui.main.flightconfigpanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.AbstractAction; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -59,6 +63,16 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel