create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / ComponentChangeEvent.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import java.util.EventObject;
4
5 public class ComponentChangeEvent extends EventObject {
6         private static final long serialVersionUID = 1L;
7         
8
9         /** A change that does not affect simulation results in any way (name, color, etc.) */
10         public static final int NONFUNCTIONAL_CHANGE = 1;
11         /** A change that affects the mass properties of the rocket */
12         public static final int MASS_CHANGE = 2;
13         /** A change that affects the aerodynamic properties of the rocket */
14         public static final int AERODYNAMIC_CHANGE = 4;
15         /** A change that affects the mass and aerodynamic properties of the rocket */
16         public static final int BOTH_CHANGE = MASS_CHANGE | AERODYNAMIC_CHANGE; // Mass & Aerodynamic
17         
18         /** A change that affects the rocket tree structure */
19         public static final int TREE_CHANGE = 8;
20         /** A change caused by undo/redo. */
21         public static final int UNDO_CHANGE = 16;
22         /** A change in the motor configurations or names */
23         public static final int MOTOR_CHANGE = 32;
24         /** A change that affects the events occurring during flight. */
25         public static final int EVENT_CHANGE = 64;
26         
27         /** A bit-field that contains all possible change types. */
28         public static final int ALL_CHANGE = 0xFFFFFFFF;
29         
30         private final int type;
31         
32         
33         public ComponentChangeEvent(RocketComponent component, int type) {
34                 super(component);
35                 if (type == 0) {
36                         throw new IllegalArgumentException("no event type provided");
37                 }
38                 this.type = type;
39         }
40         
41         
42         /**
43          * Return the source component of this event as specified in the constructor.
44          */
45         @Override
46         public RocketComponent getSource() {
47                 return (RocketComponent) super.getSource();
48         }
49         
50         
51         public boolean isAerodynamicChange() {
52                 return (type & AERODYNAMIC_CHANGE) != 0;
53         }
54         
55         public boolean isMassChange() {
56                 return (type & MASS_CHANGE) != 0;
57         }
58         
59         public boolean isOtherChange() {
60                 return (type & BOTH_CHANGE) == 0;
61         }
62         
63         public boolean isTreeChange() {
64                 return (type & TREE_CHANGE) != 0;
65         }
66         
67         public boolean isUndoChange() {
68                 return (type & UNDO_CHANGE) != 0;
69         }
70         
71         public boolean isMotorChange() {
72                 return (type & MOTOR_CHANGE) != 0;
73         }
74         
75         public int getType() {
76                 return type;
77         }
78         
79         @Override
80         public String toString() {
81                 String s = "";
82                 
83                 if ((type & NONFUNCTIONAL_CHANGE) != 0)
84                         s += ",nonfunc";
85                 if (isMassChange())
86                         s += ",mass";
87                 if (isAerodynamicChange())
88                         s += ",aero";
89                 if (isTreeChange())
90                         s += ",tree";
91                 if (isUndoChange())
92                         s += ",undo";
93                 if (isMotorChange())
94                         s += ",motor";
95                 if ((type & EVENT_CHANGE) != 0)
96                         s += ",event";
97                 
98                 if (s.length() > 0)
99                         s = s.substring(1);
100                 
101                 return "ComponentChangeEvent[" + s + "]";
102         }
103 }