Reimplement ComponentPreset to be a bag of typed parameters. This provides greater...
[debian/openrocket] / core / src / net / sf / openrocket / preset / ComponentPreset.java
1 package net.sf.openrocket.preset;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import net.sf.openrocket.material.Material;
7 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
8
9
10 /**
11  * A model for a preset component.
12  * <p>
13  * A preset component contains a component class type, manufacturer information,
14  * part information, and a method that returns a prototype of the preset component.
15  * 
16  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17  */
18 public class ComponentPreset extends TypedPropertyMap {
19         
20         // TODO - Implement clone.
21         // Implement "freezing" so the object cannot be modified.
22         
23         public enum Type {
24                 BodyTube,
25                 NoseCone
26         }
27
28         public final static TypedKey<Double> LENGTH = new TypedKey<Double>("Length", Double.class);
29         public final static TypedKey<Double> INNER_DIAMETER = new TypedKey<Double>("InnerDiameter", Double.class);
30         public final static TypedKey<Double> OUTER_DIAMETER = new TypedKey<Double>("OuterDiameter", Double.class);
31         public final static TypedKey<Material> MATERIAL = new TypedKey<Material>("Material", Material.class);
32         public final static TypedKey<Finish> FINISH = new TypedKey<Finish>("Finish",Finish.class);
33         public final static TypedKey<Double> THICKNESS = new TypedKey<Double>("Thickness", Double.class);
34         public final static TypedKey<Boolean> FILLED = new TypedKey<Boolean>("Filled",Boolean.class);
35         public final static TypedKey<Double> MASS = new TypedKey<Double>("Mass", Double.class);
36         
37         public final static Map<String,TypedKey<?>> keyMap = new HashMap<String,TypedKey<?>>();
38         static {
39                 keyMap.put(LENGTH.getName(), LENGTH);
40                 keyMap.put(INNER_DIAMETER.getName(), INNER_DIAMETER);
41                 keyMap.put(OUTER_DIAMETER.getName(), OUTER_DIAMETER);
42                 keyMap.put(MATERIAL.getName(), MATERIAL);
43                 keyMap.put(FINISH.getName(), FINISH);
44                 keyMap.put(THICKNESS.getName(), THICKNESS);
45                 keyMap.put(FILLED.getName(), FILLED);
46                 keyMap.put(MASS.getName(), MASS);
47         }
48         
49         private String manufacturer;
50         private String partNo;
51         private String partDescription;
52         private Type type;
53
54         public ComponentPreset() {
55                 
56         }
57
58         public String getManufacturer() {
59                 return manufacturer;
60         }
61
62         public void setManufacturer(String manufacturer) {
63                 this.manufacturer = manufacturer;
64         }
65
66         public String getPartNo() {
67                 return partNo;
68         }
69
70         public void setPartNo(String partNo) {
71                 this.partNo = partNo;
72         }
73
74         public String getPartDescription() {
75                 return partDescription;
76         }
77
78         public void setPartDescription(String partDescription) {
79                 this.partDescription = partDescription;
80         }
81
82         public Type getType() {
83                 return type;
84         }
85
86         public void setType(Type type) {
87                 this.type = type;
88         }
89         
90
91 }