Made burn ctor not start burn.
authorBill Kuker <bkuker@billkuker.com>
Sun, 7 Nov 2010 16:07:54 +0000 (16:07 +0000)
committerBill Kuker <bkuker@billkuker.com>
Sun, 7 Nov 2010 16:07:54 +0000 (16:07 +0000)
Add addBurnProgressListener() to burn
fixed editor to creat burn then start it.

gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorEditor.java
src/com/billkuker/rocketry/motorsim/Burn.java

index 2c863e62b99fbcc1e707c8553501f2b37dc7711c..32a876458d4d0099663f174278dc9104b00234bb 100644 (file)
@@ -156,7 +156,8 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener {
                                        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
@@ -171,6 +172,7 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener {
                                                                                }\r
                                                                        }\r
                                                                });\r
+                                               b.burn();\r
 \r
                                                final BurnPanel bp = new BurnPanel(b);\r
                                                SwingUtilities.invokeLater(new Thread() {\r
index d863cd9db5a207a2be1995ecfd76e8f3ccb2eb21..0923394f68b4d3805d266833edeb62424ddb6ee1 100644 (file)
@@ -40,6 +40,9 @@ public class Burn {
        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
@@ -64,6 +67,8 @@ public class Burn {
        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
@@ -72,7 +77,7 @@ public class Burn {
        }\r
 \r
        public Amount<Duration> burnTime(){\r
-               return data.lastKey();\r
+               return getData().lastKey();\r
        }\r
        \r
        public Burn(Motor m){\r
@@ -82,21 +87,18 @@ public class Burn {
                        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
@@ -238,6 +240,7 @@ public class Burn {
 \r
                long time = new Date().getTime() - start;\r
                log.info("Burn took " + time + " millis.");\r
+               done = true;\r
        }\r
        \r
        @SuppressWarnings("unchecked")\r
@@ -252,11 +255,11 @@ public class Burn {
        }\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