small internal API refinements

This commit is contained in:
Daniel_M_Williams 2015-11-25 18:02:25 -05:00
parent 08077392bd
commit 12cda5b722
4 changed files with 83 additions and 30 deletions

View File

@ -116,6 +116,17 @@ public class ComponentPreset implements Comparable<ComponentPreset>, Serializabl
ComponentPreset.OUTER_DIAMETER,
ComponentPreset.LENGTH }),
RAIL_BUTTON(new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.DESCRIPTION,
// these are optional / secondary parameters. Probably not necessary to include.
//ComponentPreset.BASE_HEIGHT,
//ComponentPreset.FLANGE_HEIGHT,
//ComponentPreset.INNER_DIAMETER,
ComponentPreset.OUTER_DIAMETER,
ComponentPreset.HEIGHT }),
STREAMER(new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
@ -167,6 +178,7 @@ public class ComponentPreset implements Comparable<ComponentPreset>, Serializabl
public final static TypedKey<String> DESCRIPTION = new TypedKey<String>("Description", String.class);
public final static TypedKey<Type> TYPE = new TypedKey<Type>("Type", Type.class);
public final static TypedKey<Double> LENGTH = new TypedKey<Double>("Length", Double.class, UnitGroup.UNITS_LENGTH);
public final static TypedKey<Double> HEIGHT = new TypedKey<Double>("Height", Double.class, UnitGroup.UNITS_LENGTH);
public final static TypedKey<Double> WIDTH = new TypedKey<Double>("Width", Double.class, UnitGroup.UNITS_LENGTH);
public final static TypedKey<Double> INNER_DIAMETER = new TypedKey<Double>("InnerDiameter", Double.class, UnitGroup.UNITS_LENGTH);
public final static TypedKey<Double> OUTER_DIAMETER = new TypedKey<Double>("OuterDiameter", Double.class, UnitGroup.UNITS_LENGTH);

View File

@ -5,41 +5,76 @@ import java.util.EventObject;
public class ComponentChangeEvent extends EventObject {
private static final long serialVersionUID = 1L;
public enum TYPE {
ERROR(0),
NON_FUNCTIONAL(1),
MASS(2),
AERODYNAMIC(4),
AERO_MASS ( AERODYNAMIC.value | MASS.value ), // 6
TREE( 8),
UNDO( 16),
MOTOR( 32),
EVENT( 64),
TEXTURE ( 128),
ALL(0xFFFFFFFF);
protected int value;
private TYPE( final int _val){
this.value = _val;
}
public boolean has( final int testValue ){
return (0 != (this.value & testValue ));
}
};
/** A change that does not affect simulation results in any way (name, color, etc.) */
public static final int NONFUNCTIONAL_CHANGE = 1;
public static final int NONFUNCTIONAL_CHANGE = TYPE.NON_FUNCTIONAL.value;
/** A change that affects the mass properties of the rocket */
public static final int MASS_CHANGE = 2;
public static final int MASS_CHANGE = TYPE.MASS.value;
/** A change that affects the aerodynamic properties of the rocket */
public static final int AERODYNAMIC_CHANGE = 4;
public static final int AERODYNAMIC_CHANGE = TYPE.AERODYNAMIC.value;
/** A change that affects the mass and aerodynamic properties of the rocket */
public static final int BOTH_CHANGE = MASS_CHANGE | AERODYNAMIC_CHANGE; // Mass & Aerodynamic
public static final int BOTH_CHANGE = TYPE.AERO_MASS.value; // Mass & Aerodynamic
/** A change that affects the rocket tree structure */
public static final int TREE_CHANGE = 8;
public static final int TREE_CHANGE = TYPE.TREE.value;
/** A change caused by undo/redo. */
public static final int UNDO_CHANGE = 16;
public static final int UNDO_CHANGE = TYPE.UNDO.value;
/** A change in the motor configurations or names */
public static final int MOTOR_CHANGE = 32;
public static final int MOTOR_CHANGE = TYPE.MOTOR.value;
/** A change that affects the events occurring during flight. */
public static final int EVENT_CHANGE = 64;
public static final int EVENT_CHANGE = TYPE.EVENT.value;
/** A change to the 3D texture assigned to a component*/
public static final int TEXTURE_CHANGE = 128;
public static final int TEXTURE_CHANGE = TYPE.TEXTURE.value;
// A bit-field that contains all possible change types.
// Will output as -1. for an explanation, see "twos-complement" representation of signed integers
public static final int ALL_CHANGE = TYPE.ALL.value;
/** A bit-field that contains all possible change types. Will output as -1 */
public static final int ALL_CHANGE = 0xFFFFFFFF; // =-1; // because int is a signed type.
private final int type;
public ComponentChangeEvent(RocketComponent component, int type) {
public ComponentChangeEvent(RocketComponent component, final int type) {
super(component);
if (type == 0) {
throw new IllegalArgumentException("no event type provided");
if (0 > type ) {
throw new IllegalArgumentException("bad event type provided");
}
this.type = type;
}
public ComponentChangeEvent(RocketComponent component, final ComponentChangeEvent.TYPE type) {
super(component);
if ((TYPE.ERROR == type)||(null== type)) {
throw new IllegalArgumentException("no event type provided");
}
this.type = type.value;
}
/**
* Return the source component of this event as specified in the constructor.
@ -49,43 +84,49 @@ public class ComponentChangeEvent extends EventObject {
return (RocketComponent) super.getSource();
}
public boolean isTextureChange() {
return (type & TEXTURE_CHANGE) != 0;
public boolean isAerodynamicChange() {
return TYPE.AERODYNAMIC.has( this.type);
}
public boolean isAerodynamicChange() {
return (type & AERODYNAMIC_CHANGE) != 0;
public boolean isEventChange() {
return TYPE.EVENT.has( this.type);
}
public boolean isFunctionalChange() {
return ! (TYPE.NON_FUNCTIONAL.has( this.type));
}
public boolean isMassChange() {
return (type & MASS_CHANGE) != 0;
return TYPE.MASS.has(this.type);
}
public boolean isOtherChange() {
return (type & BOTH_CHANGE) == 0;
public boolean isTextureChange() {
return TYPE.TEXTURE.has(this.type);
}
public boolean isTreeChange() {
return (type & TREE_CHANGE) != 0;
return TYPE.TREE.has(this.type);
}
public boolean isUndoChange() {
return (type & UNDO_CHANGE) != 0;
return TYPE.UNDO.has(this.type);
}
public boolean isMotorChange() {
return (type & MOTOR_CHANGE) != 0;
return TYPE.MASS.has(this.type);
}
public int getType() {
return type;
return this.type;
}
@Override
public String toString() {
String s = "";
if ((type & NONFUNCTIONAL_CHANGE) != 0)
if (isFunctionalChange())
s += ",nonfunc";
if (isMassChange())
s += ",mass";
@ -97,7 +138,7 @@ public class ComponentChangeEvent extends EventObject {
s += ",undo";
if (isMotorChange())
s += ",motor";
if ((type & EVENT_CHANGE) != 0)
if (isEventChange())
s += ",event";
if (s.length() > 0)

View File

@ -522,7 +522,7 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial
@Override
protected void componentChanged(ComponentChangeEvent e) {
super.componentChanged(e);
if (!e.isOtherChange()) {
if( e.isAerodynamicChange() || e.isMassChange()){
wetArea = -1;
planArea = -1;
planCenter = -1;

View File

@ -147,7 +147,7 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
// TODO: LOW: Could this be performed better?
expandAll();
}
} else if (e.isOtherChange()) {
} else {
fireTreeNodeChanged(e.getSource());
}
}