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.selectIgnition = Select ignition
MotorConfigurationPanel.btn.resetIgnition = Reset 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. 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.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor; 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.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Chars;
public class MotorConfigurationPanel extends JPanel { public class MotorConfigurationPanel extends JPanel {
@ -42,7 +39,6 @@ public class MotorConfigurationPanel extends JPanel {
private final MotorConfigurationTableModel configurationTableModel; private final MotorConfigurationTableModel configurationTableModel;
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton; private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
private MotorMount currentMount = null;
final MotorMount[] mounts; final MotorMount[] mounts;
MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) { MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) {
@ -84,7 +80,7 @@ public class MotorConfigurationPanel extends JPanel {
//// Motor selection table. //// Motor selection table.
configurationTableModel = new MotorConfigurationTableModel(this, true); configurationTableModel = new MotorConfigurationTableModel(rocket);
final JTable configurationTable = new JTable(configurationTableModel); final JTable configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
configurationTable.setRowSelectionAllowed(true); configurationTable.setRowSelectionAllowed(true);
@ -94,12 +90,6 @@ public class MotorConfigurationPanel extends JPanel {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
int row = configurationTable.getSelectedRow(); int row = configurationTable.getSelectedRow();
if (row >= 0) {
currentMount = findMount(row);
} else {
currentMount = null;
}
if (e.getClickCount() == 1) { if (e.getClickCount() == 1) {
// Single click updates selection // Single click updates selection
@ -162,7 +152,6 @@ public class MotorConfigurationPanel extends JPanel {
} }
public void fireTableDataChanged() { public void fireTableDataChanged() {
currentMount = null;
configurationTableModel.fireTableDataChanged(); configurationTableModel.fireTableDataChanged();
updateButtonState(); updateButtonState();
} }
@ -263,62 +252,5 @@ public class MotorConfigurationPanel extends JPanel {
return mount; 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 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.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.Chars;
import net.sf.openrocket.util.Coordinate;
/** /**
* The table model for selecting and editing the motor configurations. * The table model for selecting and editing the motor configurations.
*/ */
class MotorConfigurationTableModel extends AbstractTableModel { class MotorConfigurationTableModel extends AbstractTableModel {
private Translator trans = Application.getTranslator();
private final static String NONE = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.None"); 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_MOUNT = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Mountheader");
private final static String MOTOR = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Motorheader"); private final static String MOTOR = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Motorheader");
private final static String IGNITION = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Ignitionheader"); private final static String IGNITION = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Ignitionheader");
/** private final Rocket rocket;
*
*/
private final MotorConfigurationPanel motorConfigurationPanel;
private final boolean advanced;
/** public MotorConfigurationTableModel(Rocket rocket) {
* @param motorConfigurationPanel this.rocket = rocket;
*/
MotorConfigurationTableModel( MotorConfigurationPanel motorConfigurationPanel, boolean advanced) {
this.motorConfigurationPanel = motorConfigurationPanel;
this.advanced = advanced;
} }
@Override @Override
public int getColumnCount() { public int getColumnCount() {
int count = (advanced)? 3: 2; return 3;
return count;
} }
@Override @Override
public int getRowCount() { public int getRowCount() {
int count = 0; int count = 0;
for (MotorMount m : this.motorConfigurationPanel.mounts) { for (RocketComponent c : rocket) {
if (m.isMotorMount()) if (c instanceof MotorMount && ((MotorMount) c).isMotorMount()) {
count++; count++;
} }
}
return count; return count;
} }
@Override @Override
public Object getValueAt(int row, int column) { public Object getValueAt(int row, int column) {
switch (column) {
switch( column ) { case 0: {
case 0: MotorMount mount = findMount(row);
{
MotorMount mount = this.motorConfigurationPanel.findMount(row);
String name = mount.toString(); String name = mount.toString();
int count = mount.getMotorCount(); int count = getMountMultiplicity(mount);
if (count > 1) { if (count > 1) {
name = name + " (" + Chars.TIMES + count + ")"; name = name + " (" + Chars.TIMES + count + ")";
} }
return name; return name;
} }
case 1: case 1: {
{ MotorMount mount = findMount(row);
String str = this.motorConfigurationPanel.findMotorForDisplay(row); String currentID = rocket.getDefaultConfiguration().getFlightConfigurationID();
if (str == null) Motor motor = mount.getMotor(currentID);
//// None
if (motor == null)
return NONE; return NONE;
String str = motor.getDesignation(mount.getMotorDelay(currentID));
int count = getMountMultiplicity(mount);
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
}
return str; return str;
} }
case 2: case 2: {
{ return getIgnitionEventString(row);
String str = this.motorConfigurationPanel.findIgnitionForDisplay(row);
if (str == null)
//// None
return NONE;
return str;
} }
default: default:
return ""; throw new IndexOutOfBoundsException("column=" + column);
} }
} }
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
switch (column ) { switch (column) {
case 0: case 0:
return MOTOR_MOUNT; return MOTOR_MOUNT;
case 1: case 1:
@ -94,8 +96,59 @@ class MotorConfigurationTableModel extends AbstractTableModel {
case 2: case 2:
return IGNITION; return IGNITION;
default: 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;
}
} }