src/app/OglyPane.java
/*
     * Create the circles used to build Ogly. Because CSS is used to style these circles, they are
     * assigned an id or style class where appropriate. The center point and radius for each circle
     * are set using bindings.
     */
Create the circles used to build Ogly. Because CSS is used to style these circles, they are
assigned an id or style class where appropriate. The center point and radius for each circle
are set using bindings.
Create the circles used to build Ogly . Because CSS is used to style these circles they are assigned an id or style class where appropriate . The center point and radius for each circle are set using bindings .
private void buildOgly() {
        head = new Circle();
        head.setId("head");
        head.radiusProperty().bind(m.headRadiusProperty());
        head.centerXProperty().bind(oglyPane.widthProperty().divide(2));
        head.centerYProperty().bind(oglyPane.heightProperty().divide(2));
        leftEye = new Circle();
        leftEye.getStyleClass().add("eye");
        leftEye.radiusProperty().bind(m.eyeRadiusProperty());
        leftEye.centerXProperty().bind(head.centerXProperty().subtract(m.eyeSpacingProperty().divide(2)));
        leftEye.centerYProperty().bind(head.centerYProperty().subtract(m.eyeHeightProperty()));
        rightEye = new Circle();
        rightEye.getStyleClass().add("eye");
        rightEye.radiusProperty().bind(m.eyeRadiusProperty());
        rightEye.centerXProperty().bind(head.centerXProperty().add(m.eyeSpacingProperty().divide(2)));
        rightEye.centerYProperty().bind(head.centerYProperty().subtract(m.eyeHeightProperty()));
        leftPupil = new Circle();
        leftPupil.getStyleClass().add("pupil");
        leftPupil.radiusProperty().bind(m.pupilRadiusProperty());
        leftPupil.setCenterX(leftEye.getCenterX());
        leftPupil.setCenterY(leftEye.getCenterY());
        rightPupil = new Circle();
        rightPupil.getStyleClass().add("pupil");
        rightPupil.radiusProperty().bind(m.pupilRadiusProperty());
        rightPupil.setCenterX(rightEye.getCenterX());
        rightPupil.setCenterY(rightEye.getCenterY());
        leftEye.centerXProperty().addListener((object, oldValue, newValue) -> {
            leftPupil.setCenterX(newValue.doubleValue());
        });
        leftEye.centerYProperty().addListener((object, oldValue, newValue) -> {
            leftPupil.setCenterY(newValue.doubleValue());
        });
        rightEye.centerXProperty().addListener((object, oldValue, newValue) -> {
            rightPupil.setCenterX(newValue.doubleValue());
        });
        rightEye.centerYProperty().addListener((object, oldValue, newValue) -> {
            rightPupil.setCenterY(newValue.doubleValue());
        });
        oglyPane.getChildren().addAll(head, leftEye, rightEye, leftPupil, rightPupil);
    }
private void buildOgly ( ) { head = new Circle ( ) ; head . setId ( "head" ) ; head . radiusProperty ( ) . bind ( m . headRadiusProperty ( ) ) ; head . centerXProperty ( ) . bind ( oglyPane . widthProperty ( ) . divide ( 2 ) ) ; head . centerYProperty ( ) . bind ( oglyPane . heightProperty ( ) . divide ( 2 ) ) ; leftEye = new Circle ( ) ; leftEye . getStyleClass ( ) . add ( "eye" ) ; leftEye . radiusProperty ( ) . bind ( m . eyeRadiusProperty ( ) ) ; leftEye . centerXProperty ( ) . bind ( head . centerXProperty ( ) . subtract ( m . eyeSpacingProperty ( ) . divide ( 2 ) ) ) ; leftEye . centerYProperty ( ) . bind ( head . centerYProperty ( ) . subtract ( m . eyeHeightProperty ( ) ) ) ; rightEye = new Circle ( ) ; rightEye . getStyleClass ( ) . add ( "eye" ) ; rightEye . radiusProperty ( ) . bind ( m . eyeRadiusProperty ( ) ) ; rightEye . centerXProperty ( ) . bind ( head . centerXProperty ( ) . add ( m . eyeSpacingProperty ( ) . divide ( 2 ) ) ) ; rightEye . centerYProperty ( ) . bind ( head . centerYProperty ( ) . subtract ( m . eyeHeightProperty ( ) ) ) ; leftPupil = new Circle ( ) ; leftPupil . getStyleClass ( ) . add ( "pupil" ) ; leftPupil . radiusProperty ( ) . bind ( m . pupilRadiusProperty ( ) ) ; leftPupil . setCenterX ( leftEye . getCenterX ( ) ) ; leftPupil . setCenterY ( leftEye . getCenterY ( ) ) ; rightPupil = new Circle ( ) ; rightPupil . getStyleClass ( ) . add ( "pupil" ) ; rightPupil . radiusProperty ( ) . bind ( m . pupilRadiusProperty ( ) ) ; rightPupil . setCenterX ( rightEye . getCenterX ( ) ) ; rightPupil . setCenterY ( rightEye . getCenterY ( ) ) ; leftEye . centerXProperty ( ) . addListener ( ( object , oldValue , newValue ) -> { leftPupil . setCenterX ( newValue . doubleValue ( ) ) ; } ) ; leftEye . centerYProperty ( ) . addListener ( ( object , oldValue , newValue ) -> { leftPupil . setCenterY ( newValue . doubleValue ( ) ) ; } ) ; rightEye . centerXProperty ( ) . addListener ( ( object , oldValue , newValue ) -> { rightPupil . setCenterX ( newValue . doubleValue ( ) ) ; } ) ; rightEye . centerYProperty ( ) . addListener ( ( object , oldValue , newValue ) -> { rightPupil . setCenterY ( newValue . doubleValue ( ) ) ; } ) ; oglyPane . getChildren ( ) . addAll ( head , leftEye , rightEye , leftPupil , rightPupil ) ; }
Create the circles used to build Ogly.
Create the circles used to build Ogly .
// The center of the head is bound to the center of the pane. // This will cause the head to move when the stage is resized. // The eyes are positioned using the center of the head, the eye spacing and eye height. // We can't bind the center of the pupils because we need to be able to set them directly. // Because the centers of the pupils are not bound to the centers of the eyes, // we add listeners that update them manually whenever the eyes change position. // This is needed to make the pupils move with the eyes when the stage is resized. // Finally, add all the circles to the pane in the right order.