javafx.scene.transform.Translate Java Examples
The following examples show how to use
javafx.scene.transform.Translate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MouthView.java From narjillos with MIT License | 6 votes |
@Override public Node toNode(double zoomLevel, boolean infraredOn, boolean effectsOn) { if (zoomLevel < MINIMUM_ZOOM_LEVEL) return null; Color color = getColor(zoomLevel, infraredOn); for (int i = 0; i < lines.length; i++) { lines[i].setStroke(color); rotateLine(i); } Vector position = getNarjillo().getPosition(); group.getTransforms().clear(); group.getTransforms().add(new Translate(position.x, position.y)); return group; }
Example #2
Source File: Fx3DStageController.java From mzmine3 with GNU General Public License v2.0 | 6 votes |
/** * Starts the rotation of the plot. */ public void handleAnimate() { if (!animationRunning) { yRotate.setAngle(rotateY.getAngle() + deltaAngle); plot.getTransforms().addAll(pivot, yRotate, new Translate(-250, 0, -250)); rotateAnimationTimeline.play(); animationRunning = true; logger.finest("ANIMATE button clicked.Starting animation."); } else { plot.getTransforms().remove(yRotate); rotateY.setAngle(rotateY.getAngle() + yRotate.getAngle()); deltaAngle = yRotate.getAngle(); rotateAnimationTimeline.stop(); animationRunning = false; logger.finest("ANIMATE button clicked.Stopping animation."); } }
Example #3
Source File: SmartGraphEdgeLine.java From JavaFXSmartGraph with MIT License | 6 votes |
@Override public void attachArrow(SmartArrow arrow) { this.attachedArrow = arrow; /* attach arrow to line's endpoint */ arrow.translateXProperty().bind(endXProperty()); arrow.translateYProperty().bind(endYProperty()); /* rotate arrow around itself based on this line's angle */ Rotate rotation = new Rotate(); rotation.pivotXProperty().bind(translateXProperty()); rotation.pivotYProperty().bind(translateYProperty()); rotation.angleProperty().bind( UtilitiesBindings.toDegrees( UtilitiesBindings.atan2( endYProperty().subtract(startYProperty()), endXProperty().subtract(startXProperty())) )); arrow.getTransforms().add(rotation); /* add translation transform to put the arrow touching the circle's bounds */ Translate t = new Translate(- outbound.getRadius(), 0); arrow.getTransforms().add(t); }
Example #4
Source File: RectangleItem.java From OpenLabeler with Apache License 2.0 | 6 votes |
@Override public List<? extends Shape> getHandles(Translate translate, Scale scale, ReadOnlyObjectProperty<Color> colorProperty) { // 4 corner resize handles List<Rectangle> handles = Arrays.asList(new Rectangle[]{ createHandle(Location.NW, cursorNW), createHandle(Location.NE, cursorNE), createHandle(Location.SE, cursorSE), createHandle(Location.SW, cursorSW)}); // Maintain constant handle size at different zoom level handles.forEach(handle -> { scale.addEventHandler(TransformChangedEvent.TRANSFORM_CHANGED, event -> { handle.setWidth(HANDLE_SIZE / scale.getX()); handle.setHeight(HANDLE_SIZE / scale.getY()); }); handle.fillProperty().bind(colorProperty); handle.setWidth(HANDLE_SIZE / scale.getX()); handle.setHeight(HANDLE_SIZE / scale.getY()); handle.getTransforms().addAll(translate, scale); }); return handles; }
Example #5
Source File: SmartGraphEdgeCurve.java From JavaFXSmartGraph with MIT License | 6 votes |
@Override public void attachArrow(SmartArrow arrow) { this.attachedArrow = arrow; /* attach arrow to line's endpoint */ arrow.translateXProperty().bind(endXProperty()); arrow.translateYProperty().bind(endYProperty()); /* rotate arrow around itself based on this line's angle */ Rotate rotation = new Rotate(); rotation.pivotXProperty().bind(translateXProperty()); rotation.pivotYProperty().bind(translateYProperty()); rotation.angleProperty().bind(UtilitiesBindings.toDegrees( UtilitiesBindings.atan2(endYProperty().subtract(controlY2Property()), endXProperty().subtract(controlX2Property())) )); arrow.getTransforms().add(rotation); /* add translation transform to put the arrow touching the circle's bounds */ Translate t = new Translate(-outbound.getRadius(), 0); arrow.getTransforms().add(t); }
Example #6
Source File: Pin.java From BlockMap with MIT License | 6 votes |
@Override protected Node initBottomGui() { StackPane stack = new StackPane(); stack.getChildren().setAll(maps.stream().map(map -> map.getScale()).distinct().map(scale -> { int size = 128 * (1 << scale); Rectangle rect = new Rectangle(size, size, new Color(0.9f, 0.15f, 0.15f, 0.02f)); rect.setStroke(new Color(0.9f, 0.15f, 0.15f, 0.4f)); rect.setMouseTransparent(true); rect.setPickOnBounds(false); getTopGui().hoverProperty().addListener(e -> { if (getTopGui().isHover()) rect.setFill(new Color(0.9f, 0.15f, 0.15f, 0.2f)); else rect.setFill(new Color(0.9f, 0.15f, 0.15f, 0.02f)); }); return rect; }).collect(Collectors.toList())); Translate t = new Translate(); t.xProperty().bind(stack.widthProperty().multiply(-0.5)); t.yProperty().bind(stack.heightProperty().multiply(-0.5)); stack.getTransforms().addAll(t, new Translate(position.x(), position.y())); stack.setPickOnBounds(false); stack.setMouseTransparent(true); stack.setViewOrder(1); return stack; }
Example #7
Source File: Pin.java From BlockMap with MIT License | 6 votes |
/** * Wrap a given Node (e.g. a Pin button) in a {@link StackPane} to be placed on to the map. Applies a scaling function (used to scales it * relative to the current zoom factor) and translations (to keep it at a given world space position and centered). */ static StackPane wrapGui(Node node, Vector2dc position, DoubleBinding scale, DisplayViewport viewport) { StackPane stack = new StackPane(node); Translate center = new Translate(); center.xProperty().bind(stack.widthProperty().multiply(-0.5)); center.yProperty().bind(stack.heightProperty().multiply(-0.5)); if (position != null) stack.getTransforms().add(new Translate(position.x(), position.y())); if (scale != null) { Scale scaleTransform = new Scale(); scaleTransform.xProperty().bind(scale); scaleTransform.yProperty().bind(scale); stack.getTransforms().add(scaleTransform); } stack.getTransforms().add(center); stack.setVisible(false); stack.setPickOnBounds(false); stack.setOpacity(0.0); return stack; }
Example #8
Source File: Fx3DStageController.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
/** * Starts the rotation of the plot. */ public void handleAnimate() { if (!animationRunning) { yRotate.setAngle(rotateY.getAngle() + deltaAngle); plot.getTransforms().addAll(pivot, yRotate, new Translate(-250, 0, -250)); rotateAnimationTimeline.play(); animationRunning = true; LOG.finest("ANIMATE button clicked.Starting animation."); } else { plot.getTransforms().remove(yRotate); rotateY.setAngle(rotateY.getAngle() + yRotate.getAngle()); deltaAngle = yRotate.getAngle(); rotateAnimationTimeline.stop(); animationRunning = false; LOG.finest("ANIMATE button clicked.Stopping animation."); } }
Example #9
Source File: EggView.java From narjillos with MIT License | 6 votes |
public Node toNode(double zoomLevel, boolean infraredOn, boolean effectsOn) { if (zoomLevel < MINIMUM_ZOOM_LEVEL) return null; waveAngle = Angle.normalize(waveAngle + BLOBBING_SPEED); shape.setRadiusX(Math.min(getEgg().getAge(), Configuration.EGG_RADIUS + RADIUS_VARIATION * FastMath.sin(waveAngle))); shape.setRadiusY(Math.min(getEgg().getAge(), Configuration.EGG_RADIUS + RADIUS_VARIATION * FastMath.cos(waveAngle))); shape.setFill(getFillColor(infraredOn)); if (effectsOn) shape.setEffect(getEffects(zoomLevel, infraredOn)); shape.getTransforms().clear(); Translate translation = new Translate(getThing().getPosition().x, getThing().getPosition().y); shape.getTransforms().add(translation); return shape; }
Example #10
Source File: BendableTests.java From gef with Eclipse Public License 2.0 | 6 votes |
@Test public void test_translate() { Point start = new Point(0, 0); Point end = new Point(100, 50); Bendable bendable = new Bendable(start, end); // check content bend points List<BendPoint> contentBendPoints = bendable.getContentBendPoints(); assertEquals(start, contentBendPoints.get(0).getPosition()); assertEquals(end, contentBendPoints.get(1).getPosition()); // check size Dimension contentSize = bendable.getContentSize(); assertEquals(new Rectangle(start, end).getSize(), contentSize); // check transform (should equal translation to offset) Point contentOffset = new Point(bendable.getContentTransform().getTx(), bendable.getContentTransform().getTy()); assertEquals(start, contentOffset); // apply translation Point newStart = start.getTranslated(20, 50); Point newEnd = end.getTranslated(20, 50); Rectangle newBounds = new Rectangle(newStart, newEnd); bendable.setContentTransform(new Affine(new Translate(newStart.x, newStart.y))); assertEquals(newBounds.getSize(), bendable.getContentSize()); contentOffset = new Point(bendable.getContentTransform().getTx(), bendable.getContentTransform().getTy()); assertEquals(newStart, contentOffset); }
Example #11
Source File: EyesView.java From narjillos with MIT License | 6 votes |
public EyesView(Narjillo narjillo) { this.narjillo = narjillo; Fiber fiber = narjillo.getBody().getHead().getFiber(); this.eyeRed = fiber.getPercentOfRed(); this.eyeGreen = fiber.getPercentOfGreen(); this.eyeBlue = fiber.getPercentOfBlue(); // "Random qualities": we want something that looks random across narjillos, // but stays the same for the same narjillo even after saving and reloading double someRandomQuality = narjillo.getBody().getAdultMass(); double someOtherRandomQuality = narjillo.getBody().getEnergyToChildren(); this.eye1 = new Circle(someRandomQuality % 5 + 7); this.eye2 = new Circle(someOtherRandomQuality % 5 + 7); this.pupil1 = new Circle(Math.min(eye1.getRadius() - 2, someRandomQuality % 6 + 1)); this.pupil2 = new Circle(Math.min(eye1.getRadius() - 2, someOtherRandomQuality % 6 + 1)); eyeCenteringTranslation = eye1.getRadius() - eye2.getRadius(); pupilTranslation = Math.min(eye2.getRadius() - pupil2.getRadius(), eye1.getRadius() - pupil1.getRadius()); this.eye1.getTransforms().add(new Translate(eyeCenteringTranslation - eye1.getRadius() + 1, 0)); this.eye2.getTransforms().add(new Translate(eyeCenteringTranslation + eye2.getRadius() - 1, 0)); }
Example #12
Source File: OrganView.java From narjillos with MIT License | 6 votes |
private Shape getShape(double zoomLevel, boolean effectsOn) { segment.setWidth(organ.getLength() + getOverlap() * 2); segment.setHeight(organ.getThickness()); segment.getTransforms().clear(); // overlap slightly and shift to center based on thickness double widthCenter = organ.getThickness() / 2; segment.getTransforms().add(moveToStartPoint()); segment.getTransforms().add(new Translate(-getOverlap(), -widthCenter)); segment.getTransforms().add(new Rotate(organ.getAbsoluteAngle(), getOverlap(), widthCenter)); boolean isHighDetail = hasJoint && zoomLevel >= VERY_HIGH_MAGNIFICATION && effectsOn; if (!isHighDetail) return segment; joint.setRadius(getJointRadius(organ.getThickness())); joint.getTransforms().clear(); joint.getTransforms().add(moveToStartPoint()); joint.getTransforms().add(new Translate(organ.getLength(), 0)); joint.getTransforms().add(new Rotate(organ.getAbsoluteAngle(), -organ.getLength(), 0)); return Path.union(segment, joint); }
Example #13
Source File: PolygonItem.java From OpenLabeler with Apache License 2.0 | 6 votes |
@Override public List<? extends Shape> getHandles(Translate translate, Scale scale, ReadOnlyObjectProperty<Color> colorProperty) { List<Shape> handles = new ArrayList<>(); IntStream.range(0, getPoints().size() / 2).forEach(idx -> { Handle handle = new Handle(idx, getPoints()); handles.add(handle); // Maintain constant handle size at different zoom level scale.addEventHandler(TransformChangedEvent.TRANSFORM_CHANGED, event -> { handle.setRadius(HANDLE_RADIUS / scale.getX()); }); handle.fillProperty().bind(colorProperty); handle.setRadius(HANDLE_RADIUS / scale.getX()); handle.getTransforms().addAll(translate, scale); }); return handles; }
Example #14
Source File: ViewArrow.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Override public void setTranslation(final double tx, final double ty) { final Translate translate = new Translate(tx, ty); ellipse.getTransforms().add(0, translate); path.getTransforms().add(0, translate); arc.getTransforms().add(0, translate); }
Example #15
Source File: Sample3D.java From marathonv5 with Apache License 2.0 | 5 votes |
protected Sample3D(double width, double height) { super(width, height); Group group3d = new Group(create3dContent()); group3d.setDepthTest(DepthTest.ENABLE); group3d.getTransforms().addAll( new Translate(width / 2, height / 2), new Rotate(180, Rotate.X_AXIS) ); getChildren().add(group3d); }
Example #16
Source File: Cube3D.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Stage primaryStage) { Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 400, 150, true)); primaryStage.getScene().setCamera(new PerspectiveCamera()); root.getTransforms().addAll( new Translate(400 / 2, 150 / 2), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent()); }
Example #17
Source File: CubeSystem3D.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Stage primaryStage) { Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 500, 500, true)); primaryStage.getScene().setCamera(new PerspectiveCamera()); root.getTransforms().addAll( new Translate(500 / 2, 500 / 2), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent()); }
Example #18
Source File: EnvironmentView.java From narjillos with MIT License | 5 votes |
private Group getThingsGroup(boolean infraredOn, boolean effectsOn) { Group things = new Group(); things.getChildren().addAll(getNodesForThingsInOrder(infraredOn, effectsOn)); if (VisualDebugger.DEBUG) things.getChildren().add(getVisualDebuggingSegments()); things.getTransforms().add(new Translate(-viewport.getPositionEC().x, -viewport.getPositionEC().y)); things.getTransforms().add( new Scale(viewport.getZoomLevel(), viewport.getZoomLevel(), viewport.getPositionEC().x, viewport.getPositionEC().y)); return things; }
Example #19
Source File: Sample3D.java From marathonv5 with Apache License 2.0 | 5 votes |
protected Sample3D(double width, double height) { super(width, height); Group group3d = new Group(create3dContent()); group3d.setDepthTest(DepthTest.ENABLE); group3d.getTransforms().addAll( new Translate(width / 2, height / 2), new Rotate(180, Rotate.X_AXIS) ); getChildren().add(group3d); }
Example #20
Source File: NodePart.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public Affine getContentTransform() { Point position = ZestProperties.getPosition(getContent()); if (position == null) { position = new Point(); } return new Affine(new Translate(position.x, position.y)); }
Example #21
Source File: AbstractLabelPart.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public Affine getContentTransform() { Point p = getLabelPosition(); if (p == null) { p = new Point(); } return new Affine(new Translate(p.x, p.y)); }
Example #22
Source File: IBendableContentPart.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Computes the translation from the given list of * {@link IBendableContentPart.BendPoint}s as the offset of the bounds * around the unattached bend points. * * @param bendPoints * The list of {@link IBendableContentPart.BendPoint}s for * which to compute the translation. * @return The translation of the bounds around the unattached bend * points. */ static Affine computeTranslation(List<BendPoint> bendPoints) { // iterate over the unattached bend-points to find the minimum Point min = null; for (BendPoint bp : bendPoints) { if (!bp.isAttached()) { Point pos = bp.getPosition(); if (min == null) { // initialize min // XXX: copy so it can safely be changed min = pos.getCopy(); } else { // adjust min to the given position if (min.x > pos.x) { min.x = pos.x; } if (min.y > pos.y) { min.y = pos.y; } } } } // XXX: in case there are no unattached bend-points, an identity // transformation is returned return min == null ? new Affine() : new Affine(new Translate(min.x, min.y)); }
Example #23
Source File: SVGGlyphLoader.java From JFoenix with Apache License 2.0 | 5 votes |
/** * will retrieve icons from the glyphs map for a certain glyphName * * @param glyphName the glyph name * @return SVGGlyph node */ public static SVGGlyph getIcoMoonGlyph(String glyphName) throws Exception{ SVGGlyphBuilder builder = glyphsMap.get(glyphName); if(builder == null) throw new Exception("Glyph '" + glyphName + "' not found!"); SVGGlyph glyph = builder.build(); // we need to apply transformation to correct the icon since // its being inverted after importing from icomoon glyph.getTransforms().add(new Scale(1, -1)); Translate height = new Translate(); height.yProperty().bind(Bindings.createDoubleBinding(() -> -glyph.getHeight(), glyph.heightProperty())); glyph.getTransforms().add(height); return glyph; }
Example #24
Source File: MainPresenter.java From clarity-analyzer with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void resizeMapControl() { double scale = Math.min(mapCanvasPane.getWidth() / mapControl.getSize(), mapCanvasPane.getHeight() / mapControl.getSize()); double sw = mapControl.getSize() * scale; double dx = mapCanvasPane.getWidth() - sw; double dy = mapCanvasPane.getHeight() - sw; mapCanvasPane.getTransforms().clear(); mapCanvasPane.getTransforms().add(new Scale(scale, scale)); mapCanvasPane.getTransforms().add(new Translate(0.5 * dx / scale, 0.5 * dy / scale)); }
Example #25
Source File: Snake3dApp.java From FXTutorials with MIT License | 5 votes |
private Scene createScene() { Cube cube = new Cube(Color.BLUE); snake.getChildren().add(cube); moveFood(); root.getChildren().addAll(snake, food); Scene scene = new Scene(root, 1280, 720, true); PerspectiveCamera camera = new PerspectiveCamera(true); camera.getTransforms().addAll(new Translate(0, -20, -20), new Rotate(-45, Rotate.X_AXIS)); scene.setCamera(camera); timer = new AnimationTimer() { @Override public void handle(long now) { t += 0.016; if (t > 0.1) { onUpdate(); t = 0; } } }; timer.start(); return scene; }
Example #26
Source File: Axes.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
public Axes(double scale) { axisX.getTransforms().addAll(new Rotate(90, Rotate.Z_AXIS), new Translate(0, 30, 0)); axisX.setMaterial(new PhongMaterial(Color.RED)); axisY.getTransforms().add(new Translate(0, 30, 0)); axisY.setMaterial(new PhongMaterial(Color.GREEN)); axisZ.setMaterial(new PhongMaterial(Color.BLUE)); axisZ.getTransforms().addAll(new Rotate(90, Rotate.X_AXIS), new Translate(0, 30, 0)); getChildren().addAll(axisX, axisY, axisZ); getTransforms().add(new Scale(scale, scale, scale)); }
Example #27
Source File: Axes.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
public void setHeight(double equalHeights) { double oldHeight = axisX.getHeight(); axisX.setHeight(equalHeights); axisX.getTransforms().add(new Translate(0, (equalHeights/2.0)-(oldHeight/2.0), 0)); axisY.setHeight(equalHeights); axisY.getTransforms().add(new Translate(0, (equalHeights/2.0)-(oldHeight/2.0), 0)); axisZ.setHeight(equalHeights); axisZ.getTransforms().add(new Translate(0,(equalHeights/2.0)-(oldHeight/2.0), 0)); }
Example #28
Source File: OctahedronTest.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
private void generateShapes() { for (int i = 0; i < 100; i++) { Random r = new Random(); //A lot of magic numbers in here that just artificially constrain the math float randomHypotenuse = (float) ((r.nextFloat()*300) + 25); float randomHeight = (float) ((r.nextFloat()*200)+ 25); Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); Octahedron octahedron = new Octahedron(randomHypotenuse, randomHeight, randomColor); octahedron.setEmissiveLightingColor(randomColor); octahedron.setEmissiveLightingOn(r.nextBoolean()); octahedron.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE); double translationX = Math.random() * 1024; if (Math.random() >= 0.5) { translationX *= -1; } double translationY = Math.random() * 1024; if (Math.random() >= 0.5) { translationY *= -1; } double translationZ = Math.random() * 1024; if (Math.random() >= 0.5) { translationZ *= -1; } Translate translate = new Translate(translationX, translationY, translationZ); Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS); Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS); Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS); octahedron.getTransforms().addAll(translate, rotateX, rotateY, rotateZ); shapeGroup.getChildren().add(octahedron); } }
Example #29
Source File: TrapezoidTest.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
private void generateShapes() { for (int i = 0; i < 50; i++) { Random r = new Random(); //A lot of magic numbers in here that just artificially constrain the math double randomSmallSize = (double) ((r.nextDouble()*50) + 10); double randomBigSize = (double) ((r.nextDouble()*100)+ 50); double randomHeight = (double) ((r.nextDouble()*50)+ 25); double randomDepth = (double) ((r.nextDouble()*50) + 25); Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); Trapezoid trapezoid = new Trapezoid(randomSmallSize, randomBigSize, randomHeight, randomDepth, randomColor); // Trapezoid trapezoid = new Trapezoid(50, 100, 50, 50, randomColor); trapezoid.setEmissiveLightingColor(randomColor); trapezoid.setEmissiveLightingOn(r.nextBoolean()); trapezoid.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE); double translationX = Math.random() * 1024; if (Math.random() >= 0.5) { translationX *= -1; } double translationY = Math.random() * 1024; if (Math.random() >= 0.5) { translationY *= -1; } double translationZ = Math.random() * 1024; if (Math.random() >= 0.5) { translationZ *= -1; } Translate translate = new Translate(translationX, translationY, translationZ); Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS); Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS); Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS); trapezoid.getTransforms().addAll(translate, rotateX, rotateY, rotateZ); shapeGroup.getChildren().add(trapezoid); } }
Example #30
Source File: AbstractLabelPart.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Adjusts the label's position to fit the given {@link Point}. * * @param visual * This node's visual. * @param position * This node's position. */ protected void refreshPosition(Node visual, Point position) { if (position != null) { // translate using a transform operation TransformVisualOperation refreshPositionOp = new TransformVisualOperation(this, new Affine(new Translate(position.x, position.y))); try { refreshPositionOp.execute(null, null); } catch (ExecutionException e) { e.printStackTrace(); } } }