import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup;
+import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.ChangeSource;
import net.sf.openrocket.util.MathUtil;
+import net.sf.openrocket.util.Reflection;
/**
public class DoubleModel implements ChangeListener, ChangeSource {
private static final boolean DEBUG_LISTENERS = false;
+
+ public static final DoubleModel ZERO = new DoubleModel(0);
//////////// JSpinner Model ////////////
}
// Implement a wrapper to the ChangeListeners
- ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+ ArrayList<PropertyChangeListener> propertyChangeListeners =
+ new ArrayList<PropertyChangeListener>();
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
- listeners.add(listener);
+ propertyChangeListeners.add(listener);
DoubleModel.this.addChangeListener(this);
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
- listeners.remove(listener);
- if (listeners.isEmpty())
+ propertyChangeListeners.remove(listener);
+ if (propertyChangeListeners.isEmpty())
DoubleModel.this.removeChangeListener(this);
}
// If the value has changed, generate an event to the listeners
PropertyChangeEvent event = new PropertyChangeEvent(this,Action.SELECTED_KEY,
oldValue,newValue);
oldValue = newValue;
- Object[] l = listeners.toArray();
+ Object[] l = propertyChangeListeners.toArray();
for (int i=0; i<l.length; i++) {
((PropertyChangeListener)l[i]).propertyChange(event);
}
try {
return (Double)getMethod.invoke(source)*multiplier;
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new BugException("BUG: Unable to invoke getMethod of "+this, e);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new BugException("BUG: Unable to invoke getMethod of "+this, e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw Reflection.handleInvocationTargetException(e);
}
- return lastValue; // Should not occur
}
/**
try {
setMethod.invoke(source, v/multiplier);
- return;
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new BugException("BUG: Unable to invoke setMethod of "+this, e);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new BugException("BUG: Unable to invoke setMethod of "+this, e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw Reflection.handleInvocationTargetException(e);
}
- fireStateChanged(); // Should not occur
}
try {
return (Boolean)getAutoMethod.invoke(source);
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new BugException("Method call failed", e);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new BugException("Method call failed", e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw Reflection.handleInvocationTargetException(e);
}
- return false; // Should not occur
}
/**
return;
}
+ lastAutomatic = auto;
try {
- lastAutomatic = auto;
setAutoMethod.invoke(source, auto);
- return;
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new BugException(e);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new BugException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw Reflection.handleInvocationTargetException(e);
}
- fireStateChanged(); // Should not occur
}
/**
- * Add a listener to the model. Adds the model as a listener to the Component if this
+ * Add a listener to the model. Adds the model as a listener to the value source if this
* is the first listener.
* @param l Listener to add.
*/