5e7fea0763dbc18ae33432174f87a315d61da7d1
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / ComponentChangeEvent.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import javax.swing.event.ChangeEvent;
4
5 public class ComponentChangeEvent extends ChangeEvent {
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 in 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         public boolean isAerodynamicChange() {
43                 return (type & AERODYNAMIC_CHANGE) != 0;
44         }
45         
46         public boolean isMassChange() {
47                 return (type & MASS_CHANGE) != 0;
48         }
49         
50         public boolean isOtherChange() {
51                 return (type & BOTH_CHANGE) == 0;
52         }
53         
54         public boolean isTreeChange() {
55                 return (type & TREE_CHANGE) != 0;
56         }
57         
58         public boolean isUndoChange() {
59                 return (type & UNDO_CHANGE) != 0;
60         }
61         
62         public boolean isMotorChange() {
63                 return (type & MOTOR_CHANGE) != 0;
64         }
65
66         public int getType() {
67                 return type;
68         }
69         
70         @Override
71         public String toString() {
72                 String s = "";
73                 
74                 if ((type & NONFUNCTIONAL_CHANGE) != 0)
75                         s += ",nonfunc";
76                 if (isMassChange())
77                         s += ",mass";
78                 if (isAerodynamicChange())
79                         s += ",aero";
80                 if (isTreeChange())
81                         s += ",tree";
82                 if (isUndoChange())
83                         s += ",undo";
84                 if (isMotorChange())
85                         s += ",motor";
86                 if ((type & EVENT_CHANGE) != 0)
87                         s += ",event";
88                 
89                 if (s.length() > 0)
90                         s = s.substring(1);
91                 
92                 return "ComponentChangeEvent[" + s + "]";
93         }
94 }