Merge pull request #180 from kruland2607/master
Fix various bugs in flight configurations
This commit is contained in:
commit
f5d09233e8
@ -10,6 +10,7 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel;
|
import net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel;
|
||||||
@ -34,6 +35,8 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
public MotorChooserDialog(Window owner) {
|
public MotorChooserDialog(Window owner) {
|
||||||
super(owner, trans.get("MotorChooserDialog.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(owner, trans.get("MotorChooserDialog.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
// We're going to reuse this dialog so only hide it when it's closed.
|
||||||
|
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
|
||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
@ -67,7 +70,7 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
this.setModal(true);
|
this.setModal(true);
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setLocationByPlatform(true);
|
this.setLocationByPlatform(true);
|
||||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
GUIUtil.installEscapeCloseOperation(this);
|
||||||
|
|
||||||
JComponent focus = selectionPanel.getDefaultFocus();
|
JComponent focus = selectionPanel.getDefaultFocus();
|
||||||
if (focus != null) {
|
if (focus != null) {
|
||||||
|
@ -304,25 +304,25 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
this.add(rightSide);
|
this.add(rightSide);
|
||||||
|
|
||||||
// Update the panel data
|
// Update the panel data
|
||||||
scrollSelectionVisible();
|
|
||||||
updateData();
|
updateData();
|
||||||
setDelays(false);
|
setDelays(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) {
|
public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) {
|
||||||
|
ThrustCurveMotor motorToSelect = null;
|
||||||
if (currentConfig != null && mount != null) {
|
if (currentConfig != null && mount != null) {
|
||||||
MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig);
|
MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig);
|
||||||
selectedMotor = (ThrustCurveMotor) motorConf.getMotor();
|
motorToSelect = (ThrustCurveMotor) motorConf.getMotor();
|
||||||
selectedDelay = motorConf.getEjectionDelay();
|
selectedDelay = motorConf.getEjectionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedMotorSet = null;
|
selectedMotorSet = null;
|
||||||
|
|
||||||
// If current motor is not found in db, add a new ThrustCurveMotorSet containing it
|
// If current motor is not found in db, add a new ThrustCurveMotorSet containing it
|
||||||
if (selectedMotor != null) {
|
if (motorToSelect != null) {
|
||||||
for (ThrustCurveMotorSet motorSet : database) {
|
for (ThrustCurveMotorSet motorSet : database) {
|
||||||
if (motorSet.getMotors().contains(selectedMotor)) {
|
if (motorSet.getMotors().contains(motorToSelect)) {
|
||||||
selectedMotorSet = motorSet;
|
selectedMotorSet = motorSet;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -330,15 +330,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
if (selectedMotorSet == null) {
|
if (selectedMotorSet == null) {
|
||||||
database = new ArrayList<ThrustCurveMotorSet>(database);
|
database = new ArrayList<ThrustCurveMotorSet>(database);
|
||||||
ThrustCurveMotorSet extra = new ThrustCurveMotorSet();
|
ThrustCurveMotorSet extra = new ThrustCurveMotorSet();
|
||||||
extra.addMotor(selectedMotor);
|
extra.addMotor(motorToSelect);
|
||||||
selectedMotorSet = extra;
|
selectedMotorSet = extra;
|
||||||
database.add(extra);
|
database.add(extra);
|
||||||
Collections.sort(database);
|
Collections.sort(database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateData();
|
select(motorToSelect);
|
||||||
setDelays(true);
|
|
||||||
|
|
||||||
motorFilterPanel.setMotorMount(mount);
|
motorFilterPanel.setMotorMount(mount);
|
||||||
scrollSelectionVisible();
|
scrollSelectionVisible();
|
||||||
@ -394,7 +393,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
* Called when a different motor is selected from within the panel.
|
* Called when a different motor is selected from within the panel.
|
||||||
*/
|
*/
|
||||||
private void select(ThrustCurveMotor motor) {
|
private void select(ThrustCurveMotor motor) {
|
||||||
if (selectedMotor == motor)
|
if (selectedMotor == motor || motor == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ThrustCurveMotorSet set = findMotorSet(motor);
|
ThrustCurveMotorSet set = findMotorSet(motor);
|
||||||
@ -410,6 +409,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
if (updateDelays) {
|
if (updateDelays) {
|
||||||
setDelays(true);
|
setDelays(true);
|
||||||
}
|
}
|
||||||
|
scrollSelectionVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,12 +5,17 @@ import java.awt.Component;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.border.Border;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
@ -47,6 +52,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
synchronizeConfigurationSelection();
|
synchronizeConfigurationSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fireTableDataChanged() {
|
||||||
|
int selectedRow = table.getSelectedRow();
|
||||||
|
int selectedColumn = table.getSelectedColumn();
|
||||||
|
((AbstractTableModel)table.getModel()).fireTableDataChanged();
|
||||||
|
restoreSelection(selectedRow,selectedColumn);
|
||||||
|
updateButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void updateButtonState();
|
||||||
|
|
||||||
protected final void synchronizeConfigurationSelection() {
|
protected final void synchronizeConfigurationSelection() {
|
||||||
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
|
|
||||||
@ -67,11 +82,24 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
String rowId = rocket.getFlightConfigurationIDs()[row + 1];
|
String rowId = rocket.getFlightConfigurationIDs()[row + 1];
|
||||||
if ( rowId.equals(id) ) {
|
if ( rowId.equals(id) ) {
|
||||||
table.changeSelection(row, col, true, false);
|
table.changeSelection(row, col, true, false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void restoreSelection( int row, int col ) {
|
||||||
|
if ( row <= 0 || col <= 0 ) {
|
||||||
|
synchronizeConfigurationSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( row >= table.getRowCount() || col >= table.getColumnCount() ) {
|
||||||
|
synchronizeConfigurationSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
table.changeSelection(row, col, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
private final void installTableListener() {
|
private final void installTableListener() {
|
||||||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||||
|
|
||||||
@ -143,18 +171,41 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
switch (column) {
|
switch (column) {
|
||||||
case 0: {
|
case 0: {
|
||||||
label.setText(descriptor.format(rocket, (String) value));
|
label.setText(descriptor.format(rocket, (String) value));
|
||||||
|
regular(label);
|
||||||
|
setSelected(label, table, isSelected, hasFocus);
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
Pair<String, T> v = (Pair<String, T>) value;
|
Pair<String, T> v = (Pair<String, T>) value;
|
||||||
String id = v.getU();
|
String id = v.getU();
|
||||||
T component = v.getV();
|
T component = v.getV();
|
||||||
format(component, id, label );
|
label = format(component, id, label );
|
||||||
|
setSelected(label, table, isSelected, hasFocus);
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final void setSelected( JComponent c, JTable table, boolean isSelected, boolean hasFocus ) {
|
||||||
|
c.setOpaque(true);
|
||||||
|
if ( isSelected) {
|
||||||
|
c.setBackground(table.getSelectionBackground());
|
||||||
|
} else {
|
||||||
|
c.setBackground(table.getBackground());
|
||||||
|
}
|
||||||
|
Border b = null;
|
||||||
|
if ( hasFocus ) {
|
||||||
|
if (isSelected) {
|
||||||
|
b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
|
||||||
|
} else {
|
||||||
|
b = UIManager.getBorder("Table.focusCellHighligtBorder");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b = new EmptyBorder(1,1,1,1);
|
||||||
|
}
|
||||||
|
c.setBorder(b);
|
||||||
|
}
|
||||||
|
|
||||||
protected final void shaded(JLabel label) {
|
protected final void shaded(JLabel label) {
|
||||||
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
||||||
label.setForeground(Color.GRAY);
|
label.setForeground(Color.GRAY);
|
||||||
@ -165,7 +216,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
label.setForeground(Color.BLACK);
|
label.setForeground(Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void format( T component, String configId, JLabel label );
|
protected abstract JLabel format( T component, String configId, JLabel label );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,17 +187,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
return configurationTable;
|
return configurationTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fireTableDataChanged() {
|
protected void updateButtonState() {
|
||||||
int selected = table.getSelectedRow();
|
|
||||||
configurationTableModel.fireTableDataChanged();
|
|
||||||
if (selected >= 0) {
|
|
||||||
selected = Math.min(selected, table.getRowCount() - 1);
|
|
||||||
table.getSelectionModel().setSelectionInterval(selected, selected);
|
|
||||||
}
|
|
||||||
updateButtonState();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateButtonState() {
|
|
||||||
if( configurationTableModel.getColumnCount() > 1 ) {
|
if( configurationTableModel.getColumnCount() > 1 ) {
|
||||||
showContent();
|
showContent();
|
||||||
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
@ -280,52 +270,10 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class MotorTableCellRenderer implements TableCellRenderer {
|
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
private void setSelected( JComponent c, JTable table, boolean isSelected, boolean hasFocus ) {
|
|
||||||
c.setOpaque(true);
|
|
||||||
if ( isSelected) {
|
|
||||||
c.setBackground(table.getSelectionBackground());
|
|
||||||
c.setForeground(table.getSelectionForeground());
|
|
||||||
} else {
|
|
||||||
c.setBackground(table.getBackground());
|
|
||||||
c.setForeground(table.getForeground());
|
|
||||||
}
|
|
||||||
Border b = null;
|
|
||||||
if ( hasFocus ) {
|
|
||||||
if (isSelected) {
|
|
||||||
b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
|
|
||||||
} else {
|
|
||||||
b = UIManager.getBorder("Table.focusCellHighligtBorder");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
b = new EmptyBorder(1,1,1,1);
|
|
||||||
}
|
|
||||||
c.setBorder(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected, boolean hasFocus, int row,int column) {
|
protected JLabel format( MotorMount mount, String configId, JLabel l ) {
|
||||||
column = table.convertColumnIndexToModel(column);
|
|
||||||
row = table.convertRowIndexToModel(row);
|
|
||||||
switch (column) {
|
|
||||||
case 0: {
|
|
||||||
JLabel label = new JLabel(descriptor.format(rocket, (String) value));
|
|
||||||
setSelected(label, table, isSelected, hasFocus);
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
Pair<String, MotorMount> v = (Pair<String, MotorMount>) value;
|
|
||||||
String id = v.getU();
|
|
||||||
MotorMount component = v.getV();
|
|
||||||
JLabel label = format(component, id);
|
|
||||||
setSelected(label, table, isSelected, hasFocus);
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JLabel format(MotorMount mount, String configId) {
|
|
||||||
JLabel label = new JLabel();
|
JLabel label = new JLabel();
|
||||||
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
|
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
|
||||||
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
|
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
|
||||||
@ -337,7 +285,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
label.add(ignitionLabel);
|
label.add(ignitionLabel);
|
||||||
label.validate();
|
label.validate();
|
||||||
return label;
|
return label;
|
||||||
// label.setText(motorString + " " + ignitionString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
||||||
@ -359,12 +306,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
return c.toAbsolute(Coordinate.NUL).length;
|
return c.toAbsolute(Coordinate.NUL).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void shaded(JLabel label) {
|
|
||||||
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
|
||||||
label.setForeground(Color.GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private JLabel getIgnitionEventString(String id, MotorMount mount) {
|
private JLabel getIgnitionEventString(String id, MotorMount mount) {
|
||||||
IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(id);
|
IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(id);
|
||||||
IgnitionConfiguration.IgnitionEvent ignitionEvent = ignitionConfig.getIgnitionEvent();
|
IgnitionConfiguration.IgnitionEvent ignitionEvent = ignitionConfig.getIgnitionEvent();
|
||||||
|
@ -86,16 +86,6 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
return recoveryTable;
|
return recoveryTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fireTableDataChanged() {
|
|
||||||
int selected = table.getSelectedRow();
|
|
||||||
recoveryTableModel.fireTableDataChanged();
|
|
||||||
if (selected >= 0) {
|
|
||||||
selected = Math.min(selected, table.getRowCount() - 1);
|
|
||||||
table.getSelectionModel().setSelectionInterval(selected, selected);
|
|
||||||
}
|
|
||||||
updateButtonState();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectDeployment() {
|
private void selectDeployment() {
|
||||||
RecoveryDevice c = getSelectedComponent();
|
RecoveryDevice c = getSelectedComponent();
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
@ -125,7 +115,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
class RecoveryTableCellRenderer extends FlightConfigurablePanel<RecoveryDevice>.FlightConfigurableCellRenderer {
|
class RecoveryTableCellRenderer extends FlightConfigurablePanel<RecoveryDevice>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void format(RecoveryDevice recovery, String configId, JLabel label) {
|
protected JLabel format(RecoveryDevice recovery, String configId, JLabel label) {
|
||||||
DeploymentConfiguration deployConfig = recovery.getDeploymentConfiguration().get(configId);
|
DeploymentConfiguration deployConfig = recovery.getDeploymentConfiguration().get(configId);
|
||||||
String spec = getDeploymentSpecification(deployConfig);
|
String spec = getDeploymentSpecification(deployConfig);
|
||||||
label.setText(spec);
|
label.setText(spec);
|
||||||
@ -134,6 +124,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
} else {
|
} else {
|
||||||
regular(label);
|
regular(label);
|
||||||
}
|
}
|
||||||
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDeploymentSpecification( DeploymentConfiguration config ) {
|
private String getDeploymentSpecification( DeploymentConfiguration config ) {
|
||||||
|
@ -91,17 +91,6 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
|
|||||||
return separationTable;
|
return separationTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fireTableDataChanged() {
|
|
||||||
int selected = table.getSelectedRow();
|
|
||||||
separationTableModel.fireTableDataChanged();
|
|
||||||
if (selected >= 0) {
|
|
||||||
selected = Math.min(selected, table.getRowCount() - 1);
|
|
||||||
table.getSelectionModel().setSelectionInterval(selected, selected);
|
|
||||||
}
|
|
||||||
updateButtonState();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void selectDeployment() {
|
private void selectDeployment() {
|
||||||
Stage stage = getSelectedComponent();
|
Stage stage = getSelectedComponent();
|
||||||
if (stage == null) {
|
if (stage == null) {
|
||||||
@ -130,7 +119,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
|
|||||||
private class SeparationTableCellRenderer extends FlightConfigurablePanel<Stage>.FlightConfigurableCellRenderer {
|
private class SeparationTableCellRenderer extends FlightConfigurablePanel<Stage>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void format(Stage stage, String configId, JLabel label) {
|
protected JLabel format(Stage stage, String configId, JLabel label) {
|
||||||
StageSeparationConfiguration sepConfig = stage.getStageSeparationConfiguration().get(configId);
|
StageSeparationConfiguration sepConfig = stage.getStageSeparationConfiguration().get(configId);
|
||||||
String spec = getSeparationSpecification(sepConfig);
|
String spec = getSeparationSpecification(sepConfig);
|
||||||
label.setText(spec);
|
label.setText(spec);
|
||||||
@ -139,6 +128,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
|
|||||||
} else {
|
} else {
|
||||||
regular(label);
|
regular(label);
|
||||||
}
|
}
|
||||||
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSeparationSpecification( StageSeparationConfiguration sepConfig ) {
|
private String getSeparationSpecification( StageSeparationConfiguration sepConfig ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user