Fixed motor table so it only shows motor mounts. Extracted the table cell renderer code into abstract base class.
This commit is contained in:
parent
c8f71fcc94
commit
f433c640e2
@ -1,17 +1,25 @@
|
|||||||
package net.sf.openrocket.gui.main.flightconfigpanel;
|
package net.sf.openrocket.gui.main.flightconfigpanel;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Font;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
||||||
|
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.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||||
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
|
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.Pair;
|
import net.sf.openrocket.util.Pair;
|
||||||
@ -68,7 +76,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void installTableListener() {
|
private final void installTableListener() {
|
||||||
getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||||
|
|
||||||
@ -98,7 +106,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract JTable initializeTable();
|
protected abstract JTable initializeTable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the embedded JTable
|
* Return the embedded JTable
|
||||||
* @return
|
* @return
|
||||||
@ -136,4 +144,42 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
|
||||||
|
@Override
|
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
|
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||||
|
if (!(c instanceof JLabel)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
JLabel label = (JLabel) c;
|
||||||
|
|
||||||
|
switch (column) {
|
||||||
|
case 0: {
|
||||||
|
label.setText(descriptor.format(rocket, (String) value));
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
Pair<String, T> v = (Pair<String, T>) value;
|
||||||
|
String id = v.getU();
|
||||||
|
T component = v.getV();
|
||||||
|
format(component, id, label );
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void shaded(JLabel label) {
|
||||||
|
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
||||||
|
label.setForeground(Color.GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void regular(JLabel label) {
|
||||||
|
GUIUtil.changeFontStyle(label, Font.PLAIN);
|
||||||
|
label.setForeground(Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void format( T component, String configId, JLabel label );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -40,12 +40,21 @@ public class FlightConfigurableTableModel<T extends FlightConfigurableComponent>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if this component should be included in the table.
|
||||||
|
* @param component
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected boolean includeComponent( T component ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
components.clear();
|
components.clear();
|
||||||
Iterator<RocketComponent> it = rocket.iterator();
|
Iterator<RocketComponent> it = rocket.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
RocketComponent c = it.next();
|
RocketComponent c = it.next();
|
||||||
if (clazz.isAssignableFrom(c.getClass())) {
|
if (clazz.isAssignableFrom(c.getClass()) && includeComponent( (T) c) ) {
|
||||||
components.add( (T) c);
|
components.add( (T) c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
@Override
|
@Override
|
||||||
protected JTable initializeTable() {
|
protected JTable initializeTable() {
|
||||||
//// Motor selection table.
|
//// Motor selection table.
|
||||||
configurationTableModel = new FlightConfigurableTableModel<MotorMount>(MotorMount.class,rocket);
|
configurationTableModel = new FlightConfigurableTableModel<MotorMount>(MotorMount.class,rocket) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean includeComponent(MotorMount component) {
|
||||||
|
return component.isMotorMount();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
configurationTable = new JTable(configurationTableModel);
|
configurationTable = new JTable(configurationTableModel);
|
||||||
configurationTable.setCellSelectionEnabled(true);
|
configurationTable.setCellSelectionEnabled(true);
|
||||||
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
@ -201,34 +208,17 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class MotorTableCellRenderer extends DefaultTableCellRenderer {
|
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
protected void format(MotorMount mount, String configId, JLabel label) {
|
||||||
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
|
||||||
if (!(c instanceof JLabel)) {
|
String motorString = getMotorSpecification(mount, motorConfig);
|
||||||
return c;
|
String ignitionString = getIgnitionEventString(configId, mount);
|
||||||
}
|
label.setText(motorString + " " + ignitionString);
|
||||||
JLabel label = (JLabel) c;
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case 0: {
|
|
||||||
label.setText(descriptor.format(rocket, (String) value));
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
Pair<String, MotorMount> v = (Pair<String, MotorMount>) value;
|
|
||||||
String id = v.getU();
|
|
||||||
MotorMount mount = v.getV();
|
|
||||||
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(id);
|
|
||||||
String motorString = getMotorSpecification(mount, motorConfig);
|
|
||||||
String ignitionString = getIgnitionEventString(id, mount);
|
|
||||||
label.setText(motorString + " " + ignitionString);
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
|
||||||
Motor motor = motorConfig.getMotor();
|
Motor motor = motorConfig.getMotor();
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
|
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
@ -133,50 +134,18 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
resetDeploymentButton.setEnabled(componentSelected);
|
resetDeploymentButton.setEnabled(componentSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RecoveryTableCellRenderer extends DefaultTableCellRenderer {
|
class RecoveryTableCellRenderer extends FlightConfigurablePanel<RecoveryDevice>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
RecoveryTableCellRenderer() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
protected void format(RecoveryDevice recovery, String configId, JLabel label) {
|
||||||
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
DeploymentConfiguration deployConfig = recovery.getDeploymentConfiguration().get(configId);
|
||||||
if (!(c instanceof JLabel)) {
|
String spec = getDeploymentSpecification(deployConfig);
|
||||||
return c;
|
label.setText(spec);
|
||||||
}
|
if (recovery.getDeploymentConfiguration().isDefault(configId)) {
|
||||||
JLabel label = (JLabel) c;
|
shaded(label);
|
||||||
|
} else {
|
||||||
switch (column) {
|
|
||||||
case 0: {
|
|
||||||
label.setText(descriptor.format(rocket, (String) value));
|
|
||||||
regular(label);
|
regular(label);
|
||||||
return label;
|
|
||||||
}
|
}
|
||||||
default: {
|
|
||||||
Pair<String, RecoveryDevice> v = (Pair<String, RecoveryDevice>) value;
|
|
||||||
String id = v.getU();
|
|
||||||
RecoveryDevice recovery = v.getV();
|
|
||||||
DeploymentConfiguration deployConfig = recovery.getDeploymentConfiguration().get(id);
|
|
||||||
String spec = getDeploymentSpecification(deployConfig);
|
|
||||||
label.setText(spec);
|
|
||||||
if (recovery.getDeploymentConfiguration().isDefault(id)) {
|
|
||||||
shaded(label);
|
|
||||||
} else {
|
|
||||||
regular(label);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shaded(JLabel label) {
|
|
||||||
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
|
||||||
label.setForeground(Color.GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void regular(JLabel label) {
|
|
||||||
GUIUtil.changeFontStyle(label, Font.PLAIN);
|
|
||||||
label.setForeground(Color.BLACK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDeploymentSpecification( DeploymentConfiguration config ) {
|
private String getDeploymentSpecification( DeploymentConfiguration config ) {
|
||||||
|
@ -21,6 +21,7 @@ import net.sf.openrocket.formatting.RocketDescriptor;
|
|||||||
import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog;
|
import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog;
|
||||||
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.rocketcomponent.RecoveryDevice;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.rocketcomponent.Stage;
|
import net.sf.openrocket.rocketcomponent.Stage;
|
||||||
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
|
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
|
||||||
@ -132,51 +133,20 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<Stage>
|
|||||||
resetDeploymentButton.setEnabled(componentSelected);
|
resetDeploymentButton.setEnabled(componentSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SeparationTableCellRenderer extends DefaultTableCellRenderer {
|
private class SeparationTableCellRenderer extends FlightConfigurablePanel<Stage>.FlightConfigurableCellRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
protected void format(Stage stage, String configId, JLabel label) {
|
||||||
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
StageSeparationConfiguration sepConfig = stage.getStageSeparationConfiguration().get(configId);
|
||||||
if (!(c instanceof JLabel)) {
|
String spec = getSeparationSpecification(sepConfig);
|
||||||
return c;
|
label.setText(spec);
|
||||||
}
|
if (stage.getStageSeparationConfiguration().isDefault(configId)) {
|
||||||
JLabel label = (JLabel) c;
|
shaded(label);
|
||||||
|
} else {
|
||||||
switch (column) {
|
|
||||||
case 0: {
|
|
||||||
label.setText(descriptor.format(rocket, (String) value));
|
|
||||||
regular(label);
|
regular(label);
|
||||||
return label;
|
|
||||||
}
|
}
|
||||||
default: {
|
|
||||||
Pair<String, Stage> v = (Pair<String, Stage>) value;
|
|
||||||
String id = v.getU();
|
|
||||||
Stage stage = v.getV();
|
|
||||||
StageSeparationConfiguration sepConfig = stage.getStageSeparationConfiguration().get(id);
|
|
||||||
String spec = getSeparationSpecification(sepConfig);
|
|
||||||
label.setText(spec);
|
|
||||||
if (stage.getStageSeparationConfiguration().isDefault(id)) {
|
|
||||||
shaded(label);
|
|
||||||
} else {
|
|
||||||
regular(label);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shaded(JLabel label) {
|
|
||||||
GUIUtil.changeFontStyle(label, Font.ITALIC);
|
|
||||||
label.setForeground(Color.GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void regular(JLabel label) {
|
|
||||||
GUIUtil.changeFontStyle(label, Font.PLAIN);
|
|
||||||
label.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSeparationSpecification( StageSeparationConfiguration sepConfig ) {
|
private String getSeparationSpecification( StageSeparationConfiguration sepConfig ) {
|
||||||
String str;
|
String str;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user