javafx.scene.Node#setTranslateX ( )源码实例Demo

下面列出了javafx.scene.Node#setTranslateX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FxDock   文件: FxIconBuilder.java
/** 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);
}
 
源代码2 项目: FXyzLib   文件: ScatterPlot.java
/**
     * @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);
        }        
    }
 
源代码3 项目: FXyzLib   文件: ScatterPlot.java
/**
     * @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);
        }        
    }
 
源代码4 项目: FXyzLib   文件: ScatterPlot.java
/**
     * @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);
        }       
    }
 
源代码5 项目: PDF4Teachers   文件: NodeMenuItem.java
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);
}
 
源代码6 项目: FxDock   文件: FxIconBuilder.java
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);
}
 
源代码7 项目: gluon-samples   文件: MapPresenter.java
@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);
    }
}
 
源代码8 项目: maps   文件: PoiLayer.java
@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());
    }
}
 
源代码9 项目: mars-sim   文件: MainMenu.java
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();

}
 
源代码10 项目: FXTutorials   文件: FroggerApp.java
private void onUpdate() {
    for (Node car : cars)
        car.setTranslateX(car.getTranslateX() + Math.random() * 10);

    if (Math.random() < 0.075) {
        cars.add(spawnCar());
    }

    checkState();
}
 
源代码11 项目: FXTutorials   文件: LoadingScreen.java
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);
}
 
源代码12 项目: RadialFx   文件: RadialSettingsMenuCenter.java
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);
   }
 
源代码13 项目: marathonv5   文件: Splash.java
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);
}
 
源代码14 项目: marathonv5   文件: Splash.java
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);
}
 
源代码15 项目: netbeans   文件: Splash.java
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);
}
 
源代码16 项目: JFoenix   文件: JFXAlertAnimation.java
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setTranslateX(-(contentContainer.getLayoutX()
                                     + contentContainer.getLayoutBounds().getMaxX()));
}
 
源代码17 项目: JFoenix   文件: JFXAlertAnimation.java
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setTranslateX(contentContainer.getLayoutX()
                                   + contentContainer.getLayoutBounds().getMaxX());
}
 
源代码18 项目: JFoenix   文件: JFXNodesList.java
@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;
}