Merge pull request #1182 from SiboVG/issue-1181
[fixes #1181] Fix initial motor select in MotorChooserDialog
This commit is contained in:
commit
788b9ab12e
@ -6,6 +6,8 @@ import java.awt.Window;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.Action;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@ -73,7 +75,13 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
this.setModal(true);
|
this.setModal(true);
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setLocationByPlatform(true);
|
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();
|
JComponent focus = selectionPanel.getDefaultFocus();
|
||||||
if (focus != null) {
|
if (focus != null) {
|
||||||
@ -108,7 +116,11 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
return selectionPanel.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
|
@Override
|
||||||
public void close(boolean ok) {
|
public void close(boolean ok) {
|
||||||
|
@ -113,13 +113,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sole constructor.
|
|
||||||
*
|
|
||||||
* @param current the currently selected ThrustCurveMotor, or <code>null</code> for none.
|
|
||||||
* @param delay the currently selected ejection charge delay.
|
|
||||||
* @param diameter the diameter of the motor mount.
|
|
||||||
*/
|
|
||||||
public ThrustCurveMotorSelectionPanel() {
|
public ThrustCurveMotorSelectionPanel() {
|
||||||
super(new MigLayout("fill", "[grow][]"));
|
super(new MigLayout("fill", "[grow][]"));
|
||||||
|
|
||||||
@ -264,17 +257,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
int row = table.getSelectedRow();
|
selectMotorFromTable();
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
table.addMouseListener(new MouseAdapter() {
|
table.addMouseListener(new MouseAdapter() {
|
||||||
@ -608,6 +591,23 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
return list.get(0);
|
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 <code>reset</code> is <code>true</code>
|
* Set the values in the delay combo box. If <code>reset</code> is <code>true</code>
|
||||||
|
@ -288,7 +288,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
double initDelay = initMount.getMotorConfig(initFcId).getEjectionDelay();
|
double initDelay = initMount.getMotorConfig(initFcId).getEjectionDelay();
|
||||||
|
|
||||||
motorChooserDialog.setMotorMountAndConfig(initFcId, initMount);
|
motorChooserDialog.setMotorMountAndConfig(initFcId, initMount);
|
||||||
motorChooserDialog.setVisible(true);
|
motorChooserDialog.open();
|
||||||
|
|
||||||
Motor mtr = motorChooserDialog.getSelectedMotor();
|
Motor mtr = motorChooserDialog.getSelectedMotor();
|
||||||
double d = motorChooserDialog.getSelectedDelay();
|
double d = motorChooserDialog.getSelectedDelay();
|
||||||
|
@ -157,6 +157,19 @@ public class GUIUtil {
|
|||||||
* @param dialog the dialog for which to install the action.
|
* @param dialog the dialog for which to install the action.
|
||||||
*/
|
*/
|
||||||
public static void installEscapeCloseOperation(final JDialog dialog) {
|
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() {
|
Action dispatchClosing = new AbstractAction() {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -172,6 +185,9 @@ public class GUIUtil {
|
|||||||
JRootPane root = dialog.getRootPane();
|
JRootPane root = dialog.getRootPane();
|
||||||
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE, CLOSE_ACTION_KEY);
|
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE, CLOSE_ACTION_KEY);
|
||||||
root.getActionMap().put(CLOSE_ACTION_KEY, dispatchClosing);
|
root.getActionMap().put(CLOSE_ACTION_KEY, dispatchClosing);
|
||||||
|
if (action != null) {
|
||||||
|
root.getActionMap().put(CLOSE_ACTION_KEY, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user