Merge pull request #180 from kruland2607/master

Fix various bugs in flight configurations
This commit is contained in:
kruland2607 2014-02-17 15:13:00 -06:00
commit f5d09233e8
6 changed files with 72 additions and 96 deletions

View File

@ -10,6 +10,7 @@ import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel;
@ -34,6 +35,8 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
public MotorChooserDialog(Window owner) {
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"));
@ -67,7 +70,7 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
this.setModal(true);
this.pack();
this.setLocationByPlatform(true);
GUIUtil.setDisposableDialogOptions(this, okButton);
GUIUtil.installEscapeCloseOperation(this);
JComponent focus = selectionPanel.getDefaultFocus();
if (focus != null) {

View File

@ -304,25 +304,25 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
this.add(rightSide);
// Update the panel data
scrollSelectionVisible();
updateData();
setDelays(false);
}
public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) {
ThrustCurveMotor motorToSelect = null;
if (currentConfig != null && mount != null) {
MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig);
selectedMotor = (ThrustCurveMotor) motorConf.getMotor();
motorToSelect = (ThrustCurveMotor) motorConf.getMotor();
selectedDelay = motorConf.getEjectionDelay();
}
selectedMotorSet = null;
// If current motor is not found in db, add a new ThrustCurveMotorSet containing it
if (selectedMotor != null) {
if (motorToSelect != null) {
for (ThrustCurveMotorSet motorSet : database) {
if (motorSet.getMotors().contains(selectedMotor)) {
if (motorSet.getMotors().contains(motorToSelect)) {
selectedMotorSet = motorSet;
break;
}
@ -330,15 +330,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
if (selectedMotorSet == null) {
database = new ArrayList<ThrustCurveMotorSet>(database);
ThrustCurveMotorSet extra = new ThrustCurveMotorSet();
extra.addMotor(selectedMotor);
extra.addMotor(motorToSelect);
selectedMotorSet = extra;
database.add(extra);
Collections.sort(database);
}
}
updateData();
setDelays(true);
select(motorToSelect);
motorFilterPanel.setMotorMount(mount);
scrollSelectionVisible();
@ -394,7 +393,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
* Called when a different motor is selected from within the panel.
*/
private void select(ThrustCurveMotor motor) {
if (selectedMotor == motor)
if (selectedMotor == motor || motor == null)
return;
ThrustCurveMotorSet set = findMotorSet(motor);
@ -410,6 +409,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
if (updateDelays) {
setDelays(true);
}
scrollSelectionVisible();
}

View File

@ -5,12 +5,17 @@ import java.awt.Component;
import java.awt.Font;
import java.util.EventObject;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
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.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import net.miginfocom.swing.MigLayout;
@ -47,6 +52,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
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() {
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
@ -67,11 +82,24 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
String rowId = rocket.getFlightConfigurationIDs()[row + 1];
if ( rowId.equals(id) ) {
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() {
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@ -143,18 +171,41 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
switch (column) {
case 0: {
label.setText(descriptor.format(rocket, (String) value));
regular(label);
setSelected(label, table, isSelected, hasFocus);
return label;
}
default: {
Pair<String, T> v = (Pair<String, T>) value;
String id = v.getU();
T component = v.getV();
format(component, id, label );
label = format(component, id, label );
setSelected(label, table, isSelected, hasFocus);
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) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(Color.GRAY);
@ -165,7 +216,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
label.setForeground(Color.BLACK);
}
protected abstract void format( T component, String configId, JLabel label );
protected abstract JLabel format( T component, String configId, JLabel label );
}

View File

@ -187,17 +187,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return configurationTable;
}
public void fireTableDataChanged() {
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() {
protected void updateButtonState() {
if( configurationTableModel.getColumnCount() > 1 ) {
showContent();
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
@ -280,52 +270,10 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
}
private class MotorTableCellRenderer implements TableCellRenderer {
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);
}
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected, boolean hasFocus, int row,int column) {
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) {
protected JLabel format( MotorMount mount, String configId, JLabel l ) {
JLabel label = new JLabel();
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
@ -337,7 +285,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
label.add(ignitionLabel);
label.validate();
return label;
// label.setText(motorString + " " + ignitionString);
}
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
@ -359,12 +306,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
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) {
IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(id);
IgnitionConfiguration.IgnitionEvent ignitionEvent = ignitionConfig.getIgnitionEvent();

View File

@ -86,16 +86,6 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
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() {
RecoveryDevice c = getSelectedComponent();
if (c == null) {
@ -125,7 +115,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
class RecoveryTableCellRenderer extends FlightConfigurablePanel<RecoveryDevice>.FlightConfigurableCellRenderer {
@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);
String spec = getDeploymentSpecification(deployConfig);
label.setText(spec);
@ -134,6 +124,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
} else {
regular(label);
}
return label;
}
private String getDeploymentSpecification( DeploymentConfiguration config ) {

View File

@ -91,17 +91,6 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
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() {
Stage stage = getSelectedComponent();
if (stage == null) {
@ -130,7 +119,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
private class SeparationTableCellRenderer extends FlightConfigurablePanel<Stage>.FlightConfigurableCellRenderer {
@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);
String spec = getSeparationSpecification(sepConfig);
label.setText(spec);
@ -139,6 +128,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
} else {
regular(label);
}
return label;
}
private String getSeparationSpecification( StageSeparationConfiguration sepConfig ) {