Java Code Examples for javafx.scene.shape.Ellipse#getCenterX()

The following examples show how to use javafx.scene.shape.Ellipse#getCenterX() . 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: ShapeConverter.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public static String convertEllipse(final Ellipse ELLIPSE) {
    final StringBuilder fxPath = new StringBuilder();
    final double CENTER_X           = ELLIPSE.getCenterX() == 0 ? ELLIPSE.getRadiusX() : ELLIPSE.getCenterX();
    final double CENTER_Y           = ELLIPSE.getCenterY() == 0 ? ELLIPSE.getRadiusY() : ELLIPSE.getCenterY();
    final double RADIUS_X           = ELLIPSE.getRadiusX();
    final double RADIUS_Y           = ELLIPSE.getRadiusY();
    final double CONTROL_DISTANCE_X = RADIUS_X * KAPPA;
    final double CONTROL_DISTANCE_Y = RADIUS_Y * KAPPA;
    // Move to first point
    fxPath.append("M ").append(CENTER_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ");
    // 1. quadrant
    fxPath.append("C ").append(CENTER_X + CONTROL_DISTANCE_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ")
          .append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y - CONTROL_DISTANCE_Y).append(" ")
          .append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y).append(" ");
    // 2. quadrant
    fxPath.append("C ").append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y + CONTROL_DISTANCE_Y).append(" ")
          .append(CENTER_X + CONTROL_DISTANCE_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ")
          .append(CENTER_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ");
    // 3. quadrant
    fxPath.append("C ").append(CENTER_X - CONTROL_DISTANCE_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ")
          .append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y + CONTROL_DISTANCE_Y).append(" ")
          .append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y).append(" ");
    // 4. quadrant
    fxPath.append("C ").append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y - CONTROL_DISTANCE_Y).append(" ")
          .append(CENTER_X - CONTROL_DISTANCE_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ")
          .append(CENTER_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ");
    // Close path
    fxPath.append("Z");
    return fxPath.toString();
}
 
Example 2
Source File: Exercise_14_10.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Applicaton class
public void start(Stage primaryStage) {
	// Create a pane
	Pane pane = new Pane();

	// Create an ellipse and set its properties
	Ellipse ellipse = new Ellipse(75, 40, 50, 20);
	ellipse.setStroke(Color.BLACK);
	ellipse.setFill(Color.WHITE);

	// Create two Arcs and set their properties
	Arc arc1 = new Arc(ellipse.getCenterX(), 150, ellipse.getRadiusX(), 
		ellipse.getRadiusY(), 0, -180);
	arc1.setType(ArcType.OPEN);
	arc1.setFill(Color.WHITE);
	arc1.setStroke(Color.BLACK);

	Arc arc2 = new Arc(ellipse.getCenterX(), arc1.getCenterY(), 
		ellipse.getRadiusX(), ellipse.getRadiusY(), 0, 180);
	arc2.setType(ArcType.OPEN);
	arc2.setFill(Color.WHITE);
	arc2.setStroke(Color.BLACK);
	arc2.getStrokeDashArray().addAll(6.0, 21.0);

	// Create two lines and set thier properties
	Line line1 = new Line(ellipse.getCenterX() - ellipse.getRadiusX(), 
		ellipse.getCenterY(), ellipse.getCenterX() - ellipse.getRadiusX(),
		arc1.getCenterY());
	Line line2 = new Line((ellipse.getCenterX() - ellipse.getRadiusX()) + 
		ellipse.getRadiusX() * 2, ellipse.getCenterY(), 
		(ellipse.getCenterX() - ellipse.getRadiusX()) 
		+ ellipse.getRadiusX() * 2, arc1.getCenterY());

	// Place nodes in pane
	pane.getChildren().addAll(ellipse, arc1, arc2, line1, line2);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 150, 200);
	primaryStage.setTitle("Exercise_14_10"); // Set the stage title
	primaryStage.setScene(scene); // Place the scenen in the stage
	primaryStage.show(); // Display the stage
}
 
Example 3
Source File: Exercise_14_11.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
/** Return a circle of specified properties */
private Circle getCircle(Ellipse e) {
	Circle c = new Circle(e.getCenterX(), e.getCenterY(), 
		e.getRadiusY() - (e.getRadiusX() - e.getRadiusY()));
	return c;
}
 
Example 4
Source File: JFXToSVG.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
public SVGEllipseElement ellipseToSVGEllipse(final Ellipse ell, final SVGDocument doc) {
	final SVGEllipseElement elt = new SVGEllipseElement(ell.getCenterX(), ell.getCenterY(), ell.getRadiusX(), ell.getRadiusY(), doc);
	copyPropertiesToSVG(elt, ell);
	return elt;
}
 
Example 5
Source File: TestViewDot.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	pathBefore = duplicatePath(getPathView().getElements());
	final Ellipse dotView = getDotView();
	dotBefore = new Ellipse(dotView.getCenterX(), dotView.getCenterY(), dotView.getRadiusX(), dotView.getRadiusY());
}
 
Example 6
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Converts the given JavaFX {@link Ellipse} to a
 * {@link org.eclipse.gef.geometry.planar.Ellipse}.
 *
 * @param ellipse
 *            The JavaFX {@link Ellipse} to convert.
 * @return The newly created
 *         {@link org.eclipse.gef.geometry.planar.Ellipse} that describes
 *         the given {@link Ellipse}.
 */
public static org.eclipse.gef.geometry.planar.Ellipse toEllipse(
		Ellipse ellipse) {
	return new org.eclipse.gef.geometry.planar.Ellipse(
			ellipse.getCenterX() - ellipse.getRadiusX(),
			ellipse.getCenterY() - ellipse.getRadiusY(),
			ellipse.getRadiusX() + ellipse.getRadiusX(),
			ellipse.getRadiusY() + ellipse.getRadiusY());
}