Explicitly create the plot with a parent window so the configuration
window can be dismissed automatically.
This commit is contained in:
		
							parent
							
								
									9107566b38
								
							
						
					
					
						commit
						4716030d1b
					
				| @ -16,28 +16,19 @@ import net.sf.openrocket.document.OpenRocketDocument; | ||||
| import net.sf.openrocket.document.Simulation; | ||||
| import net.sf.openrocket.gui.util.GUIUtil; | ||||
| import net.sf.openrocket.l10n.Translator; | ||||
| import net.sf.openrocket.rocketcomponent.Configuration; | ||||
| import net.sf.openrocket.simulation.FlightData; | ||||
| import net.sf.openrocket.simulation.SimulationOptions; | ||||
| import net.sf.openrocket.startup.Application; | ||||
| 
 | ||||
| public class SimulationPlotExportDialog extends JDialog { | ||||
| 	 | ||||
| 	private final Window parentWindow; | ||||
| 	private final Simulation simulation; | ||||
| 	private final OpenRocketDocument document; | ||||
| 	private final SimulationOptions conditions; | ||||
| 	private final Configuration configuration; | ||||
| 	private static final Translator trans = Application.getTranslator(); | ||||
| 	 | ||||
| 	public SimulationPlotExportDialog(Window parent, OpenRocketDocument document, Simulation s) { | ||||
| 		//// Plot/Export simulation | ||||
| 		super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL); | ||||
| 		this.document = document; | ||||
| 		this.parentWindow = parent; | ||||
| 		this.simulation = s; | ||||
| 		this.conditions = simulation.getOptions(); | ||||
| 		configuration = simulation.getConfiguration(); | ||||
| 		 | ||||
| 		JPanel mainPanel = new JPanel(new MigLayout("fill", "[grow]")); | ||||
| 		 | ||||
| @ -50,10 +41,10 @@ public class SimulationPlotExportDialog extends JDialog { | ||||
| 		final JTabbedPane tabbedPane = new JTabbedPane(); | ||||
| 		 | ||||
| 		//// Plot data | ||||
| 		final SimulationPlotPanel plotTab = plotTab(); | ||||
| 		final SimulationPlotPanel plotTab = new SimulationPlotPanel(simulation); | ||||
| 		tabbedPane.addTab(trans.get("simedtdlg.tab.Plotdata"), plotTab); | ||||
| 		//// Export data | ||||
| 		final SimulationExportPanel exportTab = exportTab(); | ||||
| 		final SimulationExportPanel exportTab = new SimulationExportPanel(simulation); | ||||
| 		tabbedPane.addTab(trans.get("simedtdlg.tab.Exportdata"), exportTab); | ||||
| 		 | ||||
| 		mainPanel.add(tabbedPane, "grow, wrap"); | ||||
| @ -64,7 +55,7 @@ public class SimulationPlotExportDialog extends JDialog { | ||||
| 			public void actionPerformed(ActionEvent e) { | ||||
| 				 | ||||
| 				if (tabbedPane.getSelectedIndex() == 0) { | ||||
| 					JDialog plot = plotTab.doPlot(); | ||||
| 					JDialog plot = plotTab.doPlot(SimulationPlotExportDialog.this.parentWindow); | ||||
| 					if (plot != null) { | ||||
| 						SimulationPlotExportDialog.this.dispose(); | ||||
| 						plot.setVisible(true); | ||||
| @ -98,40 +89,4 @@ public class SimulationPlotExportDialog extends JDialog { | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * A panel for plotting the previously calculated data. | ||||
| 	 */ | ||||
| 	private SimulationPlotPanel plotTab() { | ||||
| 		 | ||||
| 		// Check that data exists | ||||
| 		// FIXME - | ||||
| 		/* | ||||
| 		if (simulation.getSimulatedData() == null || | ||||
| 				simulation.getSimulatedData().getBranchCount() == 0) { | ||||
| 			return noDataPanel(); | ||||
| 		} | ||||
| 		*/ | ||||
| 		return new SimulationPlotPanel(simulation); | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * A panel for exporting the data. | ||||
| 	 */ | ||||
| 	private SimulationExportPanel exportTab() { | ||||
| 		FlightData data = simulation.getSimulatedData(); | ||||
| 		 | ||||
| 		// Check that data exists | ||||
| 		// FIXME -  | ||||
| 		/* | ||||
| 		if (data == null || data.getBranchCount() == 0 || | ||||
| 				data.getBranch(0).getTypes().length == 0) { | ||||
| 			return noDataPanel(); | ||||
| 		} | ||||
| 		*/ | ||||
| 		return new SimulationExportPanel(simulation); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| package net.sf.openrocket.gui.simulation; | ||||
| 
 | ||||
| import java.awt.Window; | ||||
| import java.awt.Window; | ||||
| import java.awt.event.ActionEvent; | ||||
| import java.awt.event.ActionListener; | ||||
| import java.awt.event.ItemEvent; | ||||
| @ -11,13 +11,12 @@ import java.util.EnumSet; | ||||
| import javax.swing.BorderFactory; | ||||
| import javax.swing.JButton; | ||||
| import javax.swing.JComboBox; | ||||
| import javax.swing.JDialog; | ||||
| import javax.swing.JDialog; | ||||
| import javax.swing.JLabel; | ||||
| import javax.swing.JOptionPane; | ||||
| import javax.swing.JPanel; | ||||
| import javax.swing.JScrollPane; | ||||
| import javax.swing.JTable; | ||||
| import javax.swing.SwingUtilities; | ||||
| import javax.swing.table.AbstractTableModel; | ||||
| import javax.swing.table.TableColumn; | ||||
| import javax.swing.table.TableColumnModel; | ||||
| @ -75,18 +74,18 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		PRESET_ARRAY[PRESET_ARRAY.length - 1] = CUSTOM_CONFIGURATION; | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 
 | ||||
| 	 | ||||
| 	 | ||||
| 	/** The current default configuration, set each time a plot is made. */ | ||||
| 	private static PlotConfiguration defaultConfiguration = | ||||
| 			PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits(); | ||||
| 	 | ||||
| 
 | ||||
| 	 | ||||
| 	private final Simulation simulation; | ||||
| 	private final FlightDataType[] types; | ||||
| 	private PlotConfiguration configuration; | ||||
| 	 | ||||
| 
 | ||||
| 	 | ||||
| 	private JComboBox configurationSelector; | ||||
| 	 | ||||
| 	private JComboBox domainTypeSelector; | ||||
| @ -95,7 +94,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 	private JPanel typeSelectorPanel; | ||||
| 	private FlightEventTableModel eventTableModel; | ||||
| 	 | ||||
| 
 | ||||
| 	 | ||||
| 	private int modifying = 0; | ||||
| 	 | ||||
| 	 | ||||
| @ -111,7 +110,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		types = branch.getTypes(); | ||||
| 		 | ||||
| 		setConfiguration(defaultConfiguration); | ||||
| 
 | ||||
| 		 | ||||
| 		////  Configuration selector | ||||
| 		 | ||||
| 		// Setup the combo box | ||||
| @ -130,7 +129,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 				// the UI when the selected item changes. | ||||
| 				// TODO - this should probably be implemented as an ActionListener instead | ||||
| 				// of ItemStateListener. | ||||
| 				if ( e.getStateChange() == ItemEvent.DESELECTED) { | ||||
| 				if (e.getStateChange() == ItemEvent.DESELECTED) { | ||||
| 					return; | ||||
| 				} | ||||
| 				if (modifying > 0) | ||||
| @ -148,8 +147,8 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		this.add(new JLabel(trans.get("simplotpanel.lbl.Presetplotconf")), "spanx, split"); | ||||
| 		this.add(configurationSelector, "growx, wrap 20lp"); | ||||
| 		 | ||||
| 
 | ||||
| 
 | ||||
| 		 | ||||
| 		 | ||||
| 		//// X axis | ||||
| 		 | ||||
| 		//// X axis type: | ||||
| @ -189,8 +188,8 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		desc.setViewportBorder(BorderFactory.createEmptyBorder()); | ||||
| 		this.add(desc, "width 1px, growx 1, wrap unrel"); | ||||
| 		 | ||||
| 
 | ||||
| 
 | ||||
| 		 | ||||
| 		 | ||||
| 		//// Y axis selector panel | ||||
| 		//// Y axis types: | ||||
| 		this.add(new JLabel(trans.get("simplotpanel.lbl.Yaxistypes"))); | ||||
| @ -201,7 +200,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		JScrollPane scroll = new JScrollPane(typeSelectorPanel); | ||||
| 		this.add(scroll, "spany 2, height 10px, wmin 400lp, grow 100, gapright para"); | ||||
| 		 | ||||
| 
 | ||||
| 		 | ||||
| 		//// Flight events | ||||
| 		eventTableModel = new FlightEventTableModel(); | ||||
| 		JTable table = new JTable(eventTableModel); | ||||
| @ -217,9 +216,9 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		col0.setPreferredWidth(w); | ||||
| 		col0.setMaxWidth(w); | ||||
| 		table.addMouseListener(new GUIUtil.BooleanTableClickListener(table)); | ||||
| 		this.add(new JScrollPane(table), "height 200px, width 200lp, grow 1, wrap rel"); | ||||
| 		this.add(new JScrollPane(table), "height 200px, width 200lp, grow 1, wrap rel"); | ||||
| 		 | ||||
| 		 | ||||
| 
 | ||||
| 		////  All + None buttons | ||||
| 		JButton button = new JButton(trans.get("simplotpanel.but.All")); | ||||
| 		button.addActionListener(new ActionListener() { | ||||
| @ -244,8 +243,8 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		}); | ||||
| 		this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap para"); | ||||
| 		 | ||||
| 
 | ||||
| 
 | ||||
| 		 | ||||
| 		 | ||||
| 		//// New Y axis plot type | ||||
| 		button = new JButton(trans.get("simplotpanel.but.NewYaxisplottype")); | ||||
| 		button.addActionListener(new ActionListener() { | ||||
| @ -264,41 +263,41 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 				// Select new type smartly | ||||
| 				FlightDataType type = null; | ||||
| 				for (FlightDataType t : | ||||
| 					simulation.getSimulatedData().getBranch(0).getTypes()) { | ||||
| 						 | ||||
| 						boolean used = false; | ||||
| 						if (configuration.getDomainAxisType().equals(t)) { | ||||
| 							used = true; | ||||
| 						} else { | ||||
| 							for (int i = 0; i < configuration.getTypeCount(); i++) { | ||||
| 								if (configuration.getType(i).equals(t)) { | ||||
| 									used = true; | ||||
| 									break; | ||||
| 								} | ||||
| 				simulation.getSimulatedData().getBranch(0).getTypes()) { | ||||
| 					 | ||||
| 					boolean used = false; | ||||
| 					if (configuration.getDomainAxisType().equals(t)) { | ||||
| 						used = true; | ||||
| 					} else { | ||||
| 						for (int i = 0; i < configuration.getTypeCount(); i++) { | ||||
| 							if (configuration.getType(i).equals(t)) { | ||||
| 								used = true; | ||||
| 								break; | ||||
| 							} | ||||
| 						} | ||||
| 						 | ||||
| 						if (!used) { | ||||
| 							type = t; | ||||
| 							break; | ||||
| 						} | ||||
| 					} | ||||
| 					if (type == null) { | ||||
| 						type = simulation.getSimulatedData().getBranch(0).getTypes()[0]; | ||||
| 					} | ||||
| 					 | ||||
| 					// Add new type | ||||
| 					configuration.addPlotDataType(type); | ||||
| 					setToCustom(); | ||||
| 					updatePlots(); | ||||
| 					if (!used) { | ||||
| 						type = t; | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 				if (type == null) { | ||||
| 					type = simulation.getSimulatedData().getBranch(0).getTypes()[0]; | ||||
| 				} | ||||
| 				 | ||||
| 				// Add new type | ||||
| 				configuration.addPlotDataType(type); | ||||
| 				setToCustom(); | ||||
| 				updatePlots(); | ||||
| 			} | ||||
| 		}); | ||||
| 		this.add(button, "spanx, split"); | ||||
| 		 | ||||
| 
 | ||||
| 		 | ||||
| 		this.add(new JPanel(), "growx"); | ||||
| 		 | ||||
| 		/* | ||||
| 		/* | ||||
| 		//// Plot flight | ||||
| 		button = new JButton(trans.get("simplotpanel.but.Plotflight")); | ||||
| 		button.addActionListener(new ActionListener() { | ||||
| @ -317,22 +316,21 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 			} | ||||
| 		}); | ||||
| 		this.add(button, "right"); | ||||
| 		*/ | ||||
| 		*/ | ||||
| 		updatePlots(); | ||||
| 	} | ||||
| 	 | ||||
| 	public JDialog doPlot() { | ||||
| 		if (configuration.getTypeCount() == 0) { | ||||
| 			JOptionPane.showMessageDialog(SimulationPlotPanel.this, | ||||
| 					trans.get("error.noPlotSelected"), | ||||
| 					trans.get("error.noPlotSelected.title"), | ||||
| 					JOptionPane.ERROR_MESSAGE); | ||||
| 			return null; | ||||
| 		} | ||||
| 		defaultConfiguration = configuration.clone(); | ||||
| 		return SimulationPlotDialog.getPlot((Window) SwingUtilities.getRoot(SimulationPlotPanel.this), | ||||
| 				simulation, configuration); | ||||
| 	} | ||||
| 	public JDialog doPlot(Window parent) { | ||||
| 		if (configuration.getTypeCount() == 0) { | ||||
| 			JOptionPane.showMessageDialog(SimulationPlotPanel.this, | ||||
| 					trans.get("error.noPlotSelected"), | ||||
| 					trans.get("error.noPlotSelected.title"), | ||||
| 					JOptionPane.ERROR_MESSAGE); | ||||
| 			return null; | ||||
| 		} | ||||
| 		defaultConfiguration = configuration.clone(); | ||||
| 		return SimulationPlotDialog.getPlot(parent, simulation, configuration); | ||||
| 	} | ||||
| 	 | ||||
| 	private void setConfiguration(PlotConfiguration conf) { | ||||
| 		 | ||||
| @ -383,14 +381,14 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 		 | ||||
| 		// In order to consistantly update the ui, we need to validate before repaint. | ||||
| 		typeSelectorPanel.validate(); | ||||
| 		typeSelectorPanel.repaint();	 | ||||
| 		typeSelectorPanel.repaint(); | ||||
| 		 | ||||
| 		eventTableModel.fireTableDataChanged(); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 
 | ||||
| 
 | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * A JPanel which configures a single plot of a PlotConfiguration. | ||||
| 	 */ | ||||
| @ -460,7 +458,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 			}); | ||||
| 			this.add(axisSelector); | ||||
| 			 | ||||
| 
 | ||||
| 			 | ||||
| 			JButton button = new JButton(Icons.DELETE); | ||||
| 			//// Remove this plot | ||||
| 			button.setToolTipText(trans.get("simplotpanel.but.ttip.Removethisplot")); | ||||
| @ -478,7 +476,7 @@ public class SimulationPlotPanel extends JPanel { | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 
 | ||||
| 	 | ||||
| 	private class FlightEventTableModel extends AbstractTableModel { | ||||
| 		private final FlightEvent.Type[] eventTypes; | ||||
| 		 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user