Java Code Examples for javafx.scene.Node#setTranslateX()
The following examples show how to use
javafx.scene.Node#setTranslateX() .
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: FxIconBuilder.java From FxDock with Apache License 2.0 | 8 votes |
/** auto fit last node, useful for svg paths */ public void autoFitLastElement() { Node n = last(); double w = n.prefHeight(width); double h = n.prefWidth(height); double sx = width / w; double sy = height / h; double sc = Math.min(sx, sy); n.setScaleX(sc); n.setScaleY(sc); Bounds b = n.getBoundsInLocal(); double dx = (width / 2.0) - b.getMinX() - (b.getWidth() / 2.0); double dy = (height / 2.0) - b.getMinY() - (b.getHeight() / 2.0); n.setTranslateX(dx); n.setTranslateY(dy); }
Example 2
Source File: ScatterPlot.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
/** * @param data the zAxisData to set */ public void setzAxisData(List<Double> data) { zAxisData = data; scatterDataGroup.getChildren().clear(); for(int i=0;i<zAxisData.size();i++) { // final Sphere dataSphere = new Sphere(scatterRadius); // final Box dataSphere = new Box(scatterRadius, scatterRadius, scatterRadius); final Node dataSphere = createDefaultNode(nodeRadius); double translateX = 0.0; double translateY = 0.0; if(!xAxisData.isEmpty() && xAxisData.size() > i) translateX = xAxisData.get(i); if(!yAxisData.isEmpty() && yAxisData.size() > i) translateY = yAxisData.get(i); dataSphere.setTranslateX(translateX); dataSphere.setTranslateY(translateY); dataSphere.setTranslateZ(zAxisData.get(i)); scatterDataGroup.getChildren().add(dataSphere); } }
Example 3
Source File: ScatterPlot.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
/** * @param data the yAxisData to set */ public void setyAxisData(List<Double> data) { yAxisData = data; scatterDataGroup.getChildren().clear(); for(int i=0;i<yAxisData.size();i++) { // final Sphere dataSphere = new Sphere(scatterRadius); // final Box dataSphere = new Box(scatterRadius, scatterRadius, scatterRadius); final Node dataSphere = createDefaultNode(nodeRadius); double translateX = 0.0; double translateZ = 0.0; if(!xAxisData.isEmpty() && xAxisData.size() > i) translateX = xAxisData.get(i); if(!zAxisData.isEmpty() && zAxisData.size() > i) translateZ = zAxisData.get(i); dataSphere.setTranslateX(translateX); dataSphere.setTranslateY(yAxisData.get(i)); dataSphere.setTranslateZ(translateZ); scatterDataGroup.getChildren().add(dataSphere); } }
Example 4
Source File: ScatterPlot.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
/** * @param data the xAxisData to set */ public void setxAxisData(List<Double> data) { xAxisData = data; scatterDataGroup.getChildren().clear(); for(int i=0;i<xAxisData.size();i++) { // final Sphere dataSphere = new Sphere(scatterRadius); // final Box dataSphere = new Box(scatterRadius, scatterRadius, scatterRadius); final Node dataSphere = createDefaultNode(nodeRadius); double translateY = 0.0; double translateZ = 0.0; if(!yAxisData.isEmpty() && yAxisData.size() > i) translateY = yAxisData.get(i); if(!zAxisData.isEmpty() && zAxisData.size() > i) translateZ = zAxisData.get(i); dataSphere.setTranslateX(xAxisData.get(i)); dataSphere.setTranslateY(translateY); dataSphere.setTranslateZ(translateZ); scatterDataGroup.getChildren().add(dataSphere); } }
Example 5
Source File: RadialSettingsMenuCenter.java From RadialFx with GNU Lesser General Public License v3.0 | 5 votes |
void addCenterItem(final Object key, final Node centerGraphic) { centerGraphics.put(key, centerGraphic); centerGraphic.setTranslateX(-centerGraphic.getBoundsInLocal() .getWidth() / 2.0); centerGraphic.setTranslateY(-centerGraphic.getBoundsInLocal() .getHeight() / 2.0); }
Example 6
Source File: FxIconBuilder.java From FxDock with Apache License 2.0 | 5 votes |
protected void applyNodeProperties(Node n) { n.setOpacity(opacity); n.setScaleX(scale); n.setScaleY(scale); n.setTranslateX(xtranslate); n.setTranslateY(ytranslate); n.setEffect(effect); n.setRotate(rotate); }
Example 7
Source File: MapPresenter.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void layoutLayer() { for (Pair<MapPoint, Node> candidate : points) { MapPoint point = candidate.getKey(); Node icon = candidate.getValue(); Bounds bounds = icon.getBoundsInParent(); Point2D mapPoint = baseMap.getMapPoint(point.getLatitude(), point.getLongitude()); // translate icon so marker base point is at the center icon.setTranslateX(mapPoint.getX() - bounds.getWidth() / 2); icon.setTranslateY(mapPoint.getY() - bounds.getHeight() / 2 - 10); } }
Example 8
Source File: PoiLayer.java From maps with GNU General Public License v3.0 | 5 votes |
@Override protected void layoutLayer() { for (Pair<MapPoint, Node> candidate : points) { MapPoint point = candidate.getKey(); Node icon = candidate.getValue(); Point2D mapPoint = getMapPoint(point.getLatitude(), point.getLongitude()); icon.setVisible(true); icon.setTranslateX(mapPoint.getX()); icon.setTranslateY(mapPoint.getY()); } }
Example 9
Source File: MainMenu.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void createMovingStarfield() { for (int i = 0; i < STAR_COUNT; i++) { nodes[i] = new Rectangle(1, 1, Color.DARKGOLDENROD);// .WHITE); angles[i] = 2.0 * Math.PI * random.nextDouble(); start[i] = random.nextInt(TIME); } starsTimer = new AnimationTimer() { @Override public void handle(long now) { final double width = 0.25 * WIDTH;// primaryStage.getWidth(); final double height = 0.5 * HEIGHT;// primaryStage.getHeight(); final double radius = Math.sqrt(2) * Math.max(width, height); for (int i = 0; i < STAR_COUNT; i++) { final Node node = nodes[i]; final double angle = angles[i]; final long t = (now - start[i]) % TIME; final double d = t * radius / TIME; node.setTranslateX(Math.cos(angle) * d + width); node.setTranslateY(Math.sin(angle) * d + height); } } }; starsTimer.start(); }
Example 10
Source File: NodeMenuItem.java From PDF4Teachers with Apache License 2.0 | 5 votes |
public void setLeftData(Node data){ Pane pane = new Pane(); if(fat){ pane.setStyle("-fx-font-size: 13; -fx-padding: 7 0 7 10;"); // top - right - bottom - left data.setTranslateY(7); }else{ pane.setStyle("-fx-font-size: 13; -fx-padding: 3 0 3 10;"); // top - right - bottom - left data.setTranslateY(3); } data.setTranslateX(10); pane.getChildren().add(data); getNode().getChildren().set(0, pane); }
Example 11
Source File: LoadingScreen.java From FXTutorials with MIT License | 5 votes |
public LoadingScreen(int width, int height, Runnable action) { ImageView bg = new ImageView(new Image( getClass().getResource("res/Fallout4_loading.jpg").toExternalForm() )); bg.setFitWidth(width); bg.setFitHeight(height); Node symbol = makeSymbol(); symbol.setTranslateX(width - 150); symbol.setTranslateY(height - 100); timeline.setOnFinished(e -> action.run()); getChildren().addAll(bg, symbol); }
Example 12
Source File: FroggerApp.java From FXTutorials with MIT License | 5 votes |
private void onUpdate() { for (Node car : cars) car.setTranslateX(car.getTranslateX() + Math.random() * 10); if (Math.random() < 0.075) { cars.add(spawnCar()); } checkState(); }
Example 13
Source File: JFXAlertAnimation.java From JFoenix with Apache License 2.0 | 4 votes |
@Override public void initAnimation(Node contentContainer, Node overlay) { overlay.setOpacity(0); contentContainer.setTranslateX(-(contentContainer.getLayoutX() + contentContainer.getLayoutBounds().getMaxX())); }
Example 14
Source File: JFXNodesList.java From JFoenix with Apache License 2.0 | 4 votes |
@Override protected void layoutChildren() { performingLayout = true; List<Node> children = getChildren(); Insets insets = getInsets(); double width = getWidth(); double rotate = getRotate(); double height = getHeight(); double left = snapSpace(insets.getLeft()); double right = snapSpace(insets.getRight()); double space = snapSpace(getSpacing()); boolean isFillWidth = isFillWidth(); double contentWidth = width - left - right; Pos alignment = getAlignment(); alignment = alignment == null ? Pos.TOP_CENTER : alignment; final HPos hpos = alignment.getHpos(); final VPos vpos = alignment.getVpos(); double y = 0; for (int i = 0, size = children.size(); i < size; i++) { Node child = children.get(i); child.autosize(); child.setRotate(rotate % 180 == 0 ? rotate : -rotate); // init child node if not added using addAnimatedChild method if (!animationsMap.containsKey(child)) { if (child instanceof JFXNodesList) { StackPane container = new StackPane(child); container.setPickOnBounds(false); getChildren().set(i, container); } initChild(child, i, null, true); } double x = 0; double childWidth = child.getLayoutBounds().getWidth(); double childHeight = child.getLayoutBounds().getHeight(); if(childWidth > width){ switch (hpos) { case CENTER: x = snapPosition(contentWidth - childWidth) / 2; break; } Node alignToChild = getAlignNodeToChild(child); if (alignToChild != null && child instanceof Parent) { ((Parent) child).layout(); double alignedWidth = alignToChild.getLayoutBounds().getWidth(); double alignedX = alignToChild.getLayoutX(); if(childWidth / 2 > alignedX + alignedWidth){ alignedWidth = -(childWidth / 2 - (alignedWidth/2 + alignedX)); }else{ alignedWidth = alignedWidth/2 + alignedX - childWidth / 2; } child.setTranslateX(-alignedWidth * Math.cos(Math.toRadians(rotate))); child.setTranslateY(alignedWidth * Math.cos(Math.toRadians(90 - rotate))); } }else{ childWidth = contentWidth; } final Insets margin = getMargin(child); if (margin != null) { childWidth += margin.getLeft() + margin.getRight(); childHeight += margin.getTop() + margin.getRight(); } layoutInArea(child, x, y, childWidth, childHeight, /* baseline shouldn't matter */0, margin, isFillWidth, true, hpos, vpos); y += child.getLayoutBounds().getHeight() + space; if (margin != null) { y += margin.getTop() + margin.getBottom(); } y = snapPosition(y); } performingLayout = false; }
Example 15
Source File: JFXAlertAnimation.java From JFoenix with Apache License 2.0 | 4 votes |
@Override public void initAnimation(Node contentContainer, Node overlay) { overlay.setOpacity(0); contentContainer.setTranslateX(contentContainer.getLayoutX() + contentContainer.getLayoutBounds().getMaxX()); }
Example 16
Source File: Splash.java From netbeans with Apache License 2.0 | 4 votes |
private void initTimeline() { timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); KeyFrame kf = new KeyFrame(Config.ANIMATION_TIME, new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (state == STATE_SHOW_TITLE) { stateArg++; int center = Config.SCREEN_WIDTH / 2; int offset = (int)(Math.cos(stateArg / 4.0) * (40 - stateArg) / 40 * center); brick.setTranslateX(center - brick.getImage().getWidth() / 2 + offset); breaker.setTranslateX(center - breaker.getImage().getWidth() / 2 - offset); if (stateArg == 40) { stateArg = 0; state = STATE_SHOW_STRIKE; } return; } if (state == STATE_SHOW_STRIKE) { if (stateArg == 0) { strike.setTranslateX(breaker.getTranslateX() + brick.getImage().getWidth()); strike.setScaleX(0); strike.setScaleY(0); strike.setVisible(true); } stateArg++; double coef = stateArg / 30f; brick.setTranslateX(breaker.getTranslateX() + (breaker.getImage().getWidth() - brick.getImage().getWidth()) / 2f * (1 - coef)); strike.setScaleX(coef); strike.setScaleY(coef); strike.setRotate((30 - stateArg) * 2); if (stateArg == 30) { stateArg = 0; state = STATE_SUN; } return; } // Here state == STATE_SUN if (pressanykey.getOpacity() < 1) { pressanykey.setOpacity(pressanykey.getOpacity() + 0.05f); } stateArg--; double x = SUN_AMPLITUDE_X * Math.cos(stateArg / 100.0); double y = SUN_AMPLITUDE_Y * Math.sin(stateArg / 100.0); if (y < 0) { for (Node node : NODES_SHADOWS) { // Workaround RT-1976 node.setTranslateX(-1000); } return; } double sunX = Config.SCREEN_WIDTH / 2 + x; double sunY = Config.SCREEN_HEIGHT / 2 - y; sun.setTranslateX(sunX - sun.getImage().getWidth() / 2); sun.setTranslateY(sunY - sun.getImage().getHeight() / 2); sun.setRotate(-stateArg); for (int i = 0; i < NODES.length; i++) { NODES_SHADOWS[i].setOpacity(y / SUN_AMPLITUDE_Y / 2); NODES_SHADOWS[i].setTranslateX(NODES[i].getTranslateX() + (NODES[i].getTranslateX() + NODES[i].getImage().getWidth() / 2 - sunX) / 20); NODES_SHADOWS[i].setTranslateY(NODES[i].getTranslateY() + (NODES[i].getTranslateY() + NODES[i].getImage().getHeight() / 2 - sunY) / 20); } } }); timeline.getKeyFrames().add(kf); }
Example 17
Source File: Splash.java From marathonv5 with Apache License 2.0 | 4 votes |
private void initTimeline() { timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); KeyFrame kf = new KeyFrame(Config.ANIMATION_TIME, new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (state == STATE_SHOW_TITLE) { stateArg++; int center = Config.SCREEN_WIDTH / 2; int offset = (int)(Math.cos(stateArg / 4.0) * (40 - stateArg) / 40 * center); brick.setTranslateX(center - brick.getImage().getWidth() / 2 + offset); breaker.setTranslateX(center - breaker.getImage().getWidth() / 2 - offset); if (stateArg == 40) { stateArg = 0; state = STATE_SHOW_STRIKE; } return; } if (state == STATE_SHOW_STRIKE) { if (stateArg == 0) { strike.setTranslateX(breaker.getTranslateX() + brick.getImage().getWidth()); strike.setScaleX(0); strike.setScaleY(0); strike.setVisible(true); } stateArg++; double coef = stateArg / 30f; brick.setTranslateX(breaker.getTranslateX() + (breaker.getImage().getWidth() - brick.getImage().getWidth()) / 2f * (1 - coef)); strike.setScaleX(coef); strike.setScaleY(coef); strike.setRotate((30 - stateArg) * 2); if (stateArg == 30) { stateArg = 0; state = STATE_SUN; } return; } // Here state == STATE_SUN if (pressanykey.getOpacity() < 1) { pressanykey.setOpacity(pressanykey.getOpacity() + 0.05f); } stateArg--; double x = SUN_AMPLITUDE_X * Math.cos(stateArg / 100.0); double y = SUN_AMPLITUDE_Y * Math.sin(stateArg / 100.0); if (y < 0) { for (Node node : NODES_SHADOWS) { // Workaround RT-1976 node.setTranslateX(-1000); } return; } double sunX = Config.SCREEN_WIDTH / 2 + x; double sunY = Config.SCREEN_HEIGHT / 2 - y; sun.setTranslateX(sunX - sun.getImage().getWidth() / 2); sun.setTranslateY(sunY - sun.getImage().getHeight() / 2); sun.setRotate(-stateArg); for (int i = 0; i < NODES.length; i++) { NODES_SHADOWS[i].setOpacity(y / SUN_AMPLITUDE_Y / 2); NODES_SHADOWS[i].setTranslateX(NODES[i].getTranslateX() + (NODES[i].getTranslateX() + NODES[i].getImage().getWidth() / 2 - sunX) / 20); NODES_SHADOWS[i].setTranslateY(NODES[i].getTranslateY() + (NODES[i].getTranslateY() + NODES[i].getImage().getHeight() / 2 - sunY) / 20); } } }); timeline.getKeyFrames().add(kf); }
Example 18
Source File: Splash.java From marathonv5 with Apache License 2.0 | 4 votes |
private void initTimeline() { timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); KeyFrame kf = new KeyFrame(Config.ANIMATION_TIME, new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (state == STATE_SHOW_TITLE) { stateArg++; int center = Config.SCREEN_WIDTH / 2; int offset = (int)(Math.cos(stateArg / 4.0) * (40 - stateArg) / 40 * center); brick.setTranslateX(center - brick.getImage().getWidth() / 2 + offset); breaker.setTranslateX(center - breaker.getImage().getWidth() / 2 - offset); if (stateArg == 40) { stateArg = 0; state = STATE_SHOW_STRIKE; } return; } if (state == STATE_SHOW_STRIKE) { if (stateArg == 0) { strike.setTranslateX(breaker.getTranslateX() + brick.getImage().getWidth()); strike.setScaleX(0); strike.setScaleY(0); strike.setVisible(true); } stateArg++; double coef = stateArg / 30f; brick.setTranslateX(breaker.getTranslateX() + (breaker.getImage().getWidth() - brick.getImage().getWidth()) / 2f * (1 - coef)); strike.setScaleX(coef); strike.setScaleY(coef); strike.setRotate((30 - stateArg) * 2); if (stateArg == 30) { stateArg = 0; state = STATE_SUN; } return; } // Here state == STATE_SUN if (pressanykey.getOpacity() < 1) { pressanykey.setOpacity(pressanykey.getOpacity() + 0.05f); } stateArg--; double x = SUN_AMPLITUDE_X * Math.cos(stateArg / 100.0); double y = SUN_AMPLITUDE_Y * Math.sin(stateArg / 100.0); if (y < 0) { for (Node node : NODES_SHADOWS) { // Workaround RT-1976 node.setTranslateX(-1000); } return; } double sunX = Config.SCREEN_WIDTH / 2 + x; double sunY = Config.SCREEN_HEIGHT / 2 - y; sun.setTranslateX(sunX - sun.getImage().getWidth() / 2); sun.setTranslateY(sunY - sun.getImage().getHeight() / 2); sun.setRotate(-stateArg); for (int i = 0; i < NODES.length; i++) { NODES_SHADOWS[i].setOpacity(y / SUN_AMPLITUDE_Y / 2); NODES_SHADOWS[i].setTranslateX(NODES[i].getTranslateX() + (NODES[i].getTranslateX() + NODES[i].getImage().getWidth() / 2 - sunX) / 20); NODES_SHADOWS[i].setTranslateY(NODES[i].getTranslateY() + (NODES[i].getTranslateY() + NODES[i].getImage().getHeight() / 2 - sunY) / 20); } } }); timeline.getKeyFrames().add(kf); }