Changed propertylistening and quantitychecking to aspects
authorBill Kuker <bkuker@billkuker.com>
Fri, 7 Aug 2009 00:00:18 +0000 (00:00 +0000)
committerBill Kuker <bkuker@billkuker.com>
Fri, 7 Aug 2009 00:00:18 +0000 (00:00 +0000)
19 files changed:
.classpath
.project
src/com/billkuker/rocketry/motorsim/ChangeListening.aj [new file with mode: 0644]
src/com/billkuker/rocketry/motorsim/ConvergentDivergentNozzle.java
src/com/billkuker/rocketry/motorsim/Motor.java
src/com/billkuker/rocketry/motorsim/MotorPart.java [deleted file]
src/com/billkuker/rocketry/motorsim/QuantityChecking.aj [new file with mode: 0644]
src/com/billkuker/rocketry/motorsim/grain/CompoundGrain.java
src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java
src/com/billkuker/rocketry/motorsim/grain/ExtrudedGrain.java
src/com/billkuker/rocketry/motorsim/grain/Finocyl.java
src/com/billkuker/rocketry/motorsim/grain/Moonburner.java
src/com/billkuker/rocketry/motorsim/grain/MultiGrain.java
src/com/billkuker/rocketry/motorsim/io/MotorIO.java
src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java
src/com/billkuker/rocketry/motorsim/visual/GrainPanel.java
src/com/billkuker/rocketry/motorsim/visual/NozzlePanel.java
src/com/billkuker/rocketry/motorsim/visual/workbench/MotorEditor.java
src/com/billkuker/rocketry/motorsim/visual/workbench/WorkbenchTreeModel.java

index 189b53bd88d0f6455727bde3aea3fc3ca022416d..51967f3af9a7f36c78321736e0c0c72c9bc74deb 100644 (file)
@@ -1,15 +1,16 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
-       <classpathentry kind="src" path="src"/>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
-       <classpathentry kind="lib" path="jscience.jar"/>\r
-       <classpathentry kind="lib" path="jfreechart-1.0.12.jar"/>\r
-       <classpathentry kind="lib" path="jcommon-1.0.15.jar"/>\r
-       <classpathentry kind="lib" path="log4j-1.2.15.jar"/>\r
-       <classpathentry kind="lib" path="l2fprod-common-sheet.jar"/>\r
-       <classpathentry kind="lib" path="xstream-1.3.jar"/>\r
-       <classpathentry kind="lib" path="xpp3_min-1.1.4c.jar"/>\r
-       <classpathentry kind="lib" path="rsyntaxtextarea.jar"/>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>\r
-       <classpathentry kind="output" path="bin"/>\r
-</classpath>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="lib" path="jscience.jar"/>
+       <classpathentry kind="lib" path="jfreechart-1.0.12.jar"/>
+       <classpathentry kind="lib" path="jcommon-1.0.15.jar"/>
+       <classpathentry kind="lib" path="log4j-1.2.15.jar"/>
+       <classpathentry kind="lib" path="l2fprod-common-sheet.jar"/>
+       <classpathentry kind="lib" path="xstream-1.3.jar"/>
+       <classpathentry kind="lib" path="xpp3_min-1.1.4c.jar"/>
+       <classpathentry kind="lib" path="rsyntaxtextarea.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+       <classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
index 5fc6d6fee59ca3308c9a340c8f535e9cf59f2a70..311ced974ae48dd6fef48d72cc97c9b8e34617ad 100644 (file)
--- a/.project
+++ b/.project
@@ -1,17 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<projectDescription>\r
-       <name>MotorSim</name>\r
-       <comment></comment>\r
-       <projects>\r
-       </projects>\r
-       <buildSpec>\r
-               <buildCommand>\r
-                       <name>org.eclipse.jdt.core.javabuilder</name>\r
-                       <arguments>\r
-                       </arguments>\r
-               </buildCommand>\r
-       </buildSpec>\r
-       <natures>\r
-               <nature>org.eclipse.jdt.core.javanature</nature>\r
-       </natures>\r
-</projectDescription>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>MotorSim</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.ajdt.core.ajbuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.ajdt.ui.ajnature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/src/com/billkuker/rocketry/motorsim/ChangeListening.aj b/src/com/billkuker/rocketry/motorsim/ChangeListening.aj
new file mode 100644 (file)
index 0000000..86fc38e
--- /dev/null
@@ -0,0 +1,63 @@
+package com.billkuker.rocketry.motorsim;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Method;
+
+import javax.swing.event.ChangeListener;
+
+import com.billkuker.rocketry.motorsim.grain.MultiGrain;
+
+public aspect ChangeListening {
+
+       public interface Subject {
+               // public void addPropertyChangeListener(PropertyChangeListener l);
+       }
+
+       private PropertyChangeSupport Subject.pcs;
+
+       public void Subject.addPropertyChangeListener(PropertyChangeListener l) {
+               //System.out.println("PCS Added");
+               pcs.addPropertyChangeListener(l);
+       }
+       
+       public void Subject.removePropertyChangeListener(PropertyChangeListener l) {
+               //System.out.println("PCS Removed");
+               pcs.addPropertyChangeListener(l);
+       }
+       
+       public void Subject.firePropertyChange(PropertyChangeEvent e) {
+               pcs.firePropertyChange(e);
+       }
+
+       declare parents: Motor || Grain || Chamber || Nozzle || Fuel implements Subject;
+
+       void around(Subject s, Object newVal):
+               execution(void Subject+.set*(..)) && target(s) && args(newVal) {
+               System.out.println(s);
+               String name = thisJoinPointStaticPart.getSignature().getName();
+               name = name.replaceFirst("set", "");
+               Object old = null;
+               try {
+                       String pre = "get";
+                       if (newVal instanceof Boolean)
+                               pre = "is";
+                       Method m = s.getClass().getMethod(pre + name);
+                       old = m.invoke(s);
+
+               } catch (Throwable t) {
+                       System.err.print("Error getting old value for " + name);
+               }
+               proceed(s, newVal);
+               if (old != newVal) {
+                       System.out.println(name + " changed from " + old + " to "
+                                       + newVal);
+                       s.pcs.firePropertyChange(name, old, newVal);
+               }
+       }
+
+       after(Subject s) returning: this(s) && initialization(Subject.new(..)) {
+               s.pcs = new PropertyChangeSupport(s);
+       }
+}
index 8ce520f15918226b33ba244a18dfa238b388f33e..16100312d46438fa457a1f8c7e08e0b5770f37ad 100644 (file)
@@ -14,7 +14,7 @@ import javax.measure.unit.SI;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
-public class ConvergentDivergentNozzle extends MotorPart implements Nozzle {\r
+public class ConvergentDivergentNozzle implements Nozzle {\r
 \r
        private Amount<Length> throatDiameter;\r
        \r
@@ -40,9 +40,7 @@ public class ConvergentDivergentNozzle extends MotorPart implements Nozzle {
        public void setThroatDiameter(Amount<Length> throatDiameter) {\r
                if ( exitDiameter != null && throatDiameter.isGreaterThan(exitDiameter))\r
                        throw new IllegalArgumentException("Throat > Exit");\r
-               Amount<Length> old = this.throatDiameter;\r
                this.throatDiameter = throatDiameter;\r
-               firePropertyChange("throatDiameter", old, throatDiameter);\r
        }\r
        \r
 \r
@@ -54,9 +52,7 @@ public class ConvergentDivergentNozzle extends MotorPart implements Nozzle {
        public void setExitDiameter(Amount<Length> exitDiameter) {\r
                if ( throatDiameter != null && exitDiameter.isLessThan(throatDiameter))\r
                        throw new IllegalArgumentException("Throat > Exit");\r
-               Amount<Length> old = this.exitDiameter;\r
                this.exitDiameter = exitDiameter;\r
-               firePropertyChange("exitDiameter", old, exitDiameter);\r
        }\r
        \r
        public Amount<Force> thrust(Amount<Pressure> Po, Amount<Pressure> Pe, Amount<Pressure> Patm, final double k ){\r
@@ -87,9 +83,7 @@ public class ConvergentDivergentNozzle extends MotorPart implements Nozzle {
        }\r
 \r
        public void setEfficiency(double efficiency) {\r
-               double old = this.efficiency;\r
                this.efficiency = efficiency;\r
-               firePropertyChange("efficiency", old, efficiency);\r
        }\r
 \r
        public Shape nozzleShape(Amount<Length> chamberDiameter){\r
index a26b0b3e4808a61e34f0a08b7e6389d1e2335090..267135130ddbbc9710105e3894f62e3945d30403 100644 (file)
@@ -1,6 +1,6 @@
 package com.billkuker.rocketry.motorsim;\r
 \r
-public class Motor extends MotorPart{\r
+public class Motor {\r
        private Chamber chamber;\r
        private Grain grain;\r
        private Nozzle nozzle;\r
@@ -13,9 +13,7 @@ public class Motor extends MotorPart{
        }\r
        \r
        public void setChamber(Chamber chamber) {\r
-               Chamber old = this.chamber;\r
                this.chamber = chamber;\r
-               firePropertyChange("Chamber", old, chamber);\r
        }\r
        \r
        public Grain getGrain() {\r
@@ -23,9 +21,7 @@ public class Motor extends MotorPart{
        }\r
        \r
        public void setGrain(Grain grain) {\r
-               Grain old = this.grain;\r
                this.grain = grain;\r
-               firePropertyChange("Grain", old, grain);\r
        }\r
        \r
        public Nozzle getNozzle() {\r
@@ -33,9 +29,7 @@ public class Motor extends MotorPart{
        }\r
        \r
        public void setNozzle(Nozzle nozzle) {\r
-               Nozzle old = this.nozzle;\r
                this.nozzle = nozzle;\r
-               firePropertyChange("Nozzle", old, nozzle);\r
        }\r
 \r
        public Fuel getFuel() {\r
@@ -43,9 +37,7 @@ public class Motor extends MotorPart{
        }\r
 \r
        public void setFuel(Fuel fuel) {\r
-               Fuel old = this.fuel;\r
                this.fuel = fuel;\r
-               firePropertyChange("Fuel", old, fuel);\r
        }\r
 \r
        public String getName() {\r
@@ -53,8 +45,6 @@ public class Motor extends MotorPart{
        }\r
 \r
        public void setName(String name) {\r
-               String old = this.name;\r
                this.name = name;\r
-               firePropertyChange("Name", old, name);\r
        }\r
 }\r
diff --git a/src/com/billkuker/rocketry/motorsim/MotorPart.java b/src/com/billkuker/rocketry/motorsim/MotorPart.java
deleted file mode 100644 (file)
index eeded4d..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.billkuker.rocketry.motorsim;\r
-\r
-import java.beans.BeanInfo;\r
-import java.beans.Introspector;\r
-import java.beans.PropertyChangeEvent;\r
-import java.beans.PropertyChangeListener;\r
-import java.beans.PropertyChangeSupport;\r
-import java.beans.PropertyDescriptor;\r
-import java.beans.PropertyVetoException;\r
-import java.beans.VetoableChangeListener;\r
-import java.beans.VetoableChangeSupport;\r
-import java.lang.reflect.Field;\r
-import java.lang.reflect.ParameterizedType;\r
-import java.lang.reflect.Type;\r
-\r
-import javax.measure.unit.Unit;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.jscience.physics.amount.Amount;\r
-\r
-public class MotorPart {\r
-       PropertyChangeSupport pcs;\r
-       VetoableChangeSupport vcs;\r
-       \r
-       private static Logger log = Logger.getLogger(MotorPart.class);\r
-       \r
-       public interface Validating {\r
-                void checkValidity() throws ValidationException;\r
-                \r
-                public class ValidationException extends Exception {\r
-                               private static final long serialVersionUID = 1L;\r
-                               public ValidationException(Validating v, String error) {\r
-                                       super(v.toString() + ": " + error);\r
-                               }\r
-                       }\r
-       }\r
-       \r
-       public MotorPart() {\r
-               pcs = new PropertyChangeSupport(this);\r
-               vcs = new VetoableChangeSupport(this);\r
-               \r
-               vcs.addVetoableChangeListener(new VetoableChangeListener(){\r
-                       @SuppressWarnings("unchecked")\r
-                       public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {\r
-                               if ( evt.getNewValue() instanceof Amount ){\r
-                                       try {\r
-                                               BeanInfo b = Introspector.getBeanInfo(evt.getSource().getClass());\r
-                                               PropertyDescriptor ps[] = b.getPropertyDescriptors();\r
-                                               for ( int i = 0; i < ps.length; i++ ){\r
-                                                       if (ps[i].getName().equals(evt.getPropertyName())){\r
-                                                               Type t = ps[i].getReadMethod().getGenericReturnType();\r
-                                                               ParameterizedType p = (ParameterizedType) t;\r
-                                                               Class expected = (Class)p.getActualTypeArguments()[0];\r
-                                                               Field f = expected.getDeclaredField("UNIT");\r
-                                                               Unit u = (Unit) f.get(null);\r
-                                                               \r
-                                                               Amount a = (Amount)evt.getNewValue();\r
-                                                               if (!a.getUnit().isCompatible(u))\r
-                                                                       throw new PropertyVetoException(ps[i].getShortDescription()\r
-                                                                                       + " must be in units of "\r
-                                                                                       + expected.getSimpleName(), evt);\r
-       \r
-                                                               log.debug("Expected " + expected + " got " + u);\r
-                                                       }\r
-                                               }\r
-                                       } catch ( PropertyVetoException e ){\r
-                                               throw e;\r
-                                       } catch (Exception e) {\r
-                                               e.printStackTrace();\r
-                                       }\r
-                               }\r
-                       }\r
-               });\r
-       }\r
-\r
-       public void addPropertyChangeListener(PropertyChangeListener listener) {\r
-               pcs.addPropertyChangeListener(listener);\r
-       }\r
-\r
-       public void removePropertyChangeListener(PropertyChangeListener listener) {\r
-               pcs.removePropertyChangeListener(listener);\r
-       }\r
-\r
-       protected void firePropertyChange(PropertyChangeEvent evt) {\r
-               pcs.firePropertyChange(evt);\r
-       }\r
-\r
-       protected void firePropertyChange(String propertyName, boolean oldValue,\r
-                       boolean newValue) {\r
-               pcs.firePropertyChange(propertyName, oldValue, newValue);\r
-       }\r
-\r
-       protected void firePropertyChange(String propertyName, int oldValue,\r
-                       int newValue) {\r
-               pcs.firePropertyChange(propertyName, oldValue, newValue);\r
-       }\r
-\r
-       protected void firePropertyChange(String propertyName, Object oldValue,\r
-                       Object newValue) {\r
-               pcs.firePropertyChange(propertyName, oldValue, newValue);\r
-       }\r
-\r
-       public void fireVetoableChange(String arg0, boolean arg1, boolean arg2)\r
-                       throws PropertyVetoException {\r
-               vcs.fireVetoableChange(arg0, arg1, arg2);\r
-       }\r
-\r
-       public void fireVetoableChange(String arg0, int arg1, int arg2)\r
-                       throws PropertyVetoException {\r
-               vcs.fireVetoableChange(arg0, arg1, arg2);\r
-       }\r
-\r
-       public void fireVetoableChange(String arg0, Object arg1, Object arg2)\r
-                       throws PropertyVetoException {\r
-               vcs.fireVetoableChange(arg0, arg1, arg2);\r
-       }\r
-}\r
diff --git a/src/com/billkuker/rocketry/motorsim/QuantityChecking.aj b/src/com/billkuker/rocketry/motorsim/QuantityChecking.aj
new file mode 100644 (file)
index 0000000..544de37
--- /dev/null
@@ -0,0 +1,57 @@
+package com.billkuker.rocketry.motorsim;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.beans.PropertyVetoException;
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import javax.measure.unit.Unit;
+
+import org.jscience.physics.amount.Amount;
+import com.billkuker.rocketry.motorsim.ChangeListening.Subject;
+import com.billkuker.rocketry.motorsim.grain.CoredCylindricalGrain;
+
+public aspect QuantityChecking {
+
+       public interface Checked {
+       };
+
+       declare parents: Motor || Grain || Chamber || Nozzle || Fuel extends Checked;
+
+       void around(Checked c, Amount amt):
+               execution(void Checked+.set*(Amount)) && target(c) && args(amt) {
+               System.out.println(thisJoinPointStaticPart.getSignature().getName()
+                               + " set to " + amt);
+               try {
+                       BeanInfo b = Introspector.getBeanInfo(c.getClass());
+                       PropertyDescriptor ps[] = b.getPropertyDescriptors();
+                       String name = thisJoinPointStaticPart.getSignature().getName();
+                       name = name.replaceFirst("set", "");
+                       for (int i = 0; i < ps.length; i++) {
+                               if (ps[i].getName().equals(name)) {
+                                       Type t = ps[i].getReadMethod().getGenericReturnType();
+                                       ParameterizedType p = (ParameterizedType) t;
+                                       Class expected = (Class) p.getActualTypeArguments()[0];
+                                       Field f = expected.getDeclaredField("UNIT");
+                                       Unit u = (Unit) f.get(null);
+
+                                       Amount a = amt;
+                                       if (!a.getUnit().isCompatible(u)) {
+                                               System.err.println("Aspect Expected " + expected
+                                                               + " got " + u);
+
+                                               throw new Error(ps[i].getShortDescription()
+                                                               + " must be in units of "
+                                                               + expected.getSimpleName());
+                                       }
+                               }
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               proceed(c, amt);
+       }
+}
index ee1ac618b9397ab45ea8982636780ee65949870d..539beb7a2071162261969133e1383d6ad98dece5 100644 (file)
@@ -11,10 +11,10 @@ import javax.measure.unit.SI;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
+import com.billkuker.rocketry.motorsim.ChangeListening;\r
 import com.billkuker.rocketry.motorsim.Grain;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 \r
-public class CompoundGrain extends MotorPart implements Grain {\r
+public class CompoundGrain implements Grain {\r
        \r
        private Set<Grain> grains = new HashSet<Grain>();\r
        \r
@@ -28,14 +28,14 @@ public class CompoundGrain extends MotorPart implements Grain {
        \r
        public void addPropertyChangeListener(PropertyChangeListener listener) {\r
                for ( Grain g : grains )\r
-                       if ( g instanceof MotorPart )\r
-                               ((MotorPart)g).addPropertyChangeListener(listener);\r
+                       if ( g instanceof ChangeListening.Subject )\r
+                               ((ChangeListening.Subject)g).addPropertyChangeListener(listener);\r
        }\r
 \r
        public void removePropertyChangeListener(PropertyChangeListener listener) {\r
                for ( Grain g : grains )\r
-                       if ( g instanceof MotorPart )\r
-                               ((MotorPart)g).removePropertyChangeListener(listener);\r
+                       if ( g instanceof ChangeListening.Subject )\r
+                               ((ChangeListening.Subject)g).removePropertyChangeListener(listener);\r
        }\r
 \r
        public Area getCrossSection(Amount<Length> regression) {\r
index a505ef277a7cb28ea68b436f1deb2eb99de72a85..6071d8a24e073f44f9ef8a279a73c1fecd52de28 100644 (file)
@@ -12,12 +12,11 @@ import javax.measure.unit.SI;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.billkuker.rocketry.motorsim.visual.Editor;\r
 import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
 \r
 \r
-public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Validating {\r
+public class CoredCylindricalGrain extends ExtrudedGrain {\r
 \r
        private Amount<Length> oD, iD;\r
        private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false;\r
@@ -122,19 +121,14 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
        }\r
 \r
        public void setOD(Amount<Length> od) throws PropertyVetoException {\r
-               fireVetoableChange("od", this.oD, od);\r
-               Amount<Length> old = this.oD;\r
                this.oD = od;\r
-               firePropertyChange("OD", old, oD);\r
        }\r
 \r
        public void setID(Amount<Length> id) throws PropertyVetoException {\r
-               fireVetoableChange("id", this.iD, id);\r
-               Amount<Length> old = this.iD;\r
                iD = id;\r
-               firePropertyChange("ID", old, iD);\r
        }\r
        \r
+       /*\r
        public void checkValidity() throws ValidationException{\r
                if ( iD.equals(Amount.ZERO) )\r
                        throw new ValidationException(this, "Invalid iD");\r
@@ -149,6 +143,7 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
                        throw new ValidationException(this, "No exposed grain surface");\r
                \r
        }\r
+       */\r
 \r
        public Amount<Length> webThickness() {\r
                if ( innerSurfaceInhibited && outerSurfaceInhibited ){\r
@@ -240,10 +235,7 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
 \r
 \r
        public void setOuterSurfaceInhibited(boolean outerSurfaceInhibited) throws PropertyVetoException {\r
-               fireVetoableChange("outerSurfaceInhibited", this.outerSurfaceInhibited, outerSurfaceInhibited);\r
-               boolean old = this.outerSurfaceInhibited;\r
                this.outerSurfaceInhibited = outerSurfaceInhibited;\r
-               firePropertyChange("outerSurfaceInhibited", old, outerSurfaceInhibited);\r
        }\r
 \r
 \r
@@ -253,10 +245,7 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va
 \r
 \r
        public void setInnerSurfaceInhibited(boolean innerSurfaceInhibited)  throws PropertyVetoException {\r
-               fireVetoableChange("innerSurfaceInhibited", this.innerSurfaceInhibited, innerSurfaceInhibited);\r
-               boolean old = this.innerSurfaceInhibited;\r
                this.innerSurfaceInhibited = innerSurfaceInhibited;\r
-               firePropertyChange("innerSurfaceInhibited", old, innerSurfaceInhibited);\r
        }\r
 \r
        public static void main(String args[]) throws Exception {\r
index fb5bd5b627eaead3332e07470effad3a2342c174..2ce5e0b6d7547818c29bb1b5be75e55ff3f54f2a 100644 (file)
@@ -8,9 +8,8 @@ import javax.measure.unit.SI;
 import org.jscience.physics.amount.Amount;\r
 \r
 import com.billkuker.rocketry.motorsim.Grain;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 \r
-public abstract class ExtrudedGrain extends MotorPart implements Grain {\r
+public abstract class ExtrudedGrain implements Grain {\r
        private boolean foreEndInhibited = false;\r
        private boolean aftEndInhibited = false;\r
        private Amount<Length> length = Amount.valueOf(100, SI.MILLIMETER);\r
@@ -33,10 +32,7 @@ public abstract class ExtrudedGrain extends MotorPart implements Grain {
        }\r
 \r
        public void setForeEndInhibited(boolean foreEndInhibited)throws PropertyVetoException {\r
-               fireVetoableChange("foreEndInhibited", this.foreEndInhibited, foreEndInhibited);\r
-               boolean old = this.foreEndInhibited;\r
                this.foreEndInhibited = foreEndInhibited;\r
-               firePropertyChange("foreEndInhibited", old, foreEndInhibited);\r
        }\r
 \r
        public boolean isAftEndInhibited() {\r
@@ -44,10 +40,7 @@ public abstract class ExtrudedGrain extends MotorPart implements Grain {
        }\r
 \r
        public void setAftEndInhibited(boolean aftEndInhibited) throws PropertyVetoException {\r
-               fireVetoableChange("aftEndInhibited", this.aftEndInhibited, aftEndInhibited);\r
-               boolean old = this.aftEndInhibited;\r
                this.aftEndInhibited = aftEndInhibited;\r
-               firePropertyChange("aftEndInhibited", old, aftEndInhibited);\r
        }\r
 \r
        public Amount<Length> getLength() {\r
@@ -55,9 +48,6 @@ public abstract class ExtrudedGrain extends MotorPart implements Grain {
        }\r
 \r
        public void setLength(Amount<Length> length) throws PropertyVetoException {\r
-               fireVetoableChange("length", this.length, length);\r
-               Amount<Length> old = this.length;\r
                this.length = length;\r
-               firePropertyChange("length", old, length);\r
        }\r
 }\r
index b2295c7580ab23aa7dfeeb005a56332754b1d6e3..140556274dab0648460acd34ef99c170760bdba7 100644 (file)
@@ -58,11 +58,8 @@ public class Finocyl extends ExtrudedShapeGrain {
        public void setOD(Amount<Length> od) throws PropertyVetoException {\r
                if (od.equals(this.oD))\r
                        return;\r
-               fireVetoableChange("od", this.oD, od);\r
-               Amount<Length> old = this.oD;\r
                this.oD = od;\r
                generateGeometry();\r
-               firePropertyChange("OD", old, oD);\r
        }\r
 \r
        public Amount<Length> getID() {\r
@@ -72,11 +69,8 @@ public class Finocyl extends ExtrudedShapeGrain {
        public void setID(Amount<Length> id) throws PropertyVetoException {\r
                if (id.equals(this.iD))\r
                        return;\r
-               fireVetoableChange("id", this.iD, id);\r
-               Amount<Length> old = this.iD;\r
                iD = id;\r
                generateGeometry();\r
-               firePropertyChange("ID", old, iD);\r
        }\r
        \r
        public Amount<Length> getFinWidth() {\r
@@ -86,11 +80,8 @@ public class Finocyl extends ExtrudedShapeGrain {
        public void setFinWidth(Amount<Length> finWidth) throws PropertyVetoException {\r
                if (finWidth.equals(this.finWidth))\r
                        return;\r
-               fireVetoableChange("finWidth", this.finWidth, finWidth);\r
-               Amount<Length> old = this.finWidth;\r
                this.finWidth = finWidth;\r
                generateGeometry();\r
-               firePropertyChange("finWidth", old, finWidth);\r
        }\r
        \r
        \r
@@ -101,11 +92,8 @@ public class Finocyl extends ExtrudedShapeGrain {
        public void setFinDiameter(Amount<Length> finDiameter) throws PropertyVetoException {\r
                if (finDiameter.equals(this.finDiameter))\r
                        return;\r
-               fireVetoableChange("finDiameter", this.finDiameter, finDiameter);\r
-               Amount<Length> old = this.finDiameter;\r
                this.finDiameter = finDiameter;\r
                generateGeometry();\r
-               firePropertyChange("finDiameter", old, finDiameter);\r
        }\r
        \r
        \r
@@ -116,11 +104,8 @@ public class Finocyl extends ExtrudedShapeGrain {
        public void setFinCount(int finCount) throws PropertyVetoException {\r
                if (finCount==this.finCount)\r
                        return;\r
-               fireVetoableChange("finCount", this.finCount, finCount);\r
-               int old = this.finCount;\r
                this.finCount = finCount;\r
                generateGeometry();\r
-               firePropertyChange("finCount", old, finCount);\r
        }\r
        \r
        public static void main(String args[]) throws Exception {\r
index 66f61ab157ac6607a7f8b533ebacf502efe767d9..5a56c951a5c58064b6e3f2efafcafa6722534a06 100644 (file)
@@ -36,11 +36,8 @@ public class Moonburner extends ExtrudedShapeGrain {
        public void setOD(Amount<Length> od) throws PropertyVetoException {\r
                if (od.equals(this.oD))\r
                        return;\r
-               fireVetoableChange("od", this.oD, od);\r
-               Amount<Length> old = this.oD;\r
                this.oD = od;\r
                generateGeometry();\r
-               firePropertyChange("OD", old, oD);\r
        }\r
 \r
        public Amount<Length> getID() {\r
@@ -50,11 +47,8 @@ public class Moonburner extends ExtrudedShapeGrain {
        public void setID(Amount<Length> id) throws PropertyVetoException {\r
                if (id.equals(this.iD))\r
                        return;\r
-               fireVetoableChange("id", this.iD, id);\r
-               Amount<Length> old = this.iD;\r
                iD = id;\r
                generateGeometry();\r
-               firePropertyChange("ID", old, iD);\r
        }\r
 \r
        public Amount<Length> getCoreOffset() {\r
@@ -65,11 +59,8 @@ public class Moonburner extends ExtrudedShapeGrain {
                        throws PropertyVetoException {\r
                if (coreOffset.equals(this.coreOffset))\r
                        return;\r
-               fireVetoableChange("coreOffset", this.coreOffset, coreOffset);\r
-               Amount<Length> old = this.coreOffset;\r
                this.coreOffset = coreOffset;\r
                generateGeometry();\r
-               firePropertyChange("coreOffset", old, this.coreOffset);\r
        }\r
 \r
        private void generateGeometry() {\r
index c35ec7b8865541deaa5a93709785cb0f50d24a5f..ad04b094af7558fb064706782a9ae2a48cb575c7 100644 (file)
@@ -15,10 +15,10 @@ import javax.measure.unit.SI;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
+import com.billkuker.rocketry.motorsim.ChangeListening;\r
 import com.billkuker.rocketry.motorsim.Grain;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 \r
-public class MultiGrain extends MotorPart implements Grain, Grain.Composite, PropertyChangeListener {\r
+public class MultiGrain implements Grain, Grain.Composite, PropertyChangeListener {\r
        \r
        private Grain grain = null;\r
        private int count = 1;\r
@@ -28,18 +28,17 @@ public class MultiGrain extends MotorPart implements Grain, Grain.Composite, Pro
        }\r
 \r
        public void setCount(int count) {\r
-               int old = this.count;\r
                this.count = count;\r
-               firePropertyChange("Count", old, count );\r
        }\r
        \r
        public void setGrain(Grain g){\r
-               Grain old = grain;\r
+               if ( grain instanceof ChangeListening.Subject ){\r
+                       ((ChangeListening.Subject)grain).addPropertyChangeListener(this);\r
+               }\r
                grain = g;\r
-               if ( g instanceof MotorPart ){\r
-                       ((MotorPart)g).addPropertyChangeListener(this);\r
+               if ( g instanceof ChangeListening.Subject ){\r
+                       ((ChangeListening.Subject)g).addPropertyChangeListener(this);\r
                }\r
-               firePropertyChange("Grain", old, grain);\r
        }\r
        \r
        public Grain getGrain(){\r
index 572ad7b992d5501ab4dfad24dbf411531c6aa952..594b36546a9d2a5ab3f7bbf585297ed87c48f44f 100644 (file)
@@ -12,7 +12,6 @@ import java.io.StringWriter;
 import org.jscience.physics.amount.Amount;\r
 \r
 import com.billkuker.rocketry.motorsim.Motor;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.thoughtworks.xstream.XStream;\r
 import com.thoughtworks.xstream.converters.Converter;\r
 import com.thoughtworks.xstream.converters.MarshallingContext;\r
@@ -53,8 +52,6 @@ public class MotorIO {
        private static XStream getXStream(){\r
                XStream xstream = new XStream();\r
                xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);\r
-               xstream.omitField(MotorPart.class, "pcs");\r
-               xstream.omitField(MotorPart.class, "vcs");\r
                xstream.registerConverter(new AmountConverter());\r
                xstream.registerConverter(new JavaBeanConverter(xstream.getClassMapper(), "class"), -20); \r
                return xstream;\r
index 30324a09c9ea76fca8fb8802e1a69ac86624b49a..b20291e076f4dce2befb9a8399c4f50c8cb543bf 100644 (file)
@@ -9,7 +9,6 @@ import javax.measure.unit.SI;
 import org.jscience.physics.amount.Amount;\r
 import org.junit.Test;\r
 \r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.billkuker.rocketry.motorsim.grain.CoredCylindricalGrain;\r
 \r
 public class CoredCylindricalGrainTest extends RocketTest {\r
@@ -76,6 +75,7 @@ public class CoredCylindricalGrainTest extends RocketTest {
                assertApproximate(v, Amount.valueOf(7471, cubeMM), Amount.valueOf(1, cubeMM));\r
        }\r
 \r
+       /*\r
        @Test(expected=MotorPart.Validating.ValidationException.class)\r
        public void testCheckValidity() throws MotorPart.Validating.ValidationException, PropertyVetoException{\r
                CoredCylindricalGrain g = new CoredCylindricalGrain();\r
@@ -86,6 +86,6 @@ public class CoredCylindricalGrainTest extends RocketTest {
                g.setID(Amount.valueOf(30, SI.MILLIMETER));\r
                \r
                g.checkValidity();\r
-       }\r
+       }*/\r
 \r
 }\r
index bd6f9db5bc76a5461f86bd40dabc361612476f0c..35974ec0efbb4ef8a81702591036bc69e7ae4763 100644 (file)
@@ -28,8 +28,8 @@ import javax.swing.event.ChangeListener;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
+import com.billkuker.rocketry.motorsim.ChangeListening;\r
 import com.billkuker.rocketry.motorsim.Grain;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 \r
 public class GrainPanel extends JPanel {\r
        private static final long serialVersionUID = 1L;\r
@@ -45,8 +45,8 @@ public class GrainPanel extends JPanel {
 \r
                grain = g;\r
                \r
-               if ( g instanceof MotorPart ){\r
-                       ((MotorPart)g).addPropertyChangeListener(new PropertyChangeListener(){\r
+               if ( g instanceof ChangeListening.Subject ){\r
+                       ((ChangeListening.Subject)g).addPropertyChangeListener(new PropertyChangeListener(){\r
                                public void propertyChange(PropertyChangeEvent evt) {\r
                                        repaint();\r
                                        area.setDomain(area.new IntervalDomain(Amount.valueOf(0, SI.MILLIMETER), grain.webThickness()));\r
index 2dd29a30efde0735eaa458c905bb570b97d9a59f..ca88434fcd776de994e0ae1d5c9e2350a5d70eb2 100644 (file)
@@ -16,8 +16,8 @@ import javax.swing.WindowConstants;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
+import com.billkuker.rocketry.motorsim.ChangeListening;\r
 import com.billkuker.rocketry.motorsim.ConvergentDivergentNozzle;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.billkuker.rocketry.motorsim.Nozzle;\r
 \r
 public class NozzlePanel extends JPanel {\r
@@ -26,8 +26,8 @@ public class NozzlePanel extends JPanel {
        public NozzlePanel(Nozzle n){\r
                nozzle = n;\r
                \r
-               if ( n instanceof MotorPart ){\r
-                       ((MotorPart)n).addPropertyChangeListener(new PropertyChangeListener(){\r
+               if ( n instanceof ChangeListening.Subject ){\r
+                       ((ChangeListening.Subject)n).addPropertyChangeListener(new PropertyChangeListener(){\r
                                public void propertyChange(PropertyChangeEvent evt) {\r
                                        repaint();\r
                                }\r
index 88a045d09866aae127214e1b90c11dd9e164adb7..c9fdcce6dc68b486a2f1bdc188dbfd5b9d593932 100644 (file)
@@ -34,12 +34,12 @@ import org.jscience.physics.amount.Amount;
 \r
 import com.billkuker.rocketry.motorsim.Burn;\r
 import com.billkuker.rocketry.motorsim.Chamber;\r
+import com.billkuker.rocketry.motorsim.ChangeListening;\r
 import com.billkuker.rocketry.motorsim.ConvergentDivergentNozzle;\r
 import com.billkuker.rocketry.motorsim.CylindricalChamber;\r
 import com.billkuker.rocketry.motorsim.Fuel;\r
 import com.billkuker.rocketry.motorsim.Grain;\r
 import com.billkuker.rocketry.motorsim.Motor;\r
-import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.billkuker.rocketry.motorsim.Nozzle;\r
 import com.billkuker.rocketry.motorsim.fuel.EditableFuel;\r
 import com.billkuker.rocketry.motorsim.fuel.KNDX;\r
@@ -59,8 +59,7 @@ import com.billkuker.rocketry.motorsim.visual.GrainPanel;
 import com.billkuker.rocketry.motorsim.visual.NozzlePanel;\r
 import com.billkuker.rocketry.motorsim.visual.Chart.IntervalDomain;\r
 \r
-public class MotorEditor extends JTabbedPane implements PropertyChangeListener,\r
-               DocumentListener {\r
+public class MotorEditor extends JTabbedPane implements PropertyChangeListener {\r
        private static final long serialVersionUID = 1L;\r
        RSyntaxTextArea text = new RSyntaxTextArea();\r
        Motor motor;\r
@@ -161,8 +160,8 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
                                                }\r
                                        });\r
                                        p.add(new Editor(gg));\r
-                                       if (gg instanceof MotorPart) {\r
-                                               ((MotorPart) gg)\r
+                                       if (gg instanceof ChangeListening.Subject) {\r
+                                               ((ChangeListening.Subject) gg)\r
                                                                .addPropertyChangeListener(MotorEditor.this);\r
                                        }\r
                                }\r
@@ -172,8 +171,8 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
                        }\r
                        // setDividerLocation(.25);\r
                        // setResizeWeight(.25);\r
-                       if (g instanceof MotorPart) {\r
-                               ((MotorPart) g).addPropertyChangeListener(MotorEditor.this);\r
+                       if (g instanceof ChangeListening.Subject) {\r
+                               ((ChangeListening.Subject) g).addPropertyChangeListener(MotorEditor.this);\r
                        }\r
                }\r
        }\r
@@ -219,8 +218,8 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
                        setRightComponent(burnRate);\r
                        // setDividerLocation(.25);\r
                        // setResizeWeight(.25);\r
-                       if (f instanceof MotorPart) {\r
-                               ((MotorPart) f).addPropertyChangeListener(MotorEditor.this);\r
+                       if (f instanceof ChangeListening.Subject) {\r
+                               ((ChangeListening.Subject) f).addPropertyChangeListener(MotorEditor.this);\r
                        }\r
                }\r
        }\r
@@ -264,11 +263,11 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
                        parts.add(new Editor(c));\r
                        parts.add(new Editor(n));\r
 \r
-                       if (n instanceof MotorPart) {\r
-                               ((MotorPart) n).addPropertyChangeListener(MotorEditor.this);\r
+                       if (n instanceof ChangeListening.Subject) {\r
+                               ((ChangeListening.Subject) n).addPropertyChangeListener(MotorEditor.this);\r
                        }\r
-                       if (c instanceof MotorPart) {\r
-                               ((MotorPart) c).addPropertyChangeListener(MotorEditor.this);\r
+                       if (c instanceof ChangeListening.Subject) {\r
+                               ((ChangeListening.Subject) c).addPropertyChangeListener(MotorEditor.this);\r
                        }\r
                }\r
        }\r
@@ -280,8 +279,8 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
 \r
        public MotorEditor(Motor m) {\r
                super(JTabbedPane.BOTTOM);\r
-               text.getDocument().addDocumentListener(this);\r
                text.setName("XML");\r
+               text.setEditable(false);\r
                add(text, XML_TAB);\r
                setMotor(m, true);\r
        }\r
@@ -380,25 +379,4 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener,
                        bt.reBurn();\r
        }\r
 \r
-       public void changedUpdate(DocumentEvent e) {\r
-               try {\r
-                       final Motor m = MotorIO.readMotor(text.getText());\r
-                       SwingUtilities.invokeLater(new Runnable() {\r
-                               public void run() {\r
-                                       setMotor(m, false);\r
-                               }\r
-                       });\r
-                       System.out.println("Motor Updated");\r
-               } catch (Throwable e1) {\r
-                       // Leave blank, motor might be broken\r
-               }\r
-       }\r
-\r
-       public void insertUpdate(DocumentEvent e) {\r
-               // TODO Auto-generated method stub\r
-       }\r
-\r
-       public void removeUpdate(DocumentEvent e) {\r
-               // TODO Auto-generated method stub\r
-       }\r
 }\r
index 09be53d319cfc4992aff010e5eb9d4d7c29c9f71..f269f79d9ff96dbd2bf16ca56e1f30e87c3fccd7 100644 (file)
@@ -8,8 +8,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreeNode;
 
+import com.billkuker.rocketry.motorsim.ChangeListening;
 import com.billkuker.rocketry.motorsim.Motor;
-import com.billkuker.rocketry.motorsim.MotorPart;
 import com.billkuker.rocketry.motorsim.grain.MultiGrain;
 
 public class WorkbenchTreeModel extends DefaultTreeModel {
@@ -39,8 +39,8 @@ public class WorkbenchTreeModel extends DefaultTreeModel {
 
                public PartNode(Object part) {
                        super(part, false);
-                       if (part instanceof MotorPart) {
-                               ((MotorPart) part).addPropertyChangeListener(this);
+                       if (part instanceof ChangeListening.Subject) {
+                               ((ChangeListening.Subject) part).addPropertyChangeListener(this);
                        }
                }
        
@@ -68,8 +68,8 @@ public class WorkbenchTreeModel extends DefaultTreeModel {
                        }
                        add(gn);
                        add( fn = new PartNode(m.getFuel()));
-                       if (m instanceof MotorPart) {
-                               ((MotorPart) m).addPropertyChangeListener(this);
+                       if (m instanceof ChangeListening.Subject) {
+                               ((ChangeListening.Subject) m).addPropertyChangeListener(this);
                        }
                }