4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.ElementHandler;
8 import net.sf.openrocket.file.simplesax.PlainTextHandler;
9 import net.sf.openrocket.material.Material;
10 import net.sf.openrocket.rocketcomponent.RocketComponent;
11 import net.sf.openrocket.rocketcomponent.Streamer;
12 import org.xml.sax.SAXException;
14 import java.util.HashMap;
17 * A SAX handler for Streamer components.
19 class StreamerHandler extends PositionDependentHandler<Streamer> {
22 * The OpenRocket Streamer.
24 private final Streamer streamer;
29 * @param c the parent component
30 * @throws IllegalArgumentException thrown if <code>c</code> is null
32 public StreamerHandler(RocketComponent c) throws IllegalArgumentException {
34 throw new IllegalArgumentException("The parent of a streamer may not be null.");
36 streamer = new Streamer();
41 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
42 return PlainTextHandler.INSTANCE;
46 public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
48 super.closeElement(element, attributes, content, warnings);
51 if ("Width".equals(element)) {
52 streamer.setStripWidth(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH));
54 if ("Len".equals(element)) {
55 streamer.setStripLength(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH));
57 if ("DragCoefficient".equals(element)) {
58 streamer.setCD(Double.parseDouble(content));
60 if ("Material".equals(element)) {
61 setMaterialName(content);
64 catch (NumberFormatException nfe) {
65 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
70 public Streamer getComponent() {
75 * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
76 * public in all components.
78 * @param position the OpenRocket position
81 public void setRelativePosition(RocketComponent.Position position) {
82 streamer.setRelativePosition(position);
86 * Get the required type of material for this component.
91 public Material.Type getMaterialType() {
92 return Material.Type.SURFACE;