📄 relativpositionconstraint.java
字号:
package org.j3de.ui.constraint;import javax.media.j3d.BoundingBox;import javax.vecmath.Vector3d; import javax.vecmath.Point3d; import org.w3c.dom.Node;import org.w3c.dom.Document; import org.w3c.dom.Element;import org.j3de.ui.LayoutConstraint;import org.j3de.ui.LayoutInfo;import org.j3de.ui.UIElement;import org.j3de.ui.WrongParameterException;import org.j3de.util.AbstractComponent;import org.j3de.util.StringParser;import org.j3de.util.ConfigurationException;public class RelativPositionConstraint extends AbstractComponent implements LayoutConstraint { private LayoutInfo layoutInfo; private UIElement element1; private UIElement element2; private Vector3d referencePoint1; private Vector3d referencePoint2; private Vector3d relativPosition; public void setLayoutInfo(LayoutInfo layoutInfo) { this.layoutInfo = layoutInfo; } public boolean appliesTo(UIElement element) { return element.equals(element2); } private Vector3d getPosition(Vector3d referencePoint, UIElement element) { BoundingBox bb = new BoundingBox(layoutInfo.getBounds(element)); Point3d upper = new Point3d(); Point3d lower = new Point3d(); bb.getUpper(upper); bb.getLower(lower); double x = lower.x + (upper.x - lower.x) * referencePoint.x; double y = lower.y + (upper.y - lower.y) * referencePoint.y; double z = lower.z + (upper.z - lower.z) * referencePoint.z; return new Vector3d(x, y, z); } public void getForce(Vector3d force) { Vector3d point1 = getPosition(referencePoint1, element1); Vector3d point2 = getPosition(referencePoint2, element2); Vector3d position1 = new Vector3d(); Vector3d position2 = new Vector3d(); layoutInfo.getPosition(element1, position1); layoutInfo.getPosition(element2, position2); point1.add(position1); point2.add(position2); force.set(point2); force.sub(point1); force.sub(relativPosition); } public boolean removeReferencesTo(UIElement element) { if (element1 == element) return true; if (element2 == element) return true; return false; } public void setParam(ConstraintParam param) throws WrongParameterException { if (!(param instanceof TwoElementConstraintParam)) throw new WrongParameterException(this.getClass(), TwoElementConstraintParam.class, param.getClass()); element1 = ((TwoElementConstraintParam)param).getElement1(); element2 = ((TwoElementConstraintParam)param).getElement2(); } public LayoutConstraint cloneConstraint() { RelativPositionConstraint constraint = new RelativPositionConstraint(); constraint.referencePoint1 = this.referencePoint1; constraint.referencePoint2 = this.referencePoint2; constraint.relativPosition = this.relativPosition; return constraint; } public void configure(Node node, Document nodeFactory) throws ConfigurationException { super.configure(node, nodeFactory); referencePoint1 = StringParser.parseVector3d(helper.getPropertyValue("referencePoint1", "0.0 0.0 0.0", true)); referencePoint2 = StringParser.parseVector3d(helper.getPropertyValue("referencePoint2", "0.0 0.0 0.0", true)); relativPosition = StringParser.parseVector3d(helper.getPropertyValue("relativPosition", "0.0 0.0 0.0", true)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -