1 package com.billkuker.rocketry.motorsim.visual;
\r
3 import java.awt.BorderLayout;
\r
4 import java.awt.Color;
\r
5 import java.awt.Dimension;
\r
6 import java.awt.GridLayout;
\r
7 import java.text.NumberFormat;
\r
9 import javax.measure.quantity.Duration;
\r
10 import javax.measure.quantity.Force;
\r
11 import javax.measure.quantity.Pressure;
\r
12 import javax.measure.quantity.Velocity;
\r
13 import javax.measure.unit.SI;
\r
14 import javax.swing.JFrame;
\r
15 import javax.swing.JLabel;
\r
16 import javax.swing.JPanel;
\r
17 import javax.swing.JSlider;
\r
18 import javax.swing.JSplitPane;
\r
19 import javax.swing.WindowConstants;
\r
20 import javax.swing.event.ChangeEvent;
\r
21 import javax.swing.event.ChangeListener;
\r
23 import org.jscience.physics.amount.Amount;
\r
25 import com.billkuker.rocketry.motorsim.Burn;
\r
26 import com.billkuker.rocketry.motorsim.BurnSummary;
\r
27 import com.billkuker.rocketry.motorsim.RocketScience;
\r
29 public class BurnPanel extends JPanel {
\r
30 private static final long serialVersionUID = 1L;
\r
32 Chart<Duration, Pressure> pressure;
\r
33 Chart<Duration, Force> thrust;
\r
34 Chart<Pressure, Velocity> burnRate;
\r
36 Amount<Duration> displayedTime = Amount.valueOf(0, SI.SECOND);
\r
38 public BurnPanel(Burn b){
\r
39 super( new BorderLayout() );
\r
43 pressure = new Chart<Duration, Pressure>(
\r
48 pressure.setDomain(burn.getData().keySet());
\r
50 thrust = new Chart<Duration, Force>(
\r
55 thrust.setDomain(burn.getData().keySet());
\r
57 burnRate = new Chart<Pressure, Velocity>(
\r
59 SI.METERS_PER_SECOND,
\r
60 burn.getMotor().getFuel(),
\r
63 burnRate.new IntervalDomain(
\r
64 Amount.valueOf(0, SI.MEGA(SI.PASCAL)),
\r
65 Amount.valueOf(11, SI.MEGA(SI.PASCAL)),
\r
70 JSplitPane tp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, thrust, pressure);
\r
71 tp.setDividerLocation(.5);
\r
72 tp.setResizeWeight(.5);
\r
74 grain = new GrainPanel(burn.getMotor().getGrain()){
\r
75 private static final long serialVersionUID = 1L;
\r
76 @Override protected void addComponents(java.awt.Component crossSection, java.awt.Component slider, java.awt.Component label, java.awt.Component area, java.awt.Component volume) {
\r
77 JSplitPane h = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, crossSection, area);
\r
78 add(h, BorderLayout.CENTER);
\r
79 h.resetToPreferredSizes();
\r
83 JSplitPane grains = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, grain, burnRate);
\r
84 grains.setDividerLocation(.5);
\r
85 grains.setResizeWeight(.5);
\r
87 JSplitPane main = new JSplitPane(JSplitPane.VERTICAL_SPLIT, grains, tp);
\r
88 Dimension minimumSize = new Dimension(800, 200);
\r
89 grains.setMinimumSize(minimumSize);
\r
90 tp.setMinimumSize(minimumSize);
\r
91 main.setDividerLocation(.5);
\r
92 main.setResizeWeight(.5);
\r
94 add( main, BorderLayout.CENTER );
\r
96 add( new SL(), BorderLayout.SOUTH);
\r
101 BurnSummary bi = new BurnSummary(burn);
\r
102 JPanel text = new JPanel(new GridLayout(2, 5));
\r
104 text.add(new JLabel("Rating"));
\r
105 text.add(new JLabel("Total Impulse"));
\r
106 text.add(new JLabel("ISP"));
\r
107 text.add(new JLabel("Max Thrust"));
\r
108 text.add(new JLabel("Average Thust"));
\r
109 text.add(new JLabel("Max Pressure"));
\r
111 text.add(new JLabel(bi.getRating()));
\r
112 text.add(new JLabel(RocketScience.ammountToRoundedString(bi.totalImpulse())));
\r
113 text.add(new JLabel(RocketScience.ammountToRoundedString(bi.specificImpulse())));
\r
114 text.add(new JLabel(RocketScience
\r
115 .ammountToRoundedString(bi.maxThrust())));
\r
116 text.add(new JLabel(RocketScience
\r
117 .ammountToRoundedString(bi.averageThrust())));
\r
118 text.add(new JLabel(RocketScience
\r
119 .ammountToRoundedString(bi.maxPressure())));
\r
121 add(text, BorderLayout.NORTH);
\r
123 thrust.addRangeMarker(bi.maxThrust(), "Max", Color.BLACK);
\r
124 thrust.addRangeMarker(bi.averageThrust(), "Average", Color.BLACK);
\r
125 pressure.addRangeMarker(bi.maxPressure(), "Max", Color.BLACK);
\r
126 burnRate.addDomainMarker(bi.maxPressure(), "Max", Color.RED);
\r
130 } catch (NoSuchMethodException e){
\r
131 throw new Error(e);
\r
137 private class SL extends JSlider implements ChangeListener{
\r
138 private static final long serialVersionUID = 1L;
\r
139 private static final int STEPS = 80;
\r
141 addChangeListener(this);
\r
147 public void stateChanged(ChangeEvent e) {
\r
148 double t = ((SL)e.getSource()).getValue();
\r
149 displayedTime = burn.burnTime().divide(STEPS).times(t);
\r
151 //Find the nearest key in the data set
\r
152 displayedTime =burn.getData().tailMap(displayedTime).firstKey();
\r
154 NumberFormat nf = NumberFormat.getInstance();
\r
155 nf.setMaximumFractionDigits(2);
\r
157 pressure.mark(displayedTime);
\r
158 thrust.mark(displayedTime);
\r
160 grain.setDisplayedRegression(burn.getData().get(displayedTime).regression);
\r
162 burnRate.mark(burn.getData().get(displayedTime).chamberPressure);
\r
166 double r = ((SL)e.getSource()).getValue();
\r
167 displayedRegression = grain.webThickness().divide(STEPS).times(r);
\r
168 NumberFormat nf = NumberFormat.getInstance();
\r
169 nf.setMaximumFractionDigits(2);
\r
170 l.setText("Regression: " + nf.format(displayedRegression.doubleValue(SI.MILLIMETER)) + "mm");
\r
171 area.mark(displayedRegression);
\r
172 volume.mark(displayedRegression);
\r
179 public void showAsWindow(){
\r
180 JFrame f = new JFrame();
\r
181 f.setTitle(burn.getMotor().getName());
\r
182 f.setSize(1280,720);
\r
183 f.setLocation(0, 0);
\r
184 f.setContentPane(this);
\r
185 f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
\r
186 f.setVisible(true);
\r