Home » Eclipse Projects » GEF » JavaFX Line vs GEF Geometry Line
JavaFX Line vs GEF Geometry Line [message #1793209] |
Wed, 01 August 2018 14:11 |
Shenwei Zheng Messages: 22 Registered: December 2016 |
Junior Member |
|
|
Hello,
I noticed the difference between JavaFX Line and GEF Gepmetry Line (please see the attachment).
As defined in my example, both lines have a width of 10 pixel and a lenght of 200 pixel. The GEF Geometry line has the background color red. When both lines are drawn. The GEF Geometry line including the red part is much longer than JavaFX line, which is exactly 200 pixel.
The actual width of GEF Geometry Line is longer than defined 200 pixel when it has the width of 10 pixel. Is it desired?
Since the actual length of GEF Geometry Line depends on the width, it is difficult for me to layout other elements manually. Is it possible to draw a GEF Geometry line like a JavaFX line withou additional part? Thank you.
Best Regards
Shenwei
[Updated on: Wed, 01 August 2018 14:12] Report message to a moderator
|
|
|
Re: JavaFX Line vs GEF Geometry Line [message #1793356 is a reply to message #1793209] |
Mon, 06 August 2018 11:51 |
|
Hi Shenwei,
actually, they should be equal in visualisation by default. However, the visualisation depends on different style settings, i.e. stroke-width, stroke-line-cap, etc.
If you configure a JavaFX Line and a GEF GeometryNode in the same way, then they should really be rendered identically.
You can try this out easily, e.g.:
public class JFXLineVsGEFLine extends AbstractFxExample {
public static void main(final String[] args) {
Application.launch(args);
}
public JFXLineVsGEFLine() {
super("JFX vs. GEF Geom");
}
private void addLines(Pane root, double y, boolean changeLineCap) {
Line jfxline = new Line(50, y, 200, y);
jfxline.setStrokeWidth(10);
org.eclipse.gef.geometry.planar.Line linegeom = new org.eclipse.gef.geometry.planar.Line(
50, y + 15, 200, y + 15);
GeometryNode<org.eclipse.gef.geometry.planar.Line> gefline = new GeometryNode<>(
linegeom);
gefline.setStrokeWidth(10);
if (changeLineCap) {
gefline.setStrokeLineCap(StrokeLineCap.BUTT);
}
root.getChildren().addAll(jfxline, gefline);
}
@Override
public Scene createScene() {
Pane root = new Pane();
addLines(root, 50, false);
addLines(root, 100, true);
return new Scene(root, 400, 300);
}
}
Here, the second pair of lines is differently configured w.r.t. stroke-line-cap, resulting in the behaviour that you observe. I believe something similar is happening in your case.
Best regards,
Matthias
|
|
|
Re: JavaFX Line vs GEF Geometry Line [message #1793392 is a reply to message #1793356] |
Tue, 07 August 2018 12:06 |
Shenwei Zheng Messages: 22 Registered: December 2016 |
Junior Member |
|
|
Hi Matthias,
thank you for your reply!
Although we can get the identical visuals by using the same style (set stroke line cap to BUTT and it looks like there is no difference), I noticed that the actual length of gef line is in your example is 160 but the javafx line is 150. The backgroud in gef line is also considered as a part of its length. Which means the actual gef line is 160 and the visible part is 150.
I tried to draw a rectangle direct after the lines. But there is a undesired gap between the gef line and the rectangle (see the attachment). Also the height (boundsInParent) of gef line is 11 not as defined 10. Is it a bug ? If not, what is the advantage? Thank you.
jfxline's bounds in local: BoundingBox [minX:50.0, minY:95.0, minZ:0.0, width:150.0, height:10.0, depth:0.0, maxX:200.0, maxY:105.0, maxZ:0.0]
gefline's bounds in local: BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:160.0, height:10.0, depth:0.0, maxX:160.0, maxY:10.0, maxZ:0.0]
jfxline's bounds in parent: BoundingBox [minX:50.0, minY:95.0, minZ:0.0, width:150.0, height:10.0, depth:0.0, maxX:200.0, maxY:105.0, maxZ:0.0]
gefline's bounds in parent: BoundingBox [minX:45.0, minY:109.5, minZ:0.0, width:160.0, height:11.0, depth:0.0, maxX:205.0, maxY:120.5, maxZ:0.0]
You can try out the following code, which is changed based on your example.
public class JFXLineVsGEFLine extends Application
{
public static void main(final String[] args)
{
Application.launch(args);
}
private Line jfxline;
private GeometryNode<org.eclipse.gef.geometry.planar.Line> gefline;
private Rectangle rectangleAftergefline;
private Rectangle rectangleAfterjfxline;
private void addLines(Pane root, double y, boolean changeLineCap)
{
jfxline = new Line(50, y, 200, y);
jfxline.setStrokeWidth(10);
org.eclipse.gef.geometry.planar.Line linegeom = new org.eclipse.gef.geometry.planar.Line(50, y + 15, 200, y + 15);
gefline = new GeometryNode<>(linegeom);
gefline.setStrokeWidth(10);
if (changeLineCap)
{
jfxline.setStrokeLineCap(StrokeLineCap.BUTT);
gefline.setStrokeLineCap(StrokeLineCap.BUTT);
gefline.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
}
root.getChildren().addAll(jfxline, gefline);
}
private void addButton(Pane root)
{
TextArea textArea = new TextArea();
textArea.setMinWidth(800);
textArea.setTranslateY(200);
Button button1 = new Button("print dimension of lines");
button1.setOnAction(new javafx.event.EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("jfxline's bounds in local: " + jfxline.getLayoutBounds());
System.out.println("gefline's bounds in local: " + gefline.getLayoutBounds());
System.out.println("jfxline's bounds in parent: " + jfxline.getBoundsInParent());
System.out.println("gefline's bounds in parent: " + gefline.getBoundsInParent());
textArea.setText("jfxline's bounds in local: " + jfxline.getLayoutBounds() + "\n" + "gefline's bounds in local: " + gefline.getLayoutBounds() + "\n\n" + "jfxline's bounds in parent: " + jfxline.getBoundsInParent() + "\n"
+ "gefline's bounds in parent: " + gefline.getBoundsInParent());
}
});
Button button2 = new Button("add rectangle after lines");
button2.setTranslateX(180);
button2.setOnAction(new javafx.event.EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
double width = 80;
double height = 20;
rectangleAftergefline = new Rectangle(width, height, Color.GREEN);
rectangleAftergefline.setTranslateX(gefline.getGeometry().getX1() + gefline.getWidth());
rectangleAftergefline.setTranslateY(gefline.getGeometry().getY1());
if (!root.getChildren().contains(rectangleAftergefline))
{
root.getChildren().add(rectangleAftergefline);
}
rectangleAfterjfxline = new Rectangle(width, height, Color.GREEN);
rectangleAfterjfxline.setTranslateX(jfxline.getStartX() + jfxline.getBoundsInLocal().getWidth());
rectangleAfterjfxline.setTranslateY(jfxline.getStartY() - height);
if (!root.getChildren().contains(rectangleAfterjfxline))
{
root.getChildren().add(rectangleAfterjfxline);
}
}
});
root.getChildren().addAll(button1, button2, textArea);
}
@Override
public void start(Stage primaryStage) throws Exception
{
Pane root = new Pane();
root.setBackground(new Background(new BackgroundFill(Color.CYAN, CornerRadii.EMPTY, Insets.EMPTY)));
// addLines(root, 50, false);
addLines(root, 100, true);
addButton(root);
primaryStage.setTitle("JFX vs. GEF Geom");
primaryStage.setScene(new Scene(root, 800, 300));
primaryStage.show();
}
Bests
Shenwei
[Updated on: Tue, 07 August 2018 14:37] Report message to a moderator
|
|
|
Re: JavaFX Line vs GEF Geometry Line [message #1793611 is a reply to message #1793392] |
Sat, 11 August 2018 15:23 |
|
Hi Shenwei,
thank you for the detailed response! We should ensure that only the visualisation contributes to the bounds, so that it correctly reports 150 in your case. Also, the height looks wrong, it should probably be exactly 10. Would you create a Bugzilla, please?
The difference in bounds-in-local is okay IMHO.
Best regards,
Matthias
|
|
| |
Goto Forum:
Current Time: Fri Dec 06 07:41:23 GMT 2024
Powered by FUDForum. Page generated in 0.03388 seconds
|