-<?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>
-<?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>
--- /dev/null
+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);
+ }
+}
\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
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
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
}\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
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
}\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
}\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
}\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
}\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
}\r
\r
public void setName(String name) {\r
- String old = this.name;\r
this.name = name;\r
- firePropertyChange("Name", old, name);\r
}\r
}\r
+++ /dev/null
-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
--- /dev/null
+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);
+ }
+}
\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
\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
\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
}\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
throw new ValidationException(this, "No exposed grain surface");\r
\r
}\r
+ */\r
\r
public Amount<Length> webThickness() {\r
if ( innerSurfaceInhibited && outerSurfaceInhibited ){\r
\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
\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
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
}\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
}\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
}\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
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
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
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
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
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
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
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
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
\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
}\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
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
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
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
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
g.setID(Amount.valueOf(30, SI.MILLIMETER));\r
\r
g.checkValidity();\r
- }\r
+ }*/\r
\r
}\r
\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
\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
\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
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
\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
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
}\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
}\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
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
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
\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
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
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 {
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);
}
}
}
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);
}
}