Circle is centered
Command window:
C:\ece538\circuit3>java GroupTest mode 0 BoundsInLocal: xcen 0.00000 ycen 0.00000 width 4.10417 height 4.10417 BoundsInParent: xcen 0.00000 ycen 0.00000 width 0.410417 height 0.410417
Circle is de-centered, and the entire pattern moves away from center
Command window:
C:\ece538\circuit3>java GroupTest 1 mode 1 BoundsInLocal: xcen -0.922488 ycen 0.00000 width 4.25919 height 4.10417 BoundsInParent: xcen -0.922488 ycen 0.00000 width 0.425919 height 0.410417
Symmetric bounding rectangle added.
Command window:
C:\ece538\circuit3>java GroupTest 2 mode 2 BoundsInLocal: xcen 0.00000 ycen 0.00000 width 6.10417 height 4.10417 BoundsInParent: xcen 0.00000 ycen 0.00000 width 0.610417 height 0.410417
GroupTest.java
import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Group; import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.shape.*; import javafx.geometry.Bounds; import javafx.collections.*; import java.util.List; import java.lang.Math; public class GroupTest extends Application { public void start(Stage stage) { Group grp = new Group(); Scene scene = new Scene(grp, 400, 400); grp.setTranslateX(scene.getWidth()/2); grp.setTranslateY(scene.getHeight()/2); double res = 96; grp.setScaleX(res); grp.setScaleY(res); //grp.setRotate(10.0); Grid.draw(grp); List<String> args = getParameters().getRaw(); int mode = 0; if (args.size()>0) mode = Integer.parseInt(args.get(0)); System.out.println("mode " + mode); drawTest(grp,mode); stage.setTitle("Group Test"); stage.setScene(scene); stage.show(); } void show_elements(Group grp) { ObservableList<Node> ol = grp.getChildren(); for (Node n: ol) System.out.println(n); } void show_bounds(Group grp) { double xcen, ycen; Bounds b1 = grp.getBoundsInLocal(); //System.out.println("BoundsInLocal: " + b1); xcen = 0.5*(b1.getMinX()+b1.getMaxX()); ycen = 0.5*(b1.getMinY()+b1.getMaxY()); System.out.format("\nBoundsInLocal: xcen %g ycen %g width %g height %g\n", xcen, ycen, b1.getWidth(), b1.getHeight()); Bounds b2 = grp.getBoundsInParent(); xcen = 0.5*(b2.getMinX()+b2.getMaxX()); ycen = 0.5*(b2.getMinY()+b2.getMaxY()); //System.out.println("BoundsInParent: " + b2); System.out.format("BoundsInParent: xcen %g ycen %g width %g height %g\n", xcen, ycen, b2.getWidth(), b2.getHeight()); } void drawTest(Group parent, int mode) { Group grp = new Group(); double resc = 0.1; grp.setScaleX(resc); grp.setScaleY(resc); double res = parent.getScaleX(); Rectangle r = new Rectangle(-3,-2,6,4); r.setFill(null); r.setStrokeWidth(10/res); r.setStroke(Color.RED); if (mode>1) grp.getChildren().add(r); double xoff = 0.0; if (mode>0) xoff = -1.00; Circle cir= new Circle(xoff,0.0,2.0); cir.setFill(null); cir.setStrokeWidth(10/res); cir.setStroke(Color.BLACK); grp.getChildren().add(cir); ObservableList<Node> ol = grp.getChildren(); // mark origin with orange X Line g = new Line(-0.5,0.5,0.5,-0.5); g.setStroke(Color.ORANGE); g.setStrokeWidth(20/res); ol.add(g); g = new Line(-0.5,-0.5,0.5,0.5); g.setStroke(Color.ORANGE); g.setStrokeWidth(20/res); ol.add(g); parent.getChildren().add(grp); double xpos = 0.0, ypos = 0.0; grp.setTranslateX(xpos); grp.setTranslateY(-ypos); show_bounds(grp); } }
Maintained by John Loomis, updated Thu Feb 08 15:15:47 2018