create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / Sleeve.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.startup.Application;
5 import net.sf.openrocket.util.Coordinate;
6 import net.sf.openrocket.util.MathUtil;
7
8
9 /**
10  * A RingComponent that comes on top of another tube.  It's defined by the inner
11  * radius and thickness.  The inner radius can be automatic, in which case it
12  * takes the radius of the parent component.
13  *  
14  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15  */
16 public class Sleeve extends RingComponent {
17         private static final Translator trans = Application.getTranslator();
18         
19         protected double innerRadius = 0;
20         protected double thickness = 0;
21         
22         
23         public Sleeve() {
24                 super();
25                 setInnerRadiusAutomatic(true);
26                 setThickness(0.001);
27                 setLength(0.05);
28         }
29         
30         
31         @Override
32         public double getOuterRadius() {
33                 return getInnerRadius() + thickness;
34         }
35         
36         @Override
37         public void setOuterRadius(double r) {
38                 if (MathUtil.equals(getOuterRadius(), r))
39                         return;
40                 
41                 innerRadius = Math.max(r - thickness, 0);
42                 if (thickness > r)
43                         thickness = r;
44                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
45         }
46         
47         
48         @Override
49         public double getInnerRadius() {
50                 // Implement parent inner radius automation
51                 if (isInnerRadiusAutomatic() && getParent() instanceof RadialParent) {
52                         RocketComponent parent = getParent();
53                         double pos1 = this.toRelative(Coordinate.NUL, parent)[0].x;
54                         double pos2 = this.toRelative(new Coordinate(getLength()), parent)[0].x;
55                         pos1 = MathUtil.clamp(pos1, 0, parent.getLength());
56                         pos2 = MathUtil.clamp(pos2, 0, parent.getLength());
57                         innerRadius = Math.max(((RadialParent) parent).getOuterRadius(pos1),
58                                         ((RadialParent) parent).getOuterRadius(pos2));
59                 }
60                 
61                 return innerRadius;
62         }
63         
64         @Override
65         public void setInnerRadius(double r) {
66                 r = Math.max(r, 0);
67                 if (MathUtil.equals(innerRadius, r))
68                         return;
69                 innerRadius = r;
70                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
71         }
72         
73         @Override
74         public double getThickness() {
75                 return thickness;
76         }
77         
78         @Override
79         public void setThickness(double t) {
80                 t = Math.max(t, 0);
81                 if (MathUtil.equals(thickness, t))
82                         return;
83                 thickness = t;
84                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
85         }
86         
87         
88
89
90         @Override
91         public void setInnerRadiusAutomatic(boolean auto) {
92                 super.setOuterRadiusAutomatic(auto);
93         }
94         
95         @Override
96         public String getComponentName() {
97                 return trans.get ("Sleeve.Sleeve");
98         }
99         
100         @Override
101         public boolean allowsChildren() {
102                 return false;
103         }
104         
105         @Override
106         public boolean isCompatible(Class<? extends RocketComponent> type) {
107                 return false;
108         }
109 }