Java Code Examples for javafx.scene.shape.Rectangle#getWidth()

The following examples show how to use javafx.scene.shape.Rectangle#getWidth() . 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: ImagePanel.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
void adjust_rectangle_properties(double starting_point_x, double starting_point_y, double ending_point_x,
        double ending_point_y, Rectangle given_rectangle) {
    given_rectangle.setX(starting_point_x);
    given_rectangle.setY(starting_point_y);
    given_rectangle.setWidth(ending_point_x - starting_point_x);
    given_rectangle.setHeight(ending_point_y - starting_point_y);

    if (given_rectangle.getWidth() < 0) {
        given_rectangle.setWidth(-given_rectangle.getWidth());
        given_rectangle.setX(given_rectangle.getX() - given_rectangle.getWidth());
    }

    if (given_rectangle.getHeight() < 0) {
        given_rectangle.setHeight(-given_rectangle.getHeight());
        given_rectangle.setY(given_rectangle.getY() - given_rectangle.getHeight());
    }
}
 
Example 2
Source File: Sprite.java    From Aidos with GNU General Public License v3.0 6 votes vote down vote up
public Sprite(Entity e,int actualSize,double playSpeed,Image spriteSheet,List<Rectangle> specifications,double width, double height,int scale, boolean leftToRight){
    super();
    this.actualSize = actualSize;
    this.playSpeed = playSpeed;
    this.numberOfFrames=specifications.size();
    this.width = width;
    this.height = height;
    this.scale = scale;
    resersePlay = leftToRight;
    this.entityReference=e;
    hasValidSpriteImages=true;
    spriteImages=new Image[specifications.size()];
    for (int i = 0; i < specifications.size(); i++) {
        Rectangle specification = specifications.get(i);
        int x=(int)specification.getX();
        int y=(int)specification.getY();
        int w=(int)specification.getWidth();
        int h=(int)specification.getHeight();

        //To DO Check dimensions provided are not going out of spritesheet dimensions\
        spriteImages[i]=ImageUtils.crop(spriteSheet, x, y, w, h);
    }
}
 
Example 3
Source File: Helper.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
public static final Point[] smoothSparkLine(final List<Double> DATA_LIST, final double MIN_VALUE, final double MAX_VALUE, final Rectangle GRAPH_BOUNDS, final int NO_OF_DATAPOINTS) {
    int     size   = DATA_LIST.size();
    Point[] points = new Point[size];

    double low  = Statistics.getMin(DATA_LIST);
    double high = Statistics.getMax(DATA_LIST);
    if (Helper.equals(low, high)) {
        low  = MIN_VALUE;
        high = MAX_VALUE;
    }
    double range = high - low;

    double minX  = GRAPH_BOUNDS.getX();
    double maxX  = minX + GRAPH_BOUNDS.getWidth();
    double minY  = GRAPH_BOUNDS.getY();
    double maxY  = minY + GRAPH_BOUNDS.getHeight();
    double stepX = GRAPH_BOUNDS.getWidth() / (NO_OF_DATAPOINTS - 1);
    double stepY = GRAPH_BOUNDS.getHeight() / range;

    for (int i = 0 ; i < size ; i++) {
        points[i] = new Point(minX + i * stepX, maxY - Math.abs(low - DATA_LIST.get(i)) * stepY);
    }

    return Helper.subdividePoints(points, 16);
}
 
Example 4
Source File: ConicalGradient.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public ImagePattern getImagePattern(final Rectangle BOUNDS) {
    double x      = BOUNDS.getX();
    double y      = BOUNDS.getY();
    double width  = BOUNDS.getWidth();
    double height = BOUNDS.getHeight();
    centerX       = width * 0.5;
    centerY       = height * 0.5;
    return new ImagePattern(getImage(width, height), x, y, width, height, false);
}
 
Example 5
Source File: ConicalGradient.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public ImagePattern getImagePattern(final Rectangle BOUNDS) {
    double x      = BOUNDS.getX();
    double y      = BOUNDS.getY();
    double width  = BOUNDS.getWidth();
    double height = BOUNDS.getHeight();
    centerX       = width * 0.5;
    centerY       = height * 0.5;
    return new ImagePattern(getImage(width, height), x, y, width, height, false);
}
 
Example 6
Source File: ConicalGradient.java    From regulators with Apache License 2.0 5 votes vote down vote up
public ImagePattern getImagePattern(final Rectangle BOUNDS) {
    double x      = BOUNDS.getX();
    double y      = BOUNDS.getY();
    double width  = BOUNDS.getWidth();
    double height = BOUNDS.getHeight();
    centerX       = width * 0.5;
    centerY       = height * 0.5;
    return new ImagePattern(getImage(width, height), x, y, width, height, false);
}
 
Example 7
Source File: Exercise_14_23.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Returns true if one rectangle is inside the other */
public boolean contains(Rectangle r1, Rectangle r2) {
	return 
		r2.getY() + r2.getHeight() <= r1.getY() + r1.getHeight() && 
		r2.getX() + r2.getWidth() <= r1.getX() + r1.getWidth() && 
		r2.getX() > r1.getX() && r2.getY() > r1.getY();
}
 
Example 8
Source File: Exercise_14_23.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Returns true if the specified rectangles overlap */
public boolean overlaps(Rectangle r1, Rectangle r2) {
	return getDistance(r1.getX(), r2.getX() + r2.getWidth()) < 
		r1.getWidth() + r2.getWidth() &&
		getDistance(r1.getY(), r2.getY() + r2.getHeight()) <
		r1.getHeight() + r2.getHeight();
			 
}
 
Example 9
Source File: DynamicAnchorSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();
	Scene scene = new Scene(root, 400, 400);

	r1 = new Rectangle(50, 50);
	r1.setFill(Color.RED);
	r1.relocate(100, 100);
	r2 = new Rectangle(50, 50);
	r2.setFill(Color.BLUE);
	r2.relocate(200, 200);
	final Line l = new Line();
	l.setStroke(Color.BLACK);

	DynamicAnchor startAnchor = new DynamicAnchor(r1);
	DynamicAnchor endAnchor = new DynamicAnchor(r2);
	final AnchorKey startKey = new AnchorKey(l, "start");
	final AnchorKey endKey = new AnchorKey(l, "end");

	// update start and end point in case provided position values change
	MapChangeListener<AnchorKey, Point> changeListener = new MapChangeListener<AnchorKey, Point>() {

		@Override
		public void onChanged(
				MapChangeListener.Change<? extends AnchorKey, ? extends Point> change) {
			if (change.getKey().equals(startKey)) {
				l.setStartX(change.getMap().get(startKey).x);
				l.setStartY(change.getMap().get(startKey).y);
			}
			if (change.getKey().equals(endKey)) {
				l.setEndX(change.getMap().get(endKey).x);
				l.setEndY(change.getMap().get(endKey).y);
			}
		}
	};

	startAnchor.positionsUnmodifiableProperty().addListener(changeListener);
	endAnchor.positionsUnmodifiableProperty().addListener(changeListener);

	Point r1Center = new Point(
			r1.getLayoutBounds().getMinX() + r1.getLayoutX()
					+ r1.getWidth() / 2,
			r1.getLayoutBounds().getMinY() + r1.getLayoutY()
					+ r1.getHeight() / 2);
	Point r2Center = new Point(
			r2.getLayoutBounds().getMinX() + r2.getLayoutX()
					+ r2.getWidth() / 2,
			r2.getLayoutBounds().getMinY() + r2.getLayoutY()
					+ r2.getHeight() / 2);

	// use static values for dynamic anchor reference points
	startAnchor.getComputationParameter(startKey,
			AnchoredReferencePoint.class).set(r2Center);
	startAnchor.attach(startKey);
	endAnchor.getComputationParameter(endKey,
			AnchoredReferencePoint.class).set(r1Center);
	endAnchor.attach(endKey);

	Group g = new Group(r1, r2, l);
	root.getChildren().add(g);

	return scene;
}
 
Example 10
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Converts the given JavaFX {@link Rectangle} to a
 * {@link org.eclipse.gef.geometry.planar.RoundedRectangle}.
 *
 * @param rect
 *            The JavaFX {@link Rectangle} to convert.
 * @return The newly created
 *         {@link org.eclipse.gef.geometry.planar.RoundedRectangle} that
 *         describes the given {@link Rectangle}.
 */
public static org.eclipse.gef.geometry.planar.RoundedRectangle toRoundedRectangle(
		Rectangle rect) {
	return new org.eclipse.gef.geometry.planar.RoundedRectangle(
			rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),
			rect.getArcWidth(), rect.getArcHeight());
}
 
Example 11
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Converts the given JavaFX {@link Rectangle} to a
 * {@link org.eclipse.gef.geometry.planar.Rectangle}. Note, that the
 * arc-width and arc-height of the given {@link Rectangle} will not be
 * preserved in the resulting geometry.
 *
 * @param rect
 *            The JavaFX {@link Rectangle} to convert.
 * @return The newly created
 *         {@link org.eclipse.gef.geometry.planar.Rectangle} that describes
 *         the given {@link Rectangle} (without its arc-width and
 *         arc-height).
 */
public static org.eclipse.gef.geometry.planar.Rectangle toRectangle(
		Rectangle rect) {
	return new org.eclipse.gef.geometry.planar.Rectangle(rect.getX(),
			rect.getY(), rect.getWidth(), rect.getHeight());
}