final JLabel progress = new JLabel();\r
add(progress, BorderLayout.CENTER);\r
try {\r
- final Burn b = new Burn(motor,\r
+ final Burn b = new Burn(motor);\r
+ b.addBurnProgressListener(\r
new Burn.BurnProgressListener() {\r
@Override\r
public void setProgress(float f) {\r
}\r
}\r
});\r
+ b.burn();\r
\r
final BurnPanel bp = new BurnPanel(b);\r
SwingUtilities.invokeLater(new Thread() {\r
private static Logger log = Logger.getLogger(Burn.class);\r
protected final Motor motor;\r
\r
+ private boolean burning = false;\r
+ private boolean done = false;\r
+ \r
public interface BurnProgressListener{\r
public void setProgress(float p);\r
}\r
protected SortedMap<Amount<Duration>,Interval> data = new TreeMap<Amount<Duration>, Interval>();\r
\r
public SortedMap<Amount<Duration>,Interval> getData(){\r
+ if ( !done )\r
+ throw new IllegalStateException("Burn not complete!");\r
return data;\r
}\r
\r
}\r
\r
public Amount<Duration> burnTime(){\r
- return data.lastKey();\r
+ return getData().lastKey();\r
}\r
\r
public Burn(Motor m){\r
throw new IllegalArgumentException("Invalid Motor: " + e.getMessage());\r
}\r
motor = m;\r
- burn();\r
}\r
\r
- public Burn(Motor m, BurnProgressListener bpl){\r
- try {\r
- m.validate();\r
- } catch (ValidationException e) {\r
- throw new IllegalArgumentException("Invalid Motor: " + e.getMessage());\r
- }\r
- motor = m;\r
+ public void addBurnProgressListener( BurnProgressListener bpl ){\r
bpls.add(bpl);\r
- burn();\r
}\r
\r
- private void burn(){\r
+ public void burn(){\r
+ synchronized(this){\r
+ if ( burning )\r
+ throw new IllegalStateException("Already burning!");\r
+ burning = true;\r
+ }\r
log.info("Starting burn...");\r
int endPressureSteps = 0;\r
long start = new Date().getTime();\r
\r
long time = new Date().getTime() - start;\r
log.info("Burn took " + time + " millis.");\r
+ done = true;\r
}\r
\r
@SuppressWarnings("unchecked")\r
}\r
\r
public Amount<Pressure> pressure(Amount<Duration> time){\r
- return data.get(time).chamberPressure;\r
+ return getData().get(time).chamberPressure;\r
}\r
\r
public Amount<Force> thrust(Amount<Duration> time){\r
- return data.get(time).thrust;\r
+ return getData().get(time).thrust;\r
}\r
\r
public Amount<Dimensionless> kn(Amount<Length> regression){\r