Initial work on BodyTube ComponentPresets.
[debian/openrocket] / core / src / net / sf / openrocket / preset / ComponentPreset.java
1 package net.sf.openrocket.preset;
2
3 import net.sf.openrocket.rocketcomponent.RocketComponent;
4
5
6 /**
7  * A model for a preset component.
8  * <p>
9  * A preset component contains a component class type, manufacturer information,
10  * part information, and a method that returns a prototype of the preset component.
11  * 
12  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13  */
14 public class ComponentPreset {
15
16
17         private final String manufacturer;
18         private final String partNo;
19         private final String partDescription;
20         private final RocketComponent prototype;
21
22
23         public ComponentPreset(String manufacturer, String partNo, String partDescription, RocketComponent prototype) {
24                 this.manufacturer = manufacturer;
25                 this.partNo = partNo;
26                 this.partDescription = partDescription;
27                 this.prototype = prototype.copy();
28
29                 if (prototype.getParent() != null) {
30                         throw new IllegalArgumentException("Prototype component cannot have a parent");
31                 }
32                 if (prototype.getChildCount() > 0) {
33                         throw new IllegalArgumentException("Prototype component cannot have children");
34                 }
35
36         }
37
38         /**
39          * Return the component class that this preset defines.
40          */
41         public Class<? extends RocketComponent> getComponentClass() {
42                 return prototype.getClass();
43         }
44
45         /**
46          * Return the manufacturer of this preset component.
47          */
48         public String getManufacturer() {
49                 return manufacturer;
50         }
51
52         /**
53          * Return the part number.  This is the part identifier (e.g. "BT-50").
54          */
55         public String getPartNo() {
56                 return partNo;
57         }
58
59         /**
60          * Return the part description.  This is a longer description of the component.
61          */
62         public String getPartDescription() {
63                 return partDescription;
64         }
65
66         /**
67          * Return a prototype component.  This component may be modified freely.
68          */
69         public RocketComponent getPrototype() {
70                 return prototype.copy();
71         }
72
73 }