UI updates

This commit is contained in:
Sampo Niskanen 2013-02-02 12:07:07 +02:00
parent b3b2303f27
commit d2035ce702
3 changed files with 102 additions and 117 deletions

View File

@ -1825,7 +1825,7 @@ MotorConfigurationPanel.btn.selectMotor = Select motor
MotorConfigurationPanel.btn.selectIgnition = Select ignition
MotorConfigurationPanel.btn.resetIgnition = Reset ignition
MotorConfigurationPanel.table.ignition.default = Default ({0})
MotorConfigurationTableModel.table.ignition.default = Default ({0})
MotorConfigurationPanel.description = <b>Select the motors and motor ignition events of your rocket.</b><br> <em>Motor mounts:</em> Select which components function as motor mounts.<br> <em>Motor configurations:</em> Select the motor and ignition event for each motor mount.

View File

@ -24,13 +24,10 @@ import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.MotorConfiguration.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Chars;
public class MotorConfigurationPanel extends JPanel {
@ -42,7 +39,6 @@ public class MotorConfigurationPanel extends JPanel {
private final MotorConfigurationTableModel configurationTableModel;
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
private MotorMount currentMount = null;
final MotorMount[] mounts;
MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) {
@ -84,7 +80,7 @@ public class MotorConfigurationPanel extends JPanel {
//// Motor selection table.
configurationTableModel = new MotorConfigurationTableModel(this, true);
configurationTableModel = new MotorConfigurationTableModel(rocket);
final JTable configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
configurationTable.setRowSelectionAllowed(true);
@ -94,12 +90,6 @@ public class MotorConfigurationPanel extends JPanel {
public void mouseClicked(MouseEvent e) {
int row = configurationTable.getSelectedRow();
if (row >= 0) {
currentMount = findMount(row);
} else {
currentMount = null;
}
if (e.getClickCount() == 1) {
// Single click updates selection
@ -162,7 +152,6 @@ public class MotorConfigurationPanel extends JPanel {
}
public void fireTableDataChanged() {
currentMount = null;
configurationTableModel.fireTableDataChanged();
updateButtonState();
}
@ -263,62 +252,5 @@ public class MotorConfigurationPanel extends JPanel {
return mount;
}
public String findMotorForDisplay(int row) {
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount mount = findMount(row);
Motor motor = mount.getMotor(currentID);
if (motor == null)
return null;
String str = motor.getDesignation(mount.getMotorDelay(currentID));
int count = mount.getMotorCount();
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
}
return str;
}
public String findIgnitionForDisplay(int row) {
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount mount = findMount(row);
MotorConfiguration motorConfig = mount.getFlightConfiguration(currentID);
if (motorConfig == null) {
// No motor exists
return null;
}
StringBuilder sb = new StringBuilder();
MotorConfiguration.IgnitionEvent ignition = motorConfig.getIgnitionEvent();
if (ignition == null) {
// Default ignition event
IgnitionEvent event = mount.getDefaultIgnitionEvent();
String def = trans.get("table.ignition.default");
String value = trans.get("MotorMount.IgnitionEvent.short." + event.name());
return def.replace("{0}", value);
} else {
sb.append(ellipsizeString(ignition.toString(), 15));
}
Double ignitionDelay = motorConfig.getIgnitionDelay();
if (ignitionDelay == null) {
double defaultdelay = mount.getDefaultIgnitionDelay();
if (defaultdelay > 0) {
sb.append(" + [").append(defaultdelay).append("s]");
}
} else {
sb.append(" + ").append(ignitionDelay).append("s");
}
return sb.toString();
}
private static String ellipsizeString(String s, int length) {
if (s.length() < length) {
return s;
}
String newString = s.substring(0, length) + "...";
return newString;
}
}

View File

@ -2,91 +2,93 @@ package net.sf.openrocket.gui.dialogs.flightconfiguration;
import javax.swing.table.AbstractTableModel;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Coordinate;
/**
* The table model for selecting and editing the motor configurations.
*/
class MotorConfigurationTableModel extends AbstractTableModel {
private Translator trans = Application.getTranslator();
private final static String NONE = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.None");
private final static String MOTOR_MOUNT = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Mountheader");
private final static String MOTOR = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Motorheader");
private final static String IGNITION = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Ignitionheader");
/**
*
*/
private final MotorConfigurationPanel motorConfigurationPanel;
private final Rocket rocket;
private final boolean advanced;
/**
* @param motorConfigurationPanel
*/
MotorConfigurationTableModel( MotorConfigurationPanel motorConfigurationPanel, boolean advanced) {
this.motorConfigurationPanel = motorConfigurationPanel;
this.advanced = advanced;
public MotorConfigurationTableModel(Rocket rocket) {
this.rocket = rocket;
}
@Override
public int getColumnCount() {
int count = (advanced)? 3: 2;
return count;
return 3;
}
@Override
public int getRowCount() {
int count = 0;
for (MotorMount m : this.motorConfigurationPanel.mounts) {
if (m.isMotorMount())
for (RocketComponent c : rocket) {
if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) {
count++;
}
}
return count;
}
@Override
public Object getValueAt(int row, int column) {
switch( column ) {
case 0:
{
MotorMount mount = this.motorConfigurationPanel.findMount(row);
switch (column) {
case 0: {
MotorMount mount = findMount(row);
String name = mount.toString();
int count = mount.getMotorCount();
int count = getMountMultiplicity(mount);
if (count > 1) {
name = name + " (" + Chars.TIMES + count + ")";
}
return name;
}
case 1:
{
String str = this.motorConfigurationPanel.findMotorForDisplay(row);
if (str == null)
//// None
case 1: {
MotorMount mount = findMount(row);
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
Motor motor = mount.getMotor(currentID);
if (motor == null)
return NONE;
String str = motor.getDesignation(mount.getMotorDelay(currentID));
int count = getMountMultiplicity(mount);
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
}
return str;
}
case 2:
{
String str = this.motorConfigurationPanel.findIgnitionForDisplay(row);
if (str == null)
//// None
return NONE;
case 2: {
return getIgnitionEventString(row);
return str;
}
default:
return "";
throw new IndexOutOfBoundsException("column=" + column);
}
}
@Override
public String getColumnName(int column) {
switch (column ) {
switch (column) {
case 0:
return MOTOR_MOUNT;
case 1:
@ -94,8 +96,59 @@ class MotorConfigurationTableModel extends AbstractTableModel {
case 2:
return IGNITION;
default:
return "";
throw new IndexOutOfBoundsException("column=" + column);
}
}
private MotorMount findMount(int row) {
int count = row;
for (RocketComponent c : rocket) {
if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) {
count--;
if (count < 0) {
return (MotorMount) c;
}
}
}
throw new IndexOutOfBoundsException("Requesting row=" + row + " but only " + getRowCount() + " rows exist");
}
private int getMountMultiplicity(MotorMount mount) {
RocketComponent c = (RocketComponent) mount;
return c.toAbsolute(Coordinate.NUL).length;
}
private String getIgnitionEventString(int row) {
String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
MotorMount mount = findMount(row);
MotorConfiguration motorConfig = mount.getFlightConfiguration(currentID);
if (motorConfig == null) {
return NONE;
}
MotorConfiguration.IgnitionEvent ignition = motorConfig.getIgnitionEvent();
Double ignitionDelay = motorConfig.getIgnitionDelay();
boolean isDefault = (ignition == null);
if (ignition == null) {
ignition = mount.getDefaultIgnitionEvent();
}
if (ignitionDelay == null) {
ignitionDelay = mount.getDefaultIgnitionDelay();
}
String str = trans.get("MotorMount.IgnitionEvent.short." + ignition.name());
if (ignitionDelay > 0) {
str = str + " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(ignitionDelay);
}
if (isDefault) {
String def = trans.get("table.ignition.default");
str = def.replace("{0}", str);
}
return str;
}
}