Java Code Examples for javafx.geometry.Point2D

The following examples show how to use javafx.geometry.Point2D. These examples are extracted from open source projects. 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 Project: arma-dialog-creator   Source File: ADCCanvasView.java    License: MIT License 7 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	//use this so that when the mouse moves over the canvas and something in canvas controls has focus, the key presses
	//and mouse events are sent to the canvas rather than the focuses control
	canvasView.focusToCanvas(event.getTarget() == canvasView.uiCanvasEditor.getCanvas());

	double sceneX = event.getSceneX();
	double sceneY = event.getSceneY();
	for (Node node : canvasView.notificationPane.getContentPane().getChildren()) {
		Point2D point2D = node.sceneToLocal(sceneX, sceneY);
		if (node.contains(point2D)) {
			canvasView.notificationPane.getContentPane().setMouseTransparent(false);
			return;
		}
	}
	canvasView.notificationPane.getContentPane().setMouseTransparent(true);

}
 
Example 2
Source Project: FXTutorials   Source File: BejeweledApp.java    License: MIT License 6 votes vote down vote up
public Jewel(Point2D point) {
    circle.setCenterX(SIZE / 2);
    circle.setCenterY(SIZE / 2);
    circle.setFill(colors[new Random().nextInt(colors.length)]);

    setTranslateX(point.getX() * SIZE);
    setTranslateY(point.getY() * SIZE);
    getChildren().add(circle);

    setOnMouseClicked(event -> {
        if (selected == null) {
            selected = this;
        }
        else {
            swap(selected, this);
            checkState();
            selected = null;
        }
    });
}
 
Example 3
Source Project: phoebus   Source File: TabsRepresentation.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** Compute 'insets'
 *
 *  <p>Determines where the tabs' content Pane
 *  is located relative to the bounds of the TabPane
 */
private void computeInsets()
{
    // Called with delay by refreshHack, may be invoked when already disposed
    if (jfx_node == null)
        return;
    // There is always at least one tab. All tabs have the same size.
    final Pane pane = (Pane)jfx_node.getTabs().get(0).getContent();
    final Point2D tabs_bounds = jfx_node.localToScene(0.0, 0.0);
    final Point2D pane_bounds = pane.localToScene(0.0, 0.0);
    final int[] insets = new int[] { (int)(pane_bounds.getX() - tabs_bounds.getX()),
            (int)(pane_bounds.getY() - tabs_bounds.getY()) };
    // logger.log(Level.INFO, "Insets: " + Arrays.toString(insets));
    if (insets[0] < 0  ||  insets[1] < 0)
    {
        logger.log(Level.WARNING, "Inset computation failed: TabPane at " + tabs_bounds + ", content pane at " + pane_bounds);
        insets[0] = insets[1] = 0;
    }
    model_widget.runtimePropInsets().setValue(insets);
}
 
Example 4
Source Project: phoebus   Source File: Rubberband.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void handleStart(final MouseEvent event)
{
    if (! event.isPrimaryButtonDown())
        return;
    active = true;

    // Event originates from a node that allows 'clicking' beyond the
    // model elements, i.e. the size of the 'parent'.
    // The 'parent', however, may be scrolled, and the rubber band needs
    // to show up in the 'parent', so convert coordinates
    // from event to the parent:
    final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
    x0 = in_parent.getX();
    y0 = in_parent.getY();
    rect.setX(x0);
    rect.setY(y0);
    rect.setWidth(1);
    rect.setHeight(1);
    parent.getChildren().add(rect);
    event.consume();
}
 
Example 5
Source Project: graph-editor   Source File: ConnectionSegment.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new connection segment for the given start and end points.
 *
 * @param start the point where the segment starts
 * @param end the point where the segment ends
 * @param intersections the intersection-points of this segment with other connections
 */
public ConnectionSegment(final Point2D start, final Point2D end, final List<Double> intersections) {

    this.start = start;
    this.end = end;
    this.intersections = intersections;

    horizontal = start.getY() == end.getY();

    if (horizontal) {
        sign = start.getX() < end.getX() ? 1 : -1;
    } else {
        sign = start.getY() < end.getY() ? 1 : -1;
    }

    filterIntersections();
}
 
Example 6
Source Project: gef   Source File: FXNonApplicationThreadRule.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_PRESSED} to the target {@link Node} of the last mouse
 * interaction.
 *
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mousePress(final Modifiers mods) {
	waitForIdle();
	run(() -> {
		Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
				lastMouseInteraction.sceneY);
		Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
		fireEvent(lastMouseInteraction.target,
				new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_PRESSED,
						local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
						mods.shift, mods.control, mods.alt, mods.meta, true, false, false, false, false, false,
						new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
								lastMouseInteraction.sceneY)));
	});
	waitForIdle();
}
 
Example 7
Source Project: FXGLGames   Source File: Level2.java    License: MIT License 6 votes vote down vote up
@Override
public void init() {
    for (int y = 0; y < ENEMY_ROWS; y++) {
        for (int x = 0; x < ENEMIES_PER_ROW; x++) {
            double px = random(0, getAppWidth() - 100);
            double py = random(0, getAppHeight() / 2.0);

            Entity enemy = spawnEnemy(px, py);

            var a = animationBuilder()
                    .autoReverse(true)
                    .interpolator(Interpolators.ELASTIC.EASE_IN_OUT())
                    .repeatInfinitely()
                    .duration(Duration.seconds(1.0))
                    .translate(enemy)
                    .from(new Point2D(px, py))
                    .to(new Point2D(random(0, getAppWidth() - 100), random(0, getAppHeight() / 2.0)))
                    .build();

            animations.add(a);
            a.start();
        }
    }
}
 
Example 8
Source Project: GMapsFX   Source File: GoogleMap.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * Returns the screen point for the provided LatLong. Note: Unexpected
     * results can be obtained if this method is called as a result of a zoom
     * change, as the zoom event is fired before the bounds are updated, and
     * bounds need to be used to obtain the answer!
     * <p>
     * One workaround is to only operate off bounds_changed events.
     *
     * @param loc
     * @return
     */
    public Point2D fromLatLngToPoint(LatLong loc) {
//        System.out.println("GoogleMap.fromLatLngToPoint loc: " + loc);
        Projection proj = getProjection();
        //System.out.println("map.fromLatLngToPoint Projection: " + proj);
        LatLongBounds llb = getBounds();
//        System.out.println("GoogleMap.fromLatLngToPoint Bounds: " + llb);

        GMapPoint topRight = proj.fromLatLngToPoint(llb.getNorthEast());
//        System.out.println("GoogleMap.fromLatLngToPoint topRight: " + topRight);
        GMapPoint bottomLeft = proj.fromLatLngToPoint(llb.getSouthWest());
//        System.out.println("GoogleMap.fromLatLngToPoint bottomLeft: " + bottomLeft);

        double scale = Math.pow(2, getZoom());
        GMapPoint worldPoint = proj.fromLatLngToPoint(loc);
//        System.out.println("GoogleMap.fromLatLngToPoint worldPoint: " + worldPoint);

        double x = (worldPoint.getX() - bottomLeft.getX()) * scale;
        double y = (worldPoint.getY() - topRight.getY()) * scale;

//        System.out.println("GoogleMap.fromLatLngToPoint x: " + x + " y: " + y);
        return new Point2D(x, y);
    }
 
Example 9
Source Project: gef   Source File: FXNonApplicationThreadRule.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_MOVED} to the given target {@link Node}.
 *
 * @param sceneX
 *            The final x-coordinate (in scene) for the drag.
 * @param sceneY
 *            The final y-coordinate (in scene) for the drag.
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mouseMove(final Node target, final double sceneX, final double sceneY, final Modifiers mods) {
	waitForIdle();
	// save mouse interaction data
	lastMouseInteraction = new MouseInteraction();
	lastMouseInteraction.target = target;
	lastMouseInteraction.sceneX = sceneX;
	lastMouseInteraction.sceneY = sceneY;
	run(() -> {
		Point2D local = target.sceneToLocal(sceneX, sceneY);
		Point2D screen = target.localToScreen(local.getX(), local.getY());
		fireEvent(target,
				new MouseEvent(target, target, MouseEvent.MOUSE_MOVED, local.getX(), local.getY(), screen.getX(),
						screen.getY(), MouseButton.NONE, 0, mods.shift, mods.control, mods.alt, mods.meta, false,
						false, false, false, false, false, new PickResult(target, sceneX, sceneY)));
	});
	waitForIdle();
}
 
Example 10
Source Project: mars-sim   Source File: AnimatedTableRow.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void moveDataWithAnimation(final TableView<Person> sourceTable,
		final TableView<Person> destinationTable,
		final Pane commonTableAncestor, final TableRow<Person> row) {
	// Create imageview to display snapshot of row:
	final ImageView imageView = createImageView(row);
	// Start animation at current row:
	final Point2D animationStartPoint = row.localToScene(new Point2D(0, 0)); // relative to Scene
	final Point2D animationEndPoint = computeAnimationEndPoint(destinationTable); // relative to Scene
	// Set start location
	final Point2D startInRoot = commonTableAncestor.sceneToLocal(animationStartPoint); // relative to commonTableAncestor
	imageView.relocate(startInRoot.getX(), startInRoot.getY());
	// Create animation
	final Animation transition = createAndConfigureAnimation(
			sourceTable, destinationTable, commonTableAncestor, row,
			imageView, animationStartPoint, animationEndPoint);
	// add animated image to display
	commonTableAncestor.getChildren().add(imageView);
	// start animation
	transition.play();
}
 
Example 11
Source Project: gef   Source File: FXNonApplicationThreadRule.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_RELEASED} to the target {@link Node} of the last
 * mouse interaction.
 *
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mouseRelease(final Modifiers mods) {
	waitForIdle();
	run(() -> {
		Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
				lastMouseInteraction.sceneY);
		Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
		fireEvent(lastMouseInteraction.target,
				new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_RELEASED,
						local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
						mods.shift, mods.control, mods.alt, mods.meta, false, false, false, false, false, false,
						new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
								lastMouseInteraction.sceneY)));
	});
	waitForIdle();
}
 
Example 12
Source Project: marathonv5   Source File: JavaFXElementPropertyAccessor.java    License: Apache License 2.0 6 votes vote down vote up
protected int getIndexAt(ListView<?> listView, Point2D point) {
    if (point == null) {
        return listView.getSelectionModel().getSelectedIndex();
    }
    point = listView.localToScene(point);
    Set<Node> lookupAll = getListCells(listView);
    ListCell<?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (ListCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
 
Example 13
Source Project: FXGLGames   Source File: BonusPlayerHandler.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCollisionBegin(Entity bonus, Entity player) {
    BonusType type = (BonusType) bonus.getComponent(SubTypeComponent.class).getValue();
    fire(new BonusPickupEvent(BonusPickupEvent.ANY, type));

    bonus.getComponent(CollidableComponent.class).setValue(false);
    bonus.setUpdateEnabled(false);

    animationBuilder()
            .duration(Duration.seconds(0.66))
            .interpolator(Interpolators.ELASTIC.EASE_IN())
            .onFinished(bonus::removeFromWorld)
            .scale(bonus)
            .to(new Point2D(0, 0))
            .buildAndPlay();
}
 
Example 14
Source Project: PreferencesFX   Source File: SimpleControl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the error message as tooltip for the matching control.
 *
 * @param below     The control needed for positioning the tooltip.
 * @param reference The control which gets the tooltip.
 */
@Override
protected void toggleTooltip(Node reference, Control below) {
  String fieldTooltip = field.getTooltip();

  if ((reference.isFocused() || reference.isHover())
      && (!fieldTooltip.equals("") || field.getErrorMessages().size() > 0)) {
    tooltip.setText((!fieldTooltip.equals("") ? fieldTooltip + "\n" : "")
        + String.join("\n", field.getErrorMessages()));

    if (tooltip.isShowing()) {
      return;
    }

    Point2D p = below.localToScene(0.0, 0.0);

    tooltip.show(
        reference.getScene().getWindow(),
        p.getX() + reference.getScene().getX() + reference.getScene().getWindow().getX(),
        p.getY() + reference.getScene().getY() + reference.getScene().getWindow().getY()
            + below.getHeight() + 5
    );
  } else {
    tooltip.hide();
  }
}
 
Example 15
Source Project: graph-editor   Source File: JointCreator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the new joint positions of the temporary joints.
 *
 * @return the list of positions of the temporary joints
 */
private List<Point2D> getNewJointPositions() {

    final SkinLookup skinLookup = graphEditor.getSkinLookup();
    final List<Point2D> allJointPositions = GeometryUtils.getJointPositions(connection, skinLookup);

    final Set<Integer> jointsToCleanUp = JointCleaner.findJointsToCleanUp(allJointPositions);

    final List<Point2D> newJointPositions = new ArrayList<>();

    for (int i = 0; i < allJointPositions.size(); i++) {
        if (!jointsToCleanUp.contains(i)) {
            newJointPositions.add(allJointPositions.get(i));
        }
    }

    return newJointPositions;
}
 
Example 16
Source Project: gef   Source File: FXColorPicker.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draws a color wheel into the given {@link WritableImage}, starting at the
 * given offsets, in the given size (in pixel).
 *
 * @param image
 *            The {@link WritableImage} in which the color wheel is drawn.
 * @param offsetX
 *            The horizontal offset (in pixel).
 * @param offsetY
 *            The vertical offset (in pixel).
 * @param size
 *            The size (in pixel).
 */
private void renderColorWheel(WritableImage image, int offsetX, int offsetY,
		int size) {
	PixelWriter px = image.getPixelWriter();
	double radius = size / 2;
	Point2D mid = new Point2D(radius, radius);
	for (int y = 0; y < size; y++) {
		for (int x = 0; x < size; x++) {
			double d = mid.distance(x, y);
			if (d <= radius) {
				// compute hue angle
				double angleRad = d == 0 ? 0
						: Math.atan2(y - mid.getY(), x - mid.getX());
				// compute saturation depending on distance to
				// middle
				// ([0;1])
				double sat = d / radius;
				Color color = Color.hsb(angleRad * 180 / Math.PI, sat, 1);
				px.setColor(offsetX + x, offsetY + y, color);
			} else {
				px.setColor(offsetX + x, offsetY + y, Color.TRANSPARENT);
			}
		}
	}
}
 
Example 17
Source Project: marathonv5   Source File: RFXTableViewTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void selectAllRows() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        Point2D point = getPoint(tableView, 1, 1);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        tableView.getSelectionModel().selectRange(0, 5);
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("all", recording.getParameters()[0]);
}
 
Example 18
Source Project: FXGLGames   Source File: SpaceRunnerFactory.java    License: MIT License 5 votes vote down vote up
@Spawns("Laser")
public Entity newLaser(SpawnData data) {
    play("shoot" + FXGLMath.random(1, 4) + ".wav");

    return entityBuilder()
            .type(SpaceRunnerType.BULLET)
            .from(data)
            .viewWithBBox(texture("sprite_laser.png"))
            .with(new CollidableComponent(true))
            .with(new ProjectileComponent(new Point2D(1, 0), 850),
                    new OffscreenCleanComponent())
            .build();
}
 
Example 19
Source Project: OpenLabeler   Source File: TagBoard.java    License: Apache License 2.0 5 votes vote down vote up
private void onMouseClicked(MouseEvent me) {
   if (!me.getButton().equals(MouseButton.PRIMARY)) {
      me.consume();
      return;
   }
   if (Settings.getEditShape() == POLYGON) {
      Point2D pt = imageView.parentToLocal(me.getX(), me.getY());
      if (path == null) {
         // Start a polygon shape with double-click or SHORTCUT + mouse click
         if (!me.isShortcutDown() && me.getClickCount() != 2) {
            me.consume();
            return;
         }
         beginShape(pt);
      }
      else {
         // End a polygon shape with double-click (and space key)
         if (me.getClickCount() == 2) {
            endShape(pt);
            return;
         }
         path.getElements().add(new LineTo(pt.getX(), pt.getY()));
         points.add(pt);
         updatePath(pt);
      }
   }
   me.consume();
}
 
Example 20
Source Project: FXGLGames   Source File: SpaceRunnerFactory.java    License: MIT License 5 votes vote down vote up
@Spawns("ai_point")
public Entity newAIPoint(SpawnData data) {
    return entityBuilder()
            .from(data)
            .type(SpaceRunnerType.AI_POINT)
            .bbox(new HitBox("MAIN", new Point2D(-400, 0), BoundingShape.box(400, 30)))
            .view(new Text())
            .with("collisions", new ArrayList<Entity>())
            .with("enemies", 0)
            .with(new AIPointComponent())
            .with(new CollidableComponent(true), new MoveComponent())
            .build();
}
 
Example 21
@Test
public void testHVH2()
{
	Edge edge = new DependencyEdge();
	edge.connect(aNode3, aNode4, aGraph);
	aGraph.addEdge(edge);
	Point2D[] points = SegmentationStyleFactory.createHVHStrategy().getPath(edge, aGraph);
	assertEquals( 2, points.length );
	assertEquals( new Point2D(120,50), points[0]);
	assertEquals( new Point2D(110,50), points[1]);
}
 
Example 22
BaseShape( BasicView view, Supplier<Shape> buildRootShape) {

        this.view = view;
        rootShape = buildRootShape.get();
        view.select(rootShape);

        // select shape on click
        Disposable disposable = JavaFxObservable.eventsOf(rootShape, MouseEvent.MOUSE_CLICKED)
                .subscribe( e -> {
                    view.select(rootShape);
                    e.consume();
                });


        // dispose "listeners" when shape is removed from the scene
        JavaFxObservable.changesOf(rootShape.sceneProperty())
                .filter( scene -> scene == null )
                .subscribe( s -> disposable.dispose());


        // calculate delta between shape location and initial mouse position on mouse pressed
        JavaFxObservable
                .eventsOf( rootShape, MouseEvent.MOUSE_PRESSED )
                .map( e -> new Point2D( e.getSceneX(), e.getSceneY()))
                .subscribe( p -> {
                    view.select(rootShape);
                    Bounds bounds = rootShape.localToScene(rootShape.getLayoutBounds());
                    delta =  p.subtract( new Point2D(bounds.getMinX(), bounds.getMinY()) );
                });

        // User current mouse position and delta to recalculate and set new shape location on mouse dragged
        JavaFxObservable
                .eventsOf( rootShape, MouseDragEvent.MOUSE_DRAGGED )
                .map( e -> rootShape.sceneToLocal(e.getSceneX() - delta.getX(),  e.getSceneY() - delta.getY()))
                .map( p -> rootShape.localToParent(p))
                .subscribe( p -> rootShape.relocate(  p.getX(), p.getY()));

    }
 
Example 23
Source Project: gef   Source File: CreateCurveOnDragHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected Point getLocation(MouseEvent e) {
	// XXX: Viewer may be null if the host is removed in the same pass in
	// which the event is forwarded.
	if (getHost().getViewer() == null) {
		return new Point(e.getSceneX(), e.getSceneY());
	}
	// FIXME: Prevent invocation of interaction policies when their host
	// does not have a link to the viewer.
	Point2D location = ((InfiniteCanvasViewer) getHost().getRoot().getViewer()).getCanvas().getContentGroup()
			.sceneToLocal(e.getSceneX(), e.getSceneY());
	return new Point(location.getX(), location.getY());
}
 
Example 24
Source Project: FXGLGames   Source File: FlappyBirdApp.java    License: MIT License 5 votes vote down vote up
private void playSpawnAnimation(Entity player) {
    player.setScaleX(0);
    player.setScaleY(0);

    getGameWorld().addEntity(player);

    animationBuilder()
            .duration(Duration.seconds(0.86))
            .interpolator(Interpolators.BOUNCE.EASE_OUT())
            .scale(player)
            .from(new Point2D(0, 0))
            .to(new Point2D(1, 1))
            .buildAndPlay();
}
 
Example 25
Source Project: FXGLGames   Source File: Level11.java    License: MIT License 5 votes vote down vote up
@Override
public void init() {
    double t = 0;

    for (int y = 0; y < ENEMY_ROWS; y++) {
        for (int x = 0; x < ENEMIES_PER_ROW; x++) {

            boolean toRight = FXGLMath.randomBoolean();

            Entity enemy = spawnEnemy(toRight ? 50 : Config.WIDTH - 50 - 40, 50 + y*75);

            Animation<?> anim = animationBuilder()
                    .delay(Duration.seconds(t))
                    .autoReverse(true)
                    .interpolator(Interpolators.SMOOTH.EASE_OUT())
                    .duration(Duration.seconds(3))
                    .repeatInfinitely()
                    .translate(enemy)
                    .from(enemy.getPosition())
                    .to(new Point2D(toRight ? Config.WIDTH - 50 - 40 : 50, 50 + y*75))
                    .build();

            animations.add(anim);

            anim.start();

            t += 0.3;
        }
    }
}
 
Example 26
Source Project: ShootOFF   Source File: ProjectorArenaPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void setArenaScreenOrigin(Screen screen) {
	final double dpiScaleFactor = ShootOFFController.getDpiScaleFactorForScreen();
	final Rectangle2D arenaScreenBounds = screen.getBounds();
	arenaScreenOrigin = new Point2D(arenaScreenBounds.getMinX() * dpiScaleFactor,
			arenaScreenBounds.getMinY() * dpiScaleFactor);

	logger.debug("Set arenaScreenOrigin to {}", arenaScreenOrigin);
}
 
Example 27
Source Project: FxDock   Source File: FxIconBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/** arc from current position, using the specified center coordinates, radius, and angle */
public void arcRel(double xc, double yc, double radius, double angle)
{
	// arcTo seems to fail if sweep angle is greater than 360
	if(angle >= FX.TWO_PI)
	{
		angle = FX.TWO_PI - 0.0000001;
	}
	else if(angle <= -FX.TWO_PI)
	{
		angle = - FX.TWO_PI + 0.0000001;
	}
	
	Point2D p = currentPos();
	
	double a = Math.atan2(yc + yorigin - p.getY(), p.getX() - xc - xorigin);
	double b = a - angle;
	double xe = xorigin + xc + radius * Math.cos(b);
	double ye = yorigin - yc - radius * Math.sin(b);

	// arcTo sweep is explained here: 
	// https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/ArcTo.html
	boolean large = (angle >= Math.PI);
	boolean sweep = (angle > 0);
	
	add(new ArcTo(radius, radius, 0, xe, ye, large, sweep));
}
 
Example 28
/**
 * Connects the start point on the left side of a node to an end point on the bottom side of a node.
 * 
 * @param start the start position
 * @param end the end position
 * @return a list of points connecting the start and end
 */
private static List<Point2D> connectLeftToBottom(final Point2D start, final Point2D end) {

    final List<Point2D> path = new ArrayList<>();

    if (start.getX() > end.getX() + MINIMUM_EXTENSION) {
        if (start.getY() > end.getY() + MINIMUM_EXTENSION) {
            addPoint(path, end.getX(), start.getY());
        } else {
            final double averageX = (start.getX() + end.getX()) / 2;
            addPoint(path, averageX, start.getY());
            addPoint(path, averageX, end.getY() + MINIMUM_EXTENSION);
            addPoint(path, end.getX(), end.getY() + MINIMUM_EXTENSION);
        }
    } else {
        if (start.getY() > end.getY() + MINIMUM_EXTENSION) {
            final double averageY = (start.getY() + end.getY()) / 2;
            addPoint(path, start.getX() - MINIMUM_EXTENSION, start.getY());
            addPoint(path, start.getX() - MINIMUM_EXTENSION, averageY);
            addPoint(path, end.getX(), averageY);
        } else {
            addPoint(path, start.getX() - MINIMUM_EXTENSION, start.getY());
            addPoint(path, start.getX() - MINIMUM_EXTENSION, end.getY() + MINIMUM_EXTENSION);
            addPoint(path, end.getX(), end.getY() + MINIMUM_EXTENSION);
        }
    }

    return path;
}
 
Example 29
@Test
public void testStraight2()
{
	Edge edge = new DependencyEdge();
	edge.connect(aNode3, aNode4, aGraph);
	aGraph.addEdge(edge);
	Point2D[] points = SegmentationStyleFactory.createStraightStrategy().getPath(edge, aGraph);
	assertEquals( 2, points.length );
	assertEquals( new Point2D(120,50), points[0]);
	assertEquals( new Point2D(110,50), points[1]);
}
 
Example 30
Source Project: chart-fx   Source File: YValueIndicator.java    License: Apache License 2.0 5 votes vote down vote up
protected void handleDragMouseEvent(final MouseEvent mouseEvent) {
    Point2D c = getChart().getPlotArea().sceneToLocal(mouseEvent.getSceneX(), mouseEvent.getSceneY());
    final double yPosData = getNumericAxis().getValueForDisplay(c.getY() - dragDelta.y);

    if (getNumericAxis().isValueOnAxis(yPosData)) {
        valueProperty().set(yPosData);
    }

    mouseEvent.consume();
}