[bugfix] RocketPanel configuration list now updates changes
- Pulled JComboBoxModel<FlightConfiguration> into its own class: ConfigurationModel -- removed Rocket.toConfigArray() --> getFlightConfigurationByIndex(int,bool) -Refactored document.getDefaultConfiguration -> getSelected... -- because that's what it does. Default is a different thing. -minor: minor spelling errors and unused fields/functions
This commit is contained in:
parent
df328c1555
commit
b02e164bce
@ -164,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
|
||||
|
||||
public FlightConfiguration getDefaultConfiguration() {
|
||||
public FlightConfiguration getSelectedConfiguration() {
|
||||
return rocket.getSelectedConfiguration();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
throw new RocketLoadException("Malformed XML in input.", e);
|
||||
}
|
||||
|
||||
doc.getDefaultConfiguration().setAllStages();
|
||||
doc.getSelectedConfiguration().setAllStages();
|
||||
|
||||
// Deduce suitable time skip
|
||||
double timeSkip = StorageOptions.SIMULATION_DATA_NONE;
|
||||
|
@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -52,10 +51,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
this.active = _active;
|
||||
}
|
||||
|
||||
public int getKey(){
|
||||
return this.stage.getStageNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StageFlags clone(){
|
||||
return new StageFlags( this.stage, this.prev, true);
|
||||
@ -119,7 +114,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
/**
|
||||
* This method flags a stage inactive. Other stages are unaffected.
|
||||
*
|
||||
* @param stageNumber stage number to inactivate
|
||||
* @param stageNumber stage number to turn off
|
||||
*/
|
||||
public void clearStage(final int stageNumber) {
|
||||
_setStageActive( stageNumber, false );
|
||||
@ -214,7 +209,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the compoment for the bottom-most center, active stage.
|
||||
* @return the component for the bottom-most center, active stage.
|
||||
*/
|
||||
public AxialStage getBottomStage() {
|
||||
AxialStage bottomStage = null;
|
||||
@ -248,12 +243,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
return Math.PI * MathUtil.pow2(getReferenceLength() / 2);
|
||||
}
|
||||
|
||||
public FlightConfigurationId getFlightConfigurationID() {
|
||||
return fcid;
|
||||
}
|
||||
|
||||
public FlightConfigurationId getFlightConfigurationID() {
|
||||
return fcid;
|
||||
}
|
||||
|
||||
public FlightConfigurationId getId() {
|
||||
return getFlightConfigurationID();
|
||||
return fcid;
|
||||
}
|
||||
|
||||
//////////////// Listeners ////////////////
|
||||
@ -506,7 +501,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
if(( null == newName ) ||( "".equals(newName))){
|
||||
this.configurationName = null;
|
||||
return;
|
||||
}else if( ! this.getFlightConfigurationID().isValid()){
|
||||
}else if( ! this.getId().isValid()){
|
||||
return;
|
||||
}else if( newName.equals(this.configurationName)){
|
||||
return;
|
||||
@ -532,10 +527,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
// DEBUG / DEVEL
|
||||
public String toStageListDetail() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("\nDumping %d stages for config: %s: (#: %d)\n", this.stages.size(), this.getName(), this.instanceNumber));
|
||||
buf.append(String.format("\nDumping %d stages for config: %s: (%s)(#: %d)\n",
|
||||
stages.size(), getName(), getId().toShortKey(), instanceNumber));
|
||||
final String fmt = " [%-2s][%4s]: %6s \n";
|
||||
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
||||
for (StageFlags flags : this.stages.values()) {
|
||||
for (StageFlags flags : stages.values()) {
|
||||
AxialStage curStage = flags.stage;
|
||||
buf.append(String.format(fmt, curStage.getStageNumber(), (flags.active?" on": "off"), curStage.getName()));
|
||||
}
|
||||
@ -547,7 +543,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
public String toMotorDetail(){
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(String.format("\nDumping %2d Motors for configuration %s (%s)(#: %s)\n",
|
||||
this.motors.size(), this.getName(), this.getFlightConfigurationID().toFullKey(), this.instanceNumber));
|
||||
motors.size(), getName(), getId().toShortKey(), this.instanceNumber));
|
||||
|
||||
for( MotorConfiguration curConfig : this.motors.values() ){
|
||||
buf.append(" "+curConfig.toDebugDetail()+"\n");
|
||||
|
@ -482,7 +482,12 @@ public class Rocket extends RocketComponent {
|
||||
// Copy the list before iterating to prevent concurrent modification exceptions.
|
||||
EventListener[] list = listenerList.toArray(new EventListener[0]);
|
||||
for (EventListener l : list) {
|
||||
if (l instanceof ComponentChangeListener) {
|
||||
{ // vvvv DEVEL vvvv
|
||||
//System.err.println("notifying listener. (type= "+l.getClass().getSimpleName()+")");
|
||||
//System.err.println(" (type= "+l.getClass().getName()+")");
|
||||
} // ^^^^ DEVEL ^^^^
|
||||
|
||||
if (l instanceof ComponentChangeListener) {
|
||||
((ComponentChangeListener) l).componentChanged(cce);
|
||||
} else if (l instanceof StateChangeListener) {
|
||||
((StateChangeListener) l).stateChanged(cce);
|
||||
@ -577,16 +582,6 @@ public class Rocket extends RocketComponent {
|
||||
return configSet.getIds();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Primarily for use with UI elements
|
||||
*
|
||||
* @return list of attached flight configurations (unordered)
|
||||
*/
|
||||
public FlightConfiguration[] toConfigArray(){
|
||||
return this.configSet.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a flight configuration ID from the configuration IDs. The
|
||||
* <code>FlightConfigurationId.DEFAULT_VALUE_FCID</code> ID cannot be removed,
|
||||
@ -668,7 +663,7 @@ public class Rocket extends RocketComponent {
|
||||
return this.getFlightConfiguration(fcid);
|
||||
}
|
||||
FlightConfiguration nextConfig = new FlightConfiguration(this, fcid);
|
||||
this.configSet.set(nextConfig.getFlightConfigurationID(), nextConfig);
|
||||
this.configSet.set(nextConfig.getId(), nextConfig);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE);
|
||||
return nextConfig;
|
||||
}
|
||||
@ -685,13 +680,25 @@ public class Rocket extends RocketComponent {
|
||||
return this.configSet.get(fcid);
|
||||
}
|
||||
|
||||
public FlightConfiguration getFlightConfigurationByIndex(final int configIndex) {
|
||||
return getFlightConfigurationByIndex( configIndex, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a flight configuration. If the supplied index is out of bounds, an exception is thrown.
|
||||
* Return a flight configuration. If the supplied index is out of bounds, an exception is thrown.
|
||||
* If the default instance is allowed, the default will be at index 0.
|
||||
*
|
||||
* @param configIndex the flight configuration index number
|
||||
* @return a FlightConfiguration instance
|
||||
* @param includeDefault Whether to allow returning the default instance
|
||||
* @param configIndex The flight configuration index number
|
||||
* @return a FlightConfiguration instance
|
||||
*/
|
||||
public FlightConfiguration getFlightConfiguration(final int configIndex) {
|
||||
public FlightConfiguration getFlightConfigurationByIndex( int configIndex, final boolean allowDefault ) {
|
||||
if( allowDefault ){
|
||||
if( 0 == configIndex ){
|
||||
return configSet.getDefault();
|
||||
}
|
||||
--configIndex;
|
||||
}
|
||||
return this.configSet.get( this.getId(configIndex));
|
||||
}
|
||||
|
||||
@ -704,7 +711,7 @@ public class Rocket extends RocketComponent {
|
||||
checkState();
|
||||
this.selectedConfiguration = this.configSet.get( selectId );
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate the given ID and flight configuration.
|
||||
@ -728,7 +735,6 @@ public class Rocket extends RocketComponent {
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
//////// Obligatory component information
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
|
@ -162,23 +162,7 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNullSelectedConfiguration(){
|
||||
Rocket rkt = new Rocket();
|
||||
|
||||
// PRE-CONDITION:
|
||||
// test that all configurations correctly loaded:
|
||||
int expectedConfigCount = 0;
|
||||
int actualConfigCount = rkt.getConfigurationCount();
|
||||
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
|
||||
|
||||
rkt.getSelectedConfiguration();
|
||||
expectedConfigCount = 1;
|
||||
actualConfigCount = rkt.getConfigurationCount();
|
||||
assertThat("createFlightConfiguration with null: doesn't actually work.", actualConfigCount, equalTo(expectedConfigCount));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationSpecific() {
|
||||
public void testMotorConfigurations() {
|
||||
/* Setup */
|
||||
Rocket rkt = TestRockets.makeEstesAlphaIII();
|
||||
|
||||
@ -188,6 +172,12 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
int actualMotorCount = smmt.getMotorCount();
|
||||
assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlightConfigurationGetters(){
|
||||
Rocket rkt = TestRockets.makeEstesAlphaIII();
|
||||
|
||||
// test that all configurations correctly loaded:
|
||||
int expectedConfigCount = 5;
|
||||
int actualConfigCount = rkt.getConfigurationCount();
|
||||
@ -197,10 +187,25 @@ public class FlightConfigurationTest extends BaseTestCase {
|
||||
assertThat("number of configuration array ids doesn't actually match.",
|
||||
actualConfigCount, equalTo(expectedConfigCount));
|
||||
|
||||
int expectedConfigArraySize = 6;
|
||||
int actualConfigArraySize = rkt.toConfigArray().length;
|
||||
assertThat("Size of configuration arrays doesn't actually match.",
|
||||
actualConfigArraySize, equalTo(expectedConfigArraySize));
|
||||
// upon success, these silently complete.
|
||||
// upon failure, they'll throw exceptions:
|
||||
rkt.getFlightConfigurationByIndex(4);
|
||||
rkt.getFlightConfigurationByIndex(5, true);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=java.lang.IndexOutOfBoundsException.class)
|
||||
public void testGetFlightConfigurationOutOfBounds(){
|
||||
Rocket rkt = TestRockets.makeEstesAlphaIII();
|
||||
|
||||
// test that all configurations correctly loaded:
|
||||
int expectedConfigCount = 5;
|
||||
int actualConfigCount = rkt.getConfigurationCount();
|
||||
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
|
||||
|
||||
// this SHOULD throw an exception --
|
||||
// it's out of bounds on, and no configuration exists at index 5.
|
||||
rkt.getFlightConfigurationByIndex(5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,71 @@
|
||||
package net.sf.openrocket.gui.components;
|
||||
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class ConfigurationModel implements ComboBoxModel<FlightConfiguration>, StateChangeListener {
|
||||
|
||||
private final Rocket rkt;
|
||||
|
||||
//private FlightConfigurationSelector(){}
|
||||
|
||||
public ConfigurationModel( final Rocket _rkt) {
|
||||
rkt = _rkt;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
// FlightConfiguration newConfig = (FlightConfiguration)this.getSelectedItem();
|
||||
// rkt.setSelectedConfiguration( newConfig.getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
return rkt.getSelectedConfiguration();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setSelectedItem(Object nextItem) {
|
||||
if( nextItem instanceof FlightConfiguration ){
|
||||
FlightConfigurationId selectedId = ((FlightConfiguration)nextItem).getId();
|
||||
rkt.setSelectedConfiguration(selectedId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListDataListener(ListDataListener l) {
|
||||
// let the rocket send events, if necessary
|
||||
// ignore any listen requests here...
|
||||
}
|
||||
|
||||
|
||||
public FlightConfiguration getElementAt( final int configIndex) {
|
||||
return rkt.getFlightConfigurationByIndex(configIndex, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
// plus the default config
|
||||
return rkt.getConfigurationCount()+1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeListDataListener(ListDataListener l) {
|
||||
// delegate event handling to the rocket
|
||||
// ignore any listen requests here...
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -47,6 +47,7 @@ import net.sf.openrocket.gui.adaptors.ColumnTable;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.ConfigurationModel;
|
||||
import net.sf.openrocket.gui.components.StageSelector;
|
||||
import net.sf.openrocket.gui.components.StyledLabel;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
@ -75,7 +76,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
|
||||
|
||||
private final FlightConditions conditions;
|
||||
private final FlightConfiguration configuration;
|
||||
private final Rocket rkt;
|
||||
private final DoubleModel theta, aoa, mach, roll;
|
||||
private final JToggleButton worstToggle;
|
||||
private boolean fakeChange = false;
|
||||
@ -105,11 +106,11 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||
add(panel);
|
||||
|
||||
this.configuration = rocketPanel.getConfiguration();
|
||||
rkt = rocketPanel.getDocument().getRocket();
|
||||
this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance();
|
||||
|
||||
|
||||
conditions = new FlightConditions(configuration);
|
||||
conditions = new FlightConditions(rkt.getSelectedConfiguration());
|
||||
|
||||
rocketPanel.setCPAOA(0);
|
||||
aoa = new DoubleModel(rocketPanel, "CPAOA", UnitGroup.UNITS_ANGLE, 0, Math.PI);
|
||||
@ -169,7 +170,6 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
// Stage and motor selection:
|
||||
//// Active stages:
|
||||
panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.activestages")), "spanx, split, gapafter rel");
|
||||
Rocket rkt = rocketPanel.getDocument().getRocket();
|
||||
panel.add(new StageSelector( rkt), "gapafter paragraph");
|
||||
|
||||
//// Motor configuration:
|
||||
@ -177,9 +177,9 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||
panel.add(label, "growx, right");
|
||||
|
||||
JComboBox<FlightConfiguration> combo = new JComboBox<FlightConfiguration>( configuration.getRocket().toConfigArray());
|
||||
|
||||
panel.add(combo, "wrap");
|
||||
final ConfigurationModel configModel = new ConfigurationModel(rkt);
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
||||
panel.add( configComboBox, "wrap");
|
||||
|
||||
|
||||
// Tabbed pane
|
||||
@ -517,6 +517,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
*/
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
|
||||
AerodynamicForces forces;
|
||||
WarningSet set = new WarningSet();
|
||||
conditions.setAOA(aoa.getValue());
|
||||
@ -580,12 +581,12 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
|
||||
data[1] = MassCalcType.LAUNCH_MASS.getCG(motorConfig);
|
||||
}
|
||||
|
||||
forces = aeroData.get(configuration.getRocket());
|
||||
forces = aeroData.get(rkt);
|
||||
if (forces != null) {
|
||||
Object[] data = new Object[3];
|
||||
cgData.add(data);
|
||||
data[0] = configuration.getRocket();
|
||||
data[1] = massData.get(configuration.getRocket());
|
||||
data[0] = rkt;
|
||||
data[1] = massData.get(rkt);
|
||||
data[2] = forces;
|
||||
dragData.add(forces);
|
||||
rollData.add(forces);
|
||||
|
@ -91,7 +91,7 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
||||
((GLAutoDrawable) canvas).invoke(false, new GLRunnable() {
|
||||
@Override
|
||||
public boolean run(final GLAutoDrawable drawable) {
|
||||
PhotoPanel.this.configuration = doc.getDefaultConfiguration();
|
||||
PhotoPanel.this.configuration = doc.getSelectedConfiguration();
|
||||
cachedBounds = null;
|
||||
rr = new RealisticRenderer(doc);
|
||||
rr.init(drawable);
|
||||
|
@ -26,6 +26,7 @@ import net.sf.openrocket.rocketvisitors.ListMotorMounts;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FlightConfigurationPanel extends JPanel implements StateChangeListener {
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
|
@ -5,8 +5,6 @@ import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
@ -42,6 +40,7 @@ import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.StageSelector;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
import net.sf.openrocket.gui.components.ConfigurationModel;
|
||||
import net.sf.openrocket.gui.configdialog.ComponentConfigDialog;
|
||||
import net.sf.openrocket.gui.figure3d.RocketFigure3d;
|
||||
import net.sf.openrocket.gui.figureelements.CGCaret;
|
||||
@ -75,6 +74,7 @@ import net.sf.openrocket.util.Coordinate;
|
||||
import net.sf.openrocket.util.MathUtil;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
|
||||
/**
|
||||
* A JPanel that contains a RocketFigure and buttons to manipulate the figure.
|
||||
*
|
||||
@ -86,7 +86,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
public static enum VIEW_TYPE {
|
||||
public enum VIEW_TYPE {
|
||||
SideView(false, RocketFigure.VIEW_SIDE),
|
||||
BackView(false, RocketFigure.VIEW_BACK),
|
||||
Figure3D(true, RocketFigure3d.TYPE_FIGURE),
|
||||
@ -96,7 +96,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
public final boolean is3d;
|
||||
private final int type;
|
||||
|
||||
private VIEW_TYPE(final boolean is3d, final int type) {
|
||||
VIEW_TYPE(final boolean is3d, final int type) {
|
||||
this.is3d = is3d;
|
||||
this.type = type;
|
||||
};
|
||||
@ -140,7 +140,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
// The functional ID of the rocket that was simulated
|
||||
private int flightDataFunctionalID = -1;
|
||||
private FlightConfigurationId flightDataMotorID = null;
|
||||
private FlightConfigurationId flightDataMotorID = null;
|
||||
|
||||
private SimulationWorker backgroundSimulationWorker = null;
|
||||
|
||||
@ -271,12 +271,21 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
* Creates the layout and components of the panel.
|
||||
*/
|
||||
private void createPanel() {
|
||||
final Rocket rkt = document.getRocket();
|
||||
|
||||
rkt.addChangeListener(new StateChangeListener(){
|
||||
@Override
|
||||
public void stateChanged(EventObject eo) {
|
||||
updateExtras();
|
||||
updateFigures();
|
||||
}
|
||||
});
|
||||
|
||||
setLayout(new MigLayout("", "[shrink][grow]", "[shrink][shrink][grow][shrink]"));
|
||||
|
||||
setPreferredSize(new Dimension(800, 300));
|
||||
|
||||
// View Type Dropdown
|
||||
@SuppressWarnings("serial") // because java throws a warning without this.
|
||||
// View Type drop-down
|
||||
ComboBoxModel<VIEW_TYPE> cm = new DefaultComboBoxModel<VIEW_TYPE>(VIEW_TYPE.values()) {
|
||||
|
||||
@Override
|
||||
@ -301,7 +310,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
add(scaleSelector);
|
||||
|
||||
// Stage selector
|
||||
final Rocket rkt = document.getRocket();
|
||||
StageSelector stageSelector = new StageSelector( rkt );
|
||||
rkt.addChangeListener(stageSelector);
|
||||
add(stageSelector);
|
||||
@ -311,21 +319,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg"));
|
||||
label.setHorizontalAlignment(JLabel.RIGHT);
|
||||
add(label, "growx, right");
|
||||
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
|
||||
|
||||
|
||||
final ConfigurationModel configModel = new ConfigurationModel(rkt);
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
||||
rkt.addChangeListener( configModel );
|
||||
add(configComboBox, "wrap, width 16%, wmin 100");
|
||||
|
||||
configComboBox.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem();
|
||||
document.getRocket().setSelectedConfiguration( newConfig.getId());
|
||||
updateExtras();
|
||||
updateFigures();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Create slider and scroll pane
|
||||
DoubleModel theta = new DoubleModel(figure, "Rotation",
|
||||
@ -361,8 +360,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
return aerodynamicCalculator;
|
||||
}
|
||||
|
||||
public FlightConfiguration getConfiguration() {
|
||||
return document.getDefaultConfiguration();
|
||||
public FlightConfiguration getSelectedConfiguration() {
|
||||
return document.getSelectedConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -565,7 +564,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
Coordinate cp, cg;
|
||||
double cpx, cgx;
|
||||
|
||||
FlightConfiguration curConfig = document.getDefaultConfiguration();
|
||||
FlightConfiguration curConfig = document.getSelectedConfiguration();
|
||||
// TODO: MEDIUM: User-definable conditions
|
||||
FlightConditions conditions = new FlightConditions(curConfig);
|
||||
warnings.clear();
|
||||
@ -644,7 +643,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
extraText.setLength(length);
|
||||
extraText.setDiameter(diameter);
|
||||
extraText.setMass(cg.weight);
|
||||
extraText.setMassWithoutMotors( massCalculator.getCG( getConfiguration(), MassCalcType.NO_MOTORS ).weight );
|
||||
extraText.setMassWithoutMotors( massCalculator.getCG( getSelectedConfiguration(), MassCalcType.NO_MOTORS ).weight );
|
||||
extraText.setWarnings(warnings);
|
||||
|
||||
if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {
|
||||
@ -672,12 +671,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
// Check whether data is already up to date
|
||||
if (flightDataFunctionalID == curConfig.getRocket().getFunctionalModID() &&
|
||||
flightDataMotorID == curConfig.getFlightConfigurationID()) {
|
||||
flightDataMotorID == curConfig.getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
flightDataFunctionalID = curConfig.getRocket().getFunctionalModID();
|
||||
flightDataMotorID = curConfig.getFlightConfigurationID();
|
||||
flightDataMotorID = curConfig.getId();
|
||||
|
||||
// Stop previous computation (if any)
|
||||
stopBackgroundSimulation();
|
||||
@ -695,7 +694,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
Rocket duplicate = (Rocket) document.getRocket().copy();
|
||||
Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate);
|
||||
simulation.setFlightConfigurationId( document.getDefaultConfiguration().getFlightConfigurationID());
|
||||
simulation.setFlightConfigurationId( document.getSelectedConfiguration().getId());
|
||||
|
||||
backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation);
|
||||
backgroundSimulationExecutor.execute(backgroundSimulationWorker);
|
||||
@ -781,7 +780,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
* Adds the extra data to the figure. Currently this includes the CP and CG carets.
|
||||
*/
|
||||
private void addExtras() {
|
||||
FlightConfiguration curConfig = document.getDefaultConfiguration();
|
||||
FlightConfiguration curConfig = document.getSelectedConfiguration();
|
||||
extraCG = new CGCaret(0, 0);
|
||||
extraCP = new CPCaret(0, 0);
|
||||
extraText = new RocketInfo(curConfig);
|
||||
|
@ -21,10 +21,12 @@ import javax.swing.event.DocumentListener;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.gui.components.ConfigurationModel;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.simulation.extension.SimulationExtension;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
@ -145,8 +147,10 @@ public class SimulationEditDialog extends JDialog {
|
||||
label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg"));
|
||||
panel.add(label, "growx 0, gapright para");
|
||||
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<FlightConfiguration>( document.getRocket().toConfigArray());
|
||||
configComboBox.setSelectedItem( document.getRocket().getSelectedConfiguration().getId() );
|
||||
final Rocket rkt = document.getRocket();
|
||||
final ConfigurationModel configModel = new ConfigurationModel( rkt);
|
||||
final JComboBox<FlightConfiguration> configComboBox = new JComboBox<>(configModel);
|
||||
configComboBox.setSelectedItem( rkt.getSelectedConfiguration().getId() );
|
||||
|
||||
//// Select the motor configuration to use.
|
||||
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user