create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / StreamerDTO.java
1
2 package net.sf.openrocket.preset.xml;
3
4 import net.sf.openrocket.preset.ComponentPreset;
5 import net.sf.openrocket.preset.ComponentPresetFactory;
6 import net.sf.openrocket.preset.InvalidComponentPresetException;
7 import net.sf.openrocket.preset.TypedPropertyMap;
8
9 import javax.xml.bind.annotation.XmlAccessType;
10 import javax.xml.bind.annotation.XmlAccessorType;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import java.util.List;
14
15 /**
16  * Streamer preset XML handler.
17  */
18 @XmlRootElement(name = "Streamer")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class StreamerDTO extends BaseComponentDTO {
21
22     @XmlElement(name = "Length")
23     private AnnotatedLengthDTO length;
24     @XmlElement(name = "Width")
25     private AnnotatedLengthDTO width;
26     @XmlElement(name = "Thickness")
27     private AnnotatedLengthDTO thickness;
28
29     /**
30      * Default constructor.
31      */
32     public StreamerDTO() {
33     }
34
35     /**
36      * Most-useful constructor that maps a BodyTube preset to a BodyTubeDTO.
37      *
38      * @param preset  the preset
39      *
40      * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
41      */
42     public StreamerDTO(final ComponentPreset preset) {
43         super(preset);
44         setWidth(preset.get(ComponentPreset.WIDTH));
45         setThickness(preset.get(ComponentPreset.THICKNESS));
46         setLength(preset.get(ComponentPreset.LENGTH));
47     }
48
49     public double getWidth() {
50         return width.getValue();
51     }
52
53     public void setWidth( final AnnotatedLengthDTO theWidth ) {
54         width = theWidth;
55     }
56     
57     public void setWidth(final double theId) {
58         width = new AnnotatedLengthDTO(theId);
59     }
60
61     public double getThickness() {
62         return thickness.getValue();
63     }
64
65     public void setThickness(final AnnotatedLengthDTO theThickness) {
66         thickness = theThickness;
67     }
68
69     public void setThickness(final double theThickness) {
70         thickness = new AnnotatedLengthDTO(theThickness);
71     }
72
73     public double getLength() {
74         return length.getValue();
75     }
76
77     public void setLength(final AnnotatedLengthDTO theLength) {
78         length = theLength;
79     }
80
81     public void setLength(final double theLength) {
82         length = new AnnotatedLengthDTO(theLength);
83     }
84
85     @Override
86     public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
87         return asComponentPreset(ComponentPreset.Type.STREAMER, materials);
88     }
89
90     public ComponentPreset asComponentPreset(ComponentPreset.Type type, List<MaterialDTO> materials) throws InvalidComponentPresetException {
91         TypedPropertyMap props = new TypedPropertyMap();
92         addProps(props, materials);
93         // TODO - seems some vendors use a bulk material for the sheet along with a Thickness.
94         // need to fix the MATERIAL packed into the componentpreset.
95         props.put(ComponentPreset.WIDTH, this.getWidth());
96         props.put(ComponentPreset.THICKNESS, this.getThickness());
97         props.put(ComponentPreset.LENGTH, this.getLength());
98         props.put(ComponentPreset.TYPE, type);
99
100         return ComponentPresetFactory.create(props);
101     }
102 }