Merge pull request #1512 from SiboVG/issue-1510
[#1510] Don't update flight configuration from simulation edit
This commit is contained in:
		
						commit
						30e423064e
					
				| @ -24,21 +24,49 @@ public class ConfigurationComboBox extends JComboBox<FlightConfiguration> implem | |||||||
|     public class ConfigurationModel implements MutableComboBoxModel<FlightConfiguration> { |     public class ConfigurationModel implements MutableComboBoxModel<FlightConfiguration> { | ||||||
| 		 | 		 | ||||||
| 		private final Rocket rkt; | 		private final Rocket rkt; | ||||||
|  | 		private FlightConfiguration selectedConfig; | ||||||
|  | 		private final boolean updateRocketConfig; | ||||||
|  | 		private final ConfigurationModel listener; | ||||||
| 
 | 
 | ||||||
| 		public ConfigurationModel(final Rocket _rkt) { | 		/** | ||||||
|  | 		 * @param _rkt the rocket to get the configurations from and to (optionally) change the rocket's selected configuration | ||||||
|  | 		 * @param _updateRocketConfig whether to update the rocket's selected configuration based on the selected combo box item, | ||||||
|  | 		 *                            or just change the combo box item without altering the rocket's configuration. | ||||||
|  | 		 * @param listener model that should change its selected item to this model's selected item | ||||||
|  | 		 */ | ||||||
|  | 		public ConfigurationModel(final Rocket _rkt, boolean _updateRocketConfig, ConfigurationModel listener) { | ||||||
| 			this.rkt = _rkt; | 			this.rkt = _rkt; | ||||||
|  | 			this.updateRocketConfig = _updateRocketConfig; | ||||||
|  | 			this.selectedConfig = this.rkt.getSelectedConfiguration(); | ||||||
|  | 			this.listener = listener; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		public ConfigurationModel(final Rocket _rkt, boolean _updateRocketConfig) { | ||||||
|  | 			this(_rkt, _updateRocketConfig, null); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		@Override | 		@Override | ||||||
| 		public FlightConfiguration getSelectedItem() { | 		public FlightConfiguration getSelectedItem() { | ||||||
|  | 			if (updateRocketConfig) { | ||||||
| 				return rkt.getSelectedConfiguration(); | 				return rkt.getSelectedConfiguration(); | ||||||
|  | 			} else { | ||||||
|  | 				return selectedConfig; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		@Override | 		@Override | ||||||
| 		public void setSelectedItem(Object nextItem) { | 		public void setSelectedItem(Object nextItem) { | ||||||
| 			if( nextItem instanceof FlightConfiguration ){ | 			if( nextItem instanceof FlightConfiguration ){ | ||||||
| 				FlightConfigurationId selectedId = ((FlightConfiguration)nextItem).getId(); | 				FlightConfigurationId selectedId = ((FlightConfiguration)nextItem).getId(); | ||||||
|  | 				if (updateRocketConfig) { | ||||||
| 					rkt.setSelectedConfiguration(selectedId); | 					rkt.setSelectedConfiguration(selectedId); | ||||||
|  | 				} else { | ||||||
|  | 					selectedConfig = rkt.getFlightConfiguration(selectedId); | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				if (listener != null) { | ||||||
|  | 					listener.setSelectedItem(nextItem); | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| @ -79,9 +107,15 @@ public class ConfigurationComboBox extends JComboBox<FlightConfiguration> implem | |||||||
| 	 | 	 | ||||||
|     private final Rocket rkt; |     private final Rocket rkt; | ||||||
| 
 | 
 | ||||||
|     public ConfigurationComboBox(Rocket _rkt) { | 	/** | ||||||
|  | 	 * @param _rkt the rocket to get the configurations from and to (optionally) change the rocket's selected configuration | ||||||
|  | 	 * @param _updateRocketConfig whether to update the rocket's selected configuration based on the selected combo box item, | ||||||
|  | 	 *                            or just change the combo box item without altering the rocket's configuration. | ||||||
|  | 	 */ | ||||||
|  |     public ConfigurationComboBox(Rocket _rkt, boolean _updateRocketConfig) { | ||||||
| 		rkt = _rkt; | 		rkt = _rkt; | ||||||
| 		setModel(new ConfigurationModel(rkt)); | 		final ConfigurationModel model = new ConfigurationModel(rkt, _updateRocketConfig); | ||||||
|  | 		setModel(model); | ||||||
| 		rkt.addChangeListener(this); | 		rkt.addChangeListener(this); | ||||||
| 	 | 	 | ||||||
| 		addPopupMenuListener(new PopupMenuListener() { | 		addPopupMenuListener(new PopupMenuListener() { | ||||||
| @ -89,13 +123,19 @@ public class ConfigurationComboBox extends JComboBox<FlightConfiguration> implem | |||||||
| 			public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} | 			public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} | ||||||
| 			 | 			 | ||||||
| 			public void popupMenuWillBecomeVisible(PopupMenuEvent e) { | 			public void popupMenuWillBecomeVisible(PopupMenuEvent e) { | ||||||
| 			    setModel(new ConfigurationModel(rkt));		     | 				final ConfigurationModel model2 = new ConfigurationModel(rkt, _updateRocketConfig, model); | ||||||
|  | 				model2.setSelectedItem(model.getSelectedItem()); | ||||||
|  | 			    setModel(model2); | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 		}); | 		}); | ||||||
| 	 | 	 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 	public ConfigurationComboBox(Rocket _rkt) { | ||||||
|  | 		this(_rkt, true); | ||||||
|  | 	} | ||||||
|  |      | ||||||
|     @Override |     @Override | ||||||
|     public void stateChanged(EventObject e) { |     public void stateChanged(EventObject e) { | ||||||
|     	this.repaint(); |     	this.repaint(); | ||||||
|  | |||||||
| @ -151,7 +151,7 @@ public class SimulationEditDialog extends JDialog { | |||||||
| 			 | 			 | ||||||
| 			final Rocket rkt = document.getRocket(); | 			final Rocket rkt = document.getRocket(); | ||||||
| 			final FlightConfiguration config = rkt.getFlightConfiguration(simulationList[0].getFlightConfigurationId()); | 			final FlightConfiguration config = rkt.getFlightConfiguration(simulationList[0].getFlightConfigurationId()); | ||||||
| 			final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt); | 			final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt, false); | ||||||
| 			configComboBox.setSelectedItem(config); | 			configComboBox.setSelectedItem(config); | ||||||
| 			 | 			 | ||||||
| 			//// Select the motor configuration to use. | 			//// Select the motor configuration to use. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user