Add motor mount selection table to the Flight Configuration tab.
This commit is contained in:
parent
e091f3341a
commit
d6b19eb4b6
@ -1,6 +1,5 @@
|
|||||||
package net.sf.openrocket.gui.main.flightconfigpanel;
|
package net.sf.openrocket.gui.main.flightconfigpanel;
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
@ -8,13 +7,17 @@ import java.awt.event.MouseEvent;
|
|||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.table.DefaultTableCellRenderer;
|
|
||||||
|
|
||||||
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.gui.components.StyledLabel;
|
||||||
|
import net.sf.openrocket.gui.components.StyledLabel.Style;
|
||||||
import net.sf.openrocket.gui.dialogs.flightconfiguration.IgnitionSelectionDialog;
|
import net.sf.openrocket.gui.dialogs.flightconfiguration.IgnitionSelectionDialog;
|
||||||
|
import net.sf.openrocket.gui.dialogs.flightconfiguration.MotorMountConfigurationPanel;
|
||||||
import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
|
import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration;
|
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration;
|
||||||
@ -25,22 +28,38 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
|
|||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
import net.sf.openrocket.util.Chars;
|
import net.sf.openrocket.util.Chars;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
import net.sf.openrocket.util.Pair;
|
|
||||||
|
|
||||||
public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount> {
|
public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount> {
|
||||||
|
|
||||||
private static final String NONE = trans.get("edtmotorconfdlg.tbl.None");
|
private static final String NONE = trans.get("edtmotorconfdlg.tbl.None");
|
||||||
|
|
||||||
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
|
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
|
||||||
|
|
||||||
protected FlightConfigurableTableModel<MotorMount> configurationTableModel;
|
protected FlightConfigurableTableModel<MotorMount> configurationTableModel;
|
||||||
|
|
||||||
MotorConfigurationPanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
|
MotorConfigurationPanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
|
||||||
super(flightConfigurationPanel,rocket);
|
super(flightConfigurationPanel,rocket);
|
||||||
|
|
||||||
|
{
|
||||||
|
//// Select motor mounts
|
||||||
|
JPanel subpanel = new JPanel(new MigLayout(""));
|
||||||
|
JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD);
|
||||||
|
subpanel.add(label, "wrap");
|
||||||
|
|
||||||
|
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) {
|
||||||
|
@Override
|
||||||
|
public void onDataChanged() {
|
||||||
|
MotorConfigurationPanel.this.fireTableDataChanged();
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
subpanel.add(mountConfigPanel, "grow");
|
||||||
|
this.add(subpanel, "split, w 200lp, growy");
|
||||||
|
}
|
||||||
|
|
||||||
JScrollPane scroll = new JScrollPane(table);
|
JScrollPane scroll = new JScrollPane(table);
|
||||||
this.add(scroll, "grow, wrap");
|
this.add(scroll, "grow, wrap");
|
||||||
|
|
||||||
//// Select motor
|
//// Select motor
|
||||||
selectMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectMotor"));
|
selectMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectMotor"));
|
||||||
selectMotorButton.addActionListener(new ActionListener() {
|
selectMotorButton.addActionListener(new ActionListener() {
|
||||||
@ -50,7 +69,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(selectMotorButton, "split, sizegroup button");
|
this.add(selectMotorButton, "split, sizegroup button");
|
||||||
|
|
||||||
//// Remove motor button
|
//// Remove motor button
|
||||||
removeMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.removeMotor"));
|
removeMotorButton = new JButton(trans.get("MotorConfigurationPanel.btn.removeMotor"));
|
||||||
removeMotorButton.addActionListener(new ActionListener() {
|
removeMotorButton.addActionListener(new ActionListener() {
|
||||||
@ -60,7 +79,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(removeMotorButton, "sizegroup button");
|
this.add(removeMotorButton, "sizegroup button");
|
||||||
|
|
||||||
//// Select Ignition button
|
//// Select Ignition button
|
||||||
selectIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectIgnition"));
|
selectIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.selectIgnition"));
|
||||||
selectIgnitionButton.addActionListener(new ActionListener() {
|
selectIgnitionButton.addActionListener(new ActionListener() {
|
||||||
@ -70,7 +89,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(selectIgnitionButton, "sizegroup button");
|
this.add(selectIgnitionButton, "sizegroup button");
|
||||||
|
|
||||||
//// Reset Ignition button
|
//// Reset Ignition button
|
||||||
resetIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.resetIgnition"));
|
resetIgnitionButton = new JButton(trans.get("MotorConfigurationPanel.btn.resetIgnition"));
|
||||||
resetIgnitionButton.addActionListener(new ActionListener() {
|
resetIgnitionButton.addActionListener(new ActionListener() {
|
||||||
@ -80,11 +99,11 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(resetIgnitionButton, "sizegroup button, wrap");
|
this.add(resetIgnitionButton, "sizegroup button, wrap");
|
||||||
|
|
||||||
updateButtonState();
|
updateButtonState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JTable initializeTable() {
|
protected JTable initializeTable() {
|
||||||
//// Motor selection table.
|
//// Motor selection table.
|
||||||
@ -94,13 +113,13 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
protected boolean includeComponent(MotorMount component) {
|
protected boolean includeComponent(MotorMount component) {
|
||||||
return component.isMotorMount();
|
return component.isMotorMount();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
JTable configurationTable = new JTable(configurationTableModel);
|
JTable configurationTable = new JTable(configurationTableModel);
|
||||||
configurationTable.setCellSelectionEnabled(true);
|
configurationTable.setCellSelectionEnabled(true);
|
||||||
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
configurationTable.setDefaultRenderer(Object.class, new MotorTableCellRenderer());
|
configurationTable.setDefaultRenderer(Object.class, new MotorTableCellRenderer());
|
||||||
|
|
||||||
configurationTable.addMouseListener(new MouseAdapter() {
|
configurationTable.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@ -125,7 +144,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
updateButtonState();
|
updateButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtonState() {
|
private void updateButtonState() {
|
||||||
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
MotorMount currentMount = getSelectedComponent();
|
MotorMount currentMount = getSelectedComponent();
|
||||||
@ -134,16 +153,16 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
selectIgnitionButton.setEnabled(currentMount != null && currentID != null);
|
selectIgnitionButton.setEnabled(currentMount != null && currentID != null);
|
||||||
resetIgnitionButton.setEnabled(currentMount != null && currentID != null);
|
resetIgnitionButton.setEnabled(currentMount != null && currentID != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void selectMotor() {
|
private void selectMotor() {
|
||||||
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
MotorMount mount = getSelectedComponent();
|
MotorMount mount = getSelectedComponent();
|
||||||
if (id == null || mount == null)
|
if (id == null || mount == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MotorConfiguration config = mount.getMotorConfiguration().get(id);
|
MotorConfiguration config = mount.getMotorConfiguration().get(id);
|
||||||
|
|
||||||
MotorChooserDialog dialog = new MotorChooserDialog(
|
MotorChooserDialog dialog = new MotorChooserDialog(
|
||||||
mount,
|
mount,
|
||||||
id,
|
id,
|
||||||
@ -151,59 +170,59 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
Motor m = dialog.getSelectedMotor();
|
Motor m = dialog.getSelectedMotor();
|
||||||
double d = dialog.getSelectedDelay();
|
double d = dialog.getSelectedDelay();
|
||||||
|
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
config = new MotorConfiguration();
|
config = new MotorConfiguration();
|
||||||
config.setMotor(m);
|
config.setMotor(m);
|
||||||
config.setEjectionDelay(d);
|
config.setEjectionDelay(d);
|
||||||
mount.getMotorConfiguration().set(id, config);
|
mount.getMotorConfiguration().set(id, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeMotor() {
|
private void removeMotor() {
|
||||||
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String id = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
MotorMount mount = getSelectedComponent();
|
MotorMount mount = getSelectedComponent();
|
||||||
if (id == null || mount == null)
|
if (id == null || mount == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mount.getMotorConfiguration().resetDefault(id);
|
mount.getMotorConfiguration().resetDefault(id);
|
||||||
|
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectIgnition() {
|
private void selectIgnition() {
|
||||||
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
MotorMount currentMount = getSelectedComponent();
|
MotorMount currentMount = getSelectedComponent();
|
||||||
if (currentID == null || currentMount == null)
|
if (currentID == null || currentMount == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IgnitionSelectionDialog dialog = new IgnitionSelectionDialog(
|
IgnitionSelectionDialog dialog = new IgnitionSelectionDialog(
|
||||||
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
|
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
|
||||||
rocket,
|
rocket,
|
||||||
currentMount);
|
currentMount);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void resetIgnition() {
|
private void resetIgnition() {
|
||||||
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
|
||||||
MotorMount currentMount = getSelectedComponent();
|
MotorMount currentMount = getSelectedComponent();
|
||||||
if (currentID == null || currentMount == null)
|
if (currentID == null || currentMount == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
currentMount.getIgnitionConfiguration().resetDefault(currentID);
|
currentMount.getIgnitionConfiguration().resetDefault(currentID);
|
||||||
|
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
|
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void format(MotorMount mount, String configId, JLabel label) {
|
protected void format(MotorMount mount, String configId, JLabel label) {
|
||||||
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
|
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
|
||||||
@ -214,10 +233,10 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
|
|
||||||
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
||||||
Motor motor = motorConfig.getMotor();
|
Motor motor = motorConfig.getMotor();
|
||||||
|
|
||||||
if (motor == null)
|
if (motor == null)
|
||||||
return NONE;
|
return NONE;
|
||||||
|
|
||||||
String str = motor.getDesignation(motorConfig.getEjectionDelay());
|
String str = motor.getDesignation(motorConfig.getEjectionDelay());
|
||||||
int count = getMountMultiplicity(mount);
|
int count = getMountMultiplicity(mount);
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
@ -225,21 +244,21 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMountMultiplicity(MotorMount mount) {
|
private int getMountMultiplicity(MotorMount mount) {
|
||||||
RocketComponent c = (RocketComponent) mount;
|
RocketComponent c = (RocketComponent) mount;
|
||||||
return c.toAbsolute(Coordinate.NUL).length;
|
return c.toAbsolute(Coordinate.NUL).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String getIgnitionEventString(String id, MotorMount mount) {
|
private String 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();
|
||||||
|
|
||||||
Double ignitionDelay = ignitionConfig.getIgnitionDelay();
|
Double ignitionDelay = ignitionConfig.getIgnitionDelay();
|
||||||
boolean isDefault = mount.getIgnitionConfiguration().isDefault(id);
|
boolean isDefault = mount.getIgnitionConfiguration().isDefault(id);
|
||||||
|
|
||||||
String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name());
|
String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name());
|
||||||
if (ignitionDelay > 0.001) {
|
if (ignitionDelay > 0.001) {
|
||||||
str = str + " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(ignitionDelay);
|
str = str + " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(ignitionDelay);
|
||||||
@ -250,7 +269,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user