Java Code Examples for javafx.scene.Node#setTranslateY()

The following examples show how to use javafx.scene.Node#setTranslateY() . 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 vote down vote up
/** 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 vote down vote up
/**
     * @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 3
Source File: ScatterPlot.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
/**
     * @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 vote down vote up
/**
     * @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 5
Source File: NodeMenuItem.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
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 6
Source File: FxIconBuilder.java    From FxDock with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
@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 vote down vote up
@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 vote down vote up
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: LoadingScreen.java    From FXTutorials with MIT License 5 votes vote down vote up
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 11
Source File: RadialSettingsMenuCenter.java    From RadialFx with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 12
Source File: JFXAlertAnimation.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setTranslateY(-(contentContainer.getLayoutY()
                                     + contentContainer.getLayoutBounds().getMaxY()));
}
 
Example 13
Source File: JFXAlertAnimation.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setTranslateY(contentContainer.getLayoutY()
                                   + contentContainer.getLayoutBounds().getMaxY());
}
 
Example 14
Source File: JFXNodesList.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@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;
}