Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » JavaFX + GEF5: Trouble with display of Pie(The display of a Pie element in a javafx scene seems wrong)
JavaFX + GEF5: Trouble with display of Pie [message #1764542] Wed, 31 May 2017 07:01 Go to next message
Carsten Meyer is currently offline Carsten MeyerFriend
Messages: 1
Registered: May 2017
Junior Member
I tried to position a GEF5 Pie inside a circle so that the pie's arc matches the circle's arc.

After some experimenting I discovered that the pie's display size does not match it's bounding box as shown below:
index.php/fa/29487/0/


The code below creates two test pies (one with a surrounding circle and another without):

package de.simutek.schema.visuals;

import org.eclipse.gef.fx.nodes.GeometryNode;
import org.eclipse.gef.geometry.euclidean.Angle;
import org.eclipse.gef.geometry.planar.Ellipse;
import org.eclipse.gef.geometry.planar.Pie;
import org.eclipse.gef.geometry.planar.PolyBezier;
import org.eclipse.gef.geometry.planar.Rectangle;

import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;

public class TestNodeVisual extends Region {


	private Group shape;
	private Group shape1;
	
	public TestNodeVisual() {
		// create background shape
		shape = getPumpSymbol(); 
		shape.setTranslateX(50);
		shape.setTranslateY(50);

		shape1 = getPumpSymbol_1();
		shape1.setTranslateX(250);
		shape1.setTranslateY(250);

		// wrap shape and shape1 in a Group so that their bounds-in-parent is
		// considered when determining the layout-bounds of this visual
		getChildren().addAll(shape, shape1);
	}

	/**
	 * Create a simple pie.
	 * 
	 * Show the bounding boxes by their background color. 
	 */
	private Group getPumpSymbol() {

		Pie p = new Pie(0d, 0d, 100d, 100d, Angle.fromDeg(225), Angle.fromDeg(90));
		Rectangle rect = p.getBounds();
		System.out.println("Pie bounds are      : " + rect);
		
		PolyBezier pbz = p.getOutline();
		System.out.println("Pie PolyBezier      : " + pbz);

		GeometryNode<Pie> pTest = new GeometryNode<Pie>(p);
		pTest.setPadding(new Insets(0d));
		pTest.setBackground(new Background(new BackgroundFill(Color.LIGHTGREEN, CornerRadii.EMPTY, new Insets(0))));
		
		System.out.println("Geom<Pie> bounds: " + pTest.getBoundsInLocal());

		AnchorPane box = new AnchorPane();
		box.getChildren().addAll(pTest);
		box.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, new Insets(0))));
		
		return new Group(box);
	}

	/**
	 * Create a simple pie inside a larger circle. Position pie so that
	 * the arc matches the underlying circle. 
	 * 
	 * Show the bounding boxes by their background color. 
	 */
	private Group getPumpSymbol_1() {

		GeometryNode<Ellipse> e = new GeometryNode<Ellipse>( new Ellipse(0d, 0d, 100d, 100d));
		e.setPadding(new Insets(0d));
		e.setFill(Color.ANTIQUEWHITE);
		e.setStroke(Color.BLACK);
		e.setStrokeWidth(0.5);
		
		AnchorPane.setLeftAnchor(e, 0d);
		AnchorPane.setTopAnchor(e, 0d);

		Pie p = new Pie(0d, 0d, 100d, 100d, Angle.fromDeg(225), Angle.fromDeg(90));
		Rectangle rect = p.getBounds();
		System.out.println("Pie_1 bounds      : " + rect);

		PolyBezier pbz = p.getOutline();
		System.out.println("Pie_1 PolyBezier  : " + pbz);
		
		GeometryNode<Pie> pTest = new GeometryNode<Pie>(p);
		pTest.setPadding(new Insets(0d));
		pTest.setBackground(new Background(new BackgroundFill(Color.LIGHTGREEN, CornerRadii.EMPTY, new Insets(0))));

		System.out.println("Geom<Pie_1> bounds: " + pTest.getBoundsInLocal());

		AnchorPane.setLeftAnchor(pTest, rect.getX());
		AnchorPane.setTopAnchor(pTest, rect.getY());

		AnchorPane box = new AnchorPane();
		box.getChildren().addAll(e, pTest);
		box.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, new Insets(0))));
		
		return new Group(box);
	}

}


This test visual is the shown in a javafx scene by the following code:
package de.simutek.schema.visuals;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class SchemaVisualApplication extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Pane root = new Pane();

        // create state visuals
        TestNodeVisual node = new TestNodeVisual();
        node.relocate(50, 50);

        root.getChildren().addAll(node);

        primaryStage.setResizable(true);
        primaryStage.setScene(new Scene(root, 1024, 768));
        primaryStage.setTitle("This is an JavaFX Environment Test");
        primaryStage.sizeToScene();
        primaryStage.show();
    }
}


My tests indicate that from the GEF5 side the pie's bounding box and the pie's PolyBezier curve seem to contain correct data.

Can someone give me a hint wether I'm missing something in my code or wether it's a problem with favafx/gef5.

(The Manifest.mf containing the dependencies is attached to this post.)
Re: JavaFX + GEF5: Trouble with display of Pie [message #1764915 is a reply to message #1764542] Sat, 03 June 2017 14:44 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Carsten,

I can reproduce the issue and am currently looking into it. Feel free to add your findings to the Bugzilla ticket that I created to keep track of the issue [1]. Also, if you find more such errors, please report them at the Bugzilla [2]. Of course, you can always ask for help in the forums first, if you are unsure.

For the time being, you can use the outline of the Pie for rendering:
package my.ba.bezier.offset;

import org.eclipse.gef.fx.nodes.GeometryNode;
import org.eclipse.gef.geometry.euclidean.Angle;
import org.eclipse.gef.geometry.planar.Ellipse;
import org.eclipse.gef.geometry.planar.IGeometry;
import org.eclipse.gef.geometry.planar.Pie;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class PieSample extends Application {
	public static void main(String[] args) {
		launch();
	}
	@Override
	public void start(Stage primaryStage) throws Exception {
		Pane root = new Pane();
		Scene scene = new Scene(root, 400, 400);
		GeometryNode<IGeometry> ellipse = new GeometryNode<>(new Ellipse(0, 0, 100, 100));

		GeometryNode<IGeometry> pie = new GeometryNode<>(new Pie(0, 0, 100, 100, Angle.fromDeg(45), Angle.fromDeg(120)).getOutline());

		ellipse.setStroke(Color.TRANSPARENT);
		ellipse.setFill(new Color(0.5, 0.5, 0.5, 0.5));
		pie.setStroke(Color.TRANSPARENT);
		pie.setFill(new Color(1, 0, 0, 0.5));
		root.getChildren().addAll(ellipse, pie);
		primaryStage.setScene(scene);
		primaryStage.sizeToScene();
		primaryStage.show();
	}
}


https://bugs.eclipse.org/bugs/attachment.cgi?id=268737

Best regards,
Matthias

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=517770
[2] https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GEF

[Updated on: Sat, 03 June 2017 15:04]

Report message to a moderator

Previous Topic:GEF 3.11 is not working in eclipse DS-5 5.26.2
Next Topic:JavaFX + GEF5 + E4 RCP Application troubles
Goto Forum:
  


Current Time: Thu Apr 18 05:47:34 GMT 2024

Powered by FUDForum. Page generated in 0.02023 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top