1 package net.sf.openrocket.rocketcomponent;
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;
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.
14 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16 public class Sleeve extends RingComponent {
17 private static final Translator trans = Application.getTranslator();
19 protected double innerRadius = 0;
20 protected double thickness = 0;
25 setInnerRadiusAutomatic(true);
32 public double getOuterRadius() {
33 return getInnerRadius() + thickness;
37 public void setOuterRadius(double r) {
38 if (MathUtil.equals(getOuterRadius(), r))
41 innerRadius = Math.max(r - thickness, 0);
44 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
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));
65 public void setInnerRadius(double r) {
67 if (MathUtil.equals(innerRadius, r))
70 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
74 public double getThickness() {
79 public void setThickness(double t) {
81 if (MathUtil.equals(thickness, t))
84 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
91 public void setInnerRadiusAutomatic(boolean auto) {
92 super.setOuterRadiusAutomatic(auto);
96 public String getComponentName() {
97 return trans.get ("Sleeve.Sleeve");
101 public boolean allowsChildren() {
106 public boolean isCompatible(Class<? extends RocketComponent> type) {