diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index bc0540962..a5241cc23 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -1,17 +1,25 @@ package net.sf.openrocket.gui.main.flightconfigpanel; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; import java.util.EventObject; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableCellRenderer; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.formatting.RocketDescriptor; +import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; 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.startup.Application; import net.sf.openrocket.util.Pair; @@ -68,7 +76,7 @@ public abstract class FlightConfigurablePanel v = (Pair) 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 ); + + } + } \ No newline at end of file diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java index 853e959c8..14c31fd67 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java @@ -40,12 +40,21 @@ public class FlightConfigurableTableModel } } + /** + * Return true if this component should be included in the table. + * @param component + * @return + */ + protected boolean includeComponent( T component ) { + return true; + } + protected void initialize() { components.clear(); Iterator it = rocket.iterator(); while (it.hasNext()) { RocketComponent c = it.next(); - if (clazz.isAssignableFrom(c.getClass())) { + if (clazz.isAssignableFrom(c.getClass()) && includeComponent( (T) c) ) { components.add( (T) c); } } diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index ae86657a1..bb7969229 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -89,7 +89,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel @Override protected JTable initializeTable() { //// Motor selection table. - configurationTableModel = new FlightConfigurableTableModel(MotorMount.class,rocket); + configurationTableModel = new FlightConfigurableTableModel(MotorMount.class,rocket) { + + @Override + protected boolean includeComponent(MotorMount component) { + return component.isMotorMount(); + } + + }; configurationTable = new JTable(configurationTableModel); configurationTable.setCellSelectionEnabled(true); configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); @@ -201,34 +208,17 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel } - private class MotorTableCellRenderer extends DefaultTableCellRenderer { + private class MotorTableCellRenderer extends FlightConfigurablePanel.FlightConfigurableCellRenderer { + @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 v = (Pair) 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; - } - } + protected void format(MotorMount mount, String configId, JLabel label) { + MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId); + String motorString = getMotorSpecification(mount, motorConfig); + String ignitionString = getIgnitionEventString(configId, mount); + label.setText(motorString + " " + ignitionString); } - + private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) { Motor motor = motorConfig.getMotor(); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index 03055a7fa..7e3e460d1 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent; +import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; @@ -133,50 +134,18 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel.FlightConfigurableCellRenderer { @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)); + protected void format(RecoveryDevice recovery, String configId, JLabel label) { + DeploymentConfiguration deployConfig = recovery.getDeploymentConfiguration().get(configId); + String spec = getDeploymentSpecification(deployConfig); + label.setText(spec); + if (recovery.getDeploymentConfiguration().isDefault(configId)) { + shaded(label); + } else { regular(label); - return label; } - default: { - Pair v = (Pair) 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 ) { diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java index f4f0b748f..e9fe51c83 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java @@ -21,6 +21,7 @@ import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; +import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Stage; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; @@ -132,51 +133,20 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel resetDeploymentButton.setEnabled(componentSelected); } - private class SeparationTableCellRenderer extends DefaultTableCellRenderer { + private class SeparationTableCellRenderer extends FlightConfigurablePanel.FlightConfigurableCellRenderer { @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)); + protected void format(Stage stage, String configId, JLabel label) { + StageSeparationConfiguration sepConfig = stage.getStageSeparationConfiguration().get(configId); + String spec = getSeparationSpecification(sepConfig); + label.setText(spec); + if (stage.getStageSeparationConfiguration().isDefault(configId)) { + shaded(label); + } else { regular(label); - return label; } - default: { - Pair v = (Pair) 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 ) { String str;