Java Code Examples for javafx.geometry.Point2D#getY()

The following examples show how to use javafx.geometry.Point2D#getY() . 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: TabsRepresentation.java    From phoebus with 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 2
Source File: UtilitiesPoint2D.java    From JavaFXSmartGraph with MIT License 6 votes vote down vote up
/**
 * Rotate a point around a pivot point by a specific degrees amount
 * @param point point to rotate
 * @param pivot pivot point
 * @param angle_degrees rotation degrees
 * @return rotated point
 */
public static Point2D rotate(final Point2D point, final Point2D pivot, double angle_degrees) {
    double angle = Math.toRadians(angle_degrees); //angle_degrees * (Math.PI/180); //to radians
    
    double sin = Math.sin(angle);
    double cos = Math.cos(angle);

    //translate to origin
    Point2D result = point.subtract(pivot);
    
    // rotate point
    Point2D rotatedOrigin = new Point2D(
            result.getX() * cos - result.getY() * sin,
            result.getX() * sin + result.getY() * cos);

    // translate point back
    result = rotatedOrigin.add(pivot);

    return result;
}
 
Example 3
Source File: ConnectionSegment.java    From graph-editor with 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 4
Source File: ArrowUtils.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Draws the given arrow from the start to end points with the given offset from either end.
 *
 * @param arrow an {@link Arrow} to be drawn
 * @param start the start position
 * @param end the end position
 * @param offset an offset from start and end positions
 */
public static void draw(final Arrow arrow, final Point2D start, final Point2D end, final double offset) {

    final double deltaX = end.getX() - start.getX();
    final double deltaY = end.getY() - start.getY();

    final double angle = Math.atan2(deltaX, deltaY);

    final double startX = start.getX() + offset * Math.sin(angle);
    final double startY = start.getY() + offset * Math.cos(angle);

    final double endX = end.getX() - offset * Math.sin(angle);
    final double endY = end.getY() - offset * Math.cos(angle);

    arrow.setStart(startX, startY);
    arrow.setEnd(endX, endY);
    arrow.draw();

    if (Math.hypot(deltaX, deltaY) < 2 * offset) {
        arrow.setVisible(false);
    } else {
        arrow.setVisible(true);
    }
}
 
Example 5
Source File: Rubberband.java    From phoebus with 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 6
Source File: JFXRepresentation.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Ctrl-Wheel zoom gesture help function
 *  Repositioning scrollbars in scroller so that the zoom centre stays at mouse cursor
 */
private void repositionScroller(final Node scrollContent, final ScrollPane scroller, final double scaleFactor, final Point2D scrollOffset, final Point2D mouse)
{
    double scrollXOffset = scrollOffset.getX();
    double scrollYOffset = scrollOffset.getY();
    double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
    if (extraWidth > 0)
    {
        double newScrollXOffset = (scaleFactor - 1) *  mouse.getX() + scaleFactor * scrollXOffset;
        scroller.setHvalue(scroller.getHmin() + newScrollXOffset * (scroller.getHmax() - scroller.getHmin()) / extraWidth);
    }
    else
        scroller.setHvalue(scroller.getHmin());
    double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
    if (extraHeight > 0)
    {
        double newScrollYOffset = (scaleFactor - 1) * mouse.getY() + scaleFactor * scrollYOffset;
        scroller.setVvalue(scroller.getVmin() + newScrollYOffset * (scroller.getVmax() - scroller.getVmin()) / extraHeight);
    }
    else
        scroller.setHvalue(scroller.getHmin());
}
 
Example 7
Source File: JavaServer.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private void click(Session session, int button, int clickCount) {
    IJavaFXElement element = null;
    double xoffset;
    double yoffset;
    if (lastComponenet.element != null) {
        element = lastComponenet.element;
        xoffset = lastComponenet.x;
        yoffset = lastComponenet.y;
    } else {
        element = session.getActiveElement();
        Point2D p = element.getMidpoint();
        xoffset = p.getX();
        yoffset = p.getY();
    }
    element.click(button, null, null, clickCount, xoffset, yoffset);
}
 
Example 8
Source File: ZoomPane.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
private static void repositionScroller(Node scrollContent, ScrollPane scroller, double scaleFactor,
		Point2D scrollOffset) {
	double scrollXOffset = scrollOffset.getX();
	double scrollYOffset = scrollOffset.getY();
	double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
	if (extraWidth > 0) {
		double halfWidth = scroller.getViewportBounds().getWidth() / 2;
		double newScrollXOffset = (scaleFactor - 1) * halfWidth + scaleFactor * scrollXOffset;
		scroller.setHvalue(
				scroller.getHmin() + newScrollXOffset * (scroller.getHmax() - scroller.getHmin()) / extraWidth);
	} else {
		scroller.setHvalue(scroller.getHmin());
	}
	double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
	if (extraHeight > 0) {
		double halfHeight = scroller.getViewportBounds().getHeight() / 2;
		double newScrollYOffset = (scaleFactor - 1) * halfHeight + scaleFactor * scrollYOffset;
		scroller.setVvalue(
				scroller.getVmin() + newScrollYOffset * (scroller.getVmax() - scroller.getVmin()) / extraHeight);
	} else {
		scroller.setHvalue(scroller.getHmin());
	}
}
 
Example 9
Source File: DesktopPane.java    From desktoppanefx with Apache License 2.0 5 votes vote down vote up
public void placeInternalWindow(InternalWindow internalWindow, Point2D point) {
    double windowsWidth = internalWindow.getLayoutBounds().getWidth();
    double windowsHeight = internalWindow.getLayoutBounds().getHeight();
    internalWindow.setPrefSize(windowsWidth, windowsHeight);

    double containerWidth = internalWindowContainer.getLayoutBounds().getWidth();
    double containerHeight = internalWindowContainer.getLayoutBounds().getHeight();
    if (containerWidth <= point.getX() || containerHeight <= point.getY()) {
        throw new PositionOutOfBoundsException(
            "Tried to snapTo MDI Window with ID " + internalWindow.getId() +
                " at a coordinate " + point.toString() +
                " that is beyond current size of the MDI container " +
                containerWidth + "px x " + containerHeight + "px."
        );
    }

    if ((containerWidth - point.getX() < 40) ||
        (containerHeight - point.getY() < 40)) {
        throw new PositionOutOfBoundsException(
            "Tried to snapTo MDI Window with ID " + internalWindow.getId() +
                " at a coordinate " + point.toString() +
                " that is too close to the edge of the parent of size " +
                containerWidth + "px x " + containerHeight + "px " +
                " for user to comfortably grab the title bar with the mouse."
        );
    }

    internalWindow.setLayoutX((int) point.getX());
    internalWindow.setLayoutY((int) point.getY());
}
 
Example 10
Source File: JFXColorPickerUI.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private Image getSLCricle(int width, int height) {
    WritableImage raster = new WritableImage(width, height);
    PixelWriter pixelWriter = raster.getPixelWriter();
    Point2D center = new Point2D((double) width / 2, (double) height / 2);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double dy = x - center.getX();
            double dx = y - center.getY();
            pixelWriter.setColor(x, y, getColor(dx, dy));
        }
    }
    return raster;
}
 
Example 11
Source File: RFXTableView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public RFXTableView(Node source, JSONOMapConfig omapConfig, Point2D point, IJSONRecorder recorder) {
    super(source, omapConfig, point, recorder);
    TableView<?> table = (TableView<?>) source;
    if (source == null) {
        return;
    }
    if (table.getEditingCell() != null) {
        TablePosition<?, ?> editingCell = table.getEditingCell();
        row = editingCell.getRow();
        column = editingCell.getColumn();
    } else {
        if (point != null && point.getX() > 0 && point.getY() > 0) {
            column = getColumnAt(table, point);
            row = getRowAt(table, point);
        } else {
            @SuppressWarnings("rawtypes")
            ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells();
            for (TablePosition<?, ?> tablePosition : selectedCells) {
                column = tablePosition.getColumn();
                row = tablePosition.getRow();
            }
        }
    }
    cellInfo = getTableCellText((TableView<?>) node, row, column);
    if (row == -1 || column == -1) {
        row = column = -1;
    }
}
 
Example 12
Source File: WebEventDispatcher.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {

	if (event instanceof MouseEvent){
        MouseEvent m = (MouseEvent)event;
        if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED) ||
            event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
            Point2D origin = new Point2D(m.getX(),m.getY());
            if (limit != null)
            	allowDrag = !(origin.getX() < limit.getX() && origin.getY() < limit.getY());
        }

        // avoid selection with mouse dragging, allowing dragging the scrollbars
        if (event.getEventType().equals(MouseEvent.MOUSE_DRAGGED)) {
            if(!allowDrag){
                event.consume();
            }
        }
        // Avoid selection of word, line, paragraph with mouse click
        if(m.getClickCount() > 1){
            event.consume();
        }
    }

    if (event instanceof KeyEvent && event.getEventType().equals(KeyEvent.KEY_PRESSED)){
        KeyEvent k = (KeyEvent)event;
        // Avoid copy with Ctrl+C or Ctrl+Insert
        if((k.getCode().equals(KeyCode.C) || k.getCode().equals(KeyCode.INSERT)) && k.isControlDown()){
            event.consume();
        }
        // Avoid selection with shift+Arrow
        if(k.isShiftDown() && (k.getCode().equals(KeyCode.RIGHT) || k.getCode().equals(KeyCode.LEFT) ||
            k.getCode().equals(KeyCode.UP) || k.getCode().equals(KeyCode.DOWN))){
            event.consume();
        }
    }
    return oldDispatcher.dispatchEvent(event, tail);
}
 
Example 13
Source File: JFXColorPickerUI.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private Point2D rotate(Point2D a, Point2D center, double angle) {
    double resultX = center.getX() + (a.getX() - center.getX()) * Math.cos(angle) - (a.getY() - center.getY()) * Math
        .sin(angle);
    double resultY = center.getY() + (a.getX() - center.getX()) * Math.sin(angle) + (a.getY() - center.getY()) * Math
        .cos(angle);
    return new Point2D(resultX, resultY);
}
 
Example 14
Source File: CreateCurveOnDragHandler.java    From gef with 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 15
Source File: SmartGraphPanel.java    From JavaFXSmartGraph with MIT License 5 votes vote down vote up
private void computeForces() {
    for (SmartGraphVertexNode<V> v : vertexNodes.values()) {
        for (SmartGraphVertexNode<V> other : vertexNodes.values()) {
            if (v == other) {
                continue; //NOP
            }

            //double k = Math.sqrt(getWidth() * getHeight() / graphVertexMap.size());
            Point2D repellingForce = repellingForce(v.getUpdatedPosition(), other.getUpdatedPosition(), this.repulsionForce);

            double deltaForceX = 0, deltaForceY = 0;

            //compute attractive and reppeling forces
            //opt to use internal areAdjacent check, because a vertex can be removed from
            //the underlying graph before we have the chance to remove it from our
            //internal data structure
            if (areAdjacent(v, other)) {

                Point2D attractiveForce = attractiveForce(v.getUpdatedPosition(), other.getUpdatedPosition(),
                        vertexNodes.size(), this.attractionForce, this.attractionScale);

                deltaForceX = attractiveForce.getX() + repellingForce.getX();
                deltaForceY = attractiveForce.getY() + repellingForce.getY();
            } else {
                deltaForceX = repellingForce.getX();
                deltaForceY = repellingForce.getY();
            }

            v.addForceVector(deltaForceX, deltaForceY);
        }
    }
}
 
Example 16
Source File: FXSwingUtilities.java    From megan-ce with GNU General Public License v3.0 4 votes vote down vote up
public static java.awt.geom.Point2D asAWTPoint2D(Point2D center) {
    return new java.awt.geom.Point2D.Double(center.getX(), center.getY());
}
 
Example 17
Source File: TimerControlTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void drawTicks() {
    minuteTickMarks.setCache(false);
    hourTickMarks.setCache(false);
    minuteTickMarks.getElements().clear();
    hourTickMarks.getElements().clear();
    double  sinValue;
    double  cosValue;
    double  startAngle             = 180;
    double  angleStep              = 360 / 60;
    Point2D center                 = new Point2D(clockSize * 0.5, clockSize * 0.5);
    boolean hourTickMarksVisible   = tile.isHourTickMarksVisible();
    boolean minuteTickMarksVisible = tile.isMinuteTickMarksVisible();
    for (double angle = 0, counter = 0 ; Double.compare(counter, 59) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint       = new Point2D(center.getX() + clockSize * 0.405 * sinValue, center.getY() + clockSize * 0.405 * cosValue);
        Point2D innerMinutePoint = new Point2D(center.getX() + clockSize * 0.435 * sinValue, center.getY() + clockSize * 0.435 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + clockSize * 0.465 * sinValue, center.getY() + clockSize * 0.465 * cosValue);

        if (counter % 5 == 0) {
            // Draw hour tickmark
            if (hourTickMarksVisible) {
                hourTickMarks.setStrokeWidth(clockSize * 0.01);
                hourTickMarks.getElements().add(new MoveTo(innerPoint.getX(), innerPoint.getY()));
                hourTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
            } else if (minuteTickMarksVisible) {
                minuteTickMarks.setStrokeWidth(clockSize * 0.005);
                minuteTickMarks.getElements().add(new MoveTo(innerMinutePoint.getX(), innerMinutePoint.getY()));
                minuteTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
            }
        } else if (counter % 1 == 0 && minuteTickMarksVisible) {
            // Draw minute tickmark
            minuteTickMarks.setStrokeWidth(clockSize * 0.005);
            minuteTickMarks.getElements().add(new MoveTo(innerMinutePoint.getX(), innerMinutePoint.getY()));
            minuteTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
        }
    }
    minuteTickMarks.setCache(true);
    minuteTickMarks.setCacheHint(CacheHint.QUALITY);
    hourTickMarks.setCache(true);
    hourTickMarks.setCacheHint(CacheHint.QUALITY);
}
 
Example 18
Source File: PearClockSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTicks() {
    double  sinValue;
    double  cosValue;
    double  startAngle             = 180;
    double  angleStep              = 360 / 240 +0.5;
    Point2D center                 = new Point2D(size * 0.5, size * 0.5);
    Color   hourTickMarkColor      = clock.getHourTickMarkColor();
    Color   minuteTickMarkColor    = clock.getMinuteTickMarkColor();
    Color   tickLabelColor         = clock.getTickLabelColor();
    boolean hourTickMarksVisible   = clock.isHourTickMarksVisible();
    boolean minuteTickMarksVisible = clock.isMinuteTickMarksVisible();
    boolean tickLabelsVisible      = clock.isTickLabelsVisible();
    Font    font                   = Fonts.robotoLight(size * 0.084);
    tickCtx.clearRect(0, 0, size, size);
    tickCtx.setLineCap(StrokeLineCap.BUTT);
    tickCtx.setFont(font);
    tickCtx.setLineWidth(size * 0.005);
    for (double angle = 0, counter = 0 ; Double.compare(counter, 239) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint       = new Point2D(center.getX() + size * 0.45866667 * sinValue, center.getY() + size * 0.45866667 * cosValue);
        Point2D innerMinutePoint = new Point2D(center.getX() + size * 0.47733333 * sinValue, center.getY() + size * 0.47733333 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + size * 0.5 * sinValue, center.getY() + size * 0.5 * cosValue);
        Point2D textPoint        = new Point2D(center.getX() + size * 0.405 * sinValue, center.getY() + size * 0.405 * cosValue);
        
        if (counter % 20 == 0) {
            tickCtx.setStroke(hourTickMarkColor);
            if (hourTickMarksVisible) {
                tickCtx.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());
            } else if (minuteTickMarksVisible) {
                tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
            }
            if (tickLabelsVisible) {
                tickCtx.save();
                tickCtx.translate(textPoint.getX(), textPoint.getY());

                Helper.rotateContextForText(tickCtx, startAngle, angle, TickLabelOrientation.HORIZONTAL);
                tickCtx.setTextAlign(TextAlignment.CENTER);
                tickCtx.setTextBaseline(VPos.CENTER);
                tickCtx.setFill(tickLabelColor);
                if (counter == 0) {
                    tickCtx.fillText("12", 0, 0);
                } else {
                    tickCtx.fillText(Integer.toString((int) (counter / 20)), 0, 0);
                }

                tickCtx.restore();
            }
        } else if (counter % 4 == 0 && minuteTickMarksVisible) {
            tickCtx.setStroke(minuteTickMarkColor);
            tickCtx.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());
        } else if (counter % 1 == 0 && minuteTickMarksVisible) {
            tickCtx.setStroke(minuteTickMarkColor);
            tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 19
Source File: ResizeTransformSelectedOnHandleDragHandler.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void drag(MouseEvent e, Dimension delta) {
	if (invalidGesture) {
		return;
	}
	if (selectionBounds == null) {
		return;
	}
	if (targetParts.isEmpty()) {
		return;
	}

	// snap to grid
	// FIXME: apply resize-transform first, then snap the moved vertex to
	// the next grid position and update the values

	// TODO
	Point newEndPointInScene = isPrecise(e)
			? new Point(e.getSceneX(), e.getSceneY())
			: new Point(e.getSceneX(), e.getSceneY());

	// update selection bounds
	Rectangle sel = updateSelectionBounds(newEndPointInScene);

	// update target parts
	for (IContentPart<? extends Node> targetPart : targetParts) {
		// compute initial and new bounds for this target
		Bounds initialBounds = getBounds(selectionBounds, targetPart);
		Bounds newBounds = getBounds(sel, targetPart);

		// System.out.println(targetPart.getClass().getSimpleName()
		// + " bounds change from " + initialBounds.getMinX() + ", "
		// + initialBounds.getMinY() + " : " + initialBounds.getWidth()
		// + " x " + initialBounds.getHeight() + " to "
		// + newBounds.getMinX() + ", " + newBounds.getMinY() + " : "
		// + newBounds.getWidth() + " x " + newBounds.getHeight()
		// + ".");

		// compute translation in scene coordinates
		double dx = newBounds.getMinX() - initialBounds.getMinX();
		double dy = newBounds.getMinY() - initialBounds.getMinY();

		// transform translation to parent coordinates
		Node visual = targetPart.getVisual();
		Point2D originInParent = visual.getParent().sceneToLocal(0, 0);
		Point2D deltaInParent = visual.getParent().sceneToLocal(dx, dy);
		dx = deltaInParent.getX() - originInParent.getX();
		dy = deltaInParent.getY() - originInParent.getY();

		// apply translation
		getTransformPolicy(targetPart)
				.setPostTranslate(translateIndices.get(targetPart), dx, dy);

		// check if we can resize the part
		AffineTransform affineTransform = getTransformPolicy(targetPart)
				.getCurrentTransform();
		if (affineTransform.getRotation().equals(Angle.fromDeg(0))) {
			// no rotation => resize possible
			// TODO: special case 90 degree rotations
			double dw = newBounds.getWidth() - initialBounds.getWidth();
			double dh = newBounds.getHeight() - initialBounds.getHeight();

			// System.out.println(
			// "delta size in scene: " + dw + ", " + dh + ".");

			Point2D originInLocal = visual.sceneToLocal(newBounds.getMinX(),
					newBounds.getMinY());
			Point2D dstInLocal = visual.sceneToLocal(
					newBounds.getMinX() + dw, newBounds.getMinY() + dh);
			dw = dstInLocal.getX() - originInLocal.getX();
			dh = dstInLocal.getY() - originInLocal.getY();

			// System.out.println(
			// "delta size in local: " + dw + ", " + dh + ".");

			getResizePolicy(targetPart).resize(dw, dh);
		} else {
			// compute scaling based on bounds change
			double sx = newBounds.getWidth() / initialBounds.getWidth();
			double sy = newBounds.getHeight() / initialBounds.getHeight();
			// apply scaling
			getTransformPolicy(targetPart)
					.setPostScale(scaleIndices.get(targetPart), sx, sy);
		}
	}
}
 
Example 20
Source File: ProjectorTrainingExerciseBase.java    From ShootOFF with GNU General Public License v3.0 3 votes vote down vote up
/**
 * This function corrects coordinates in the arena area for the DPI of the
 * arena screen and relative to the origin.  This is for creating mouse
 * events and other javafx functions that need true coordinates rather 
 * than scaled ones.
 * 
 * @param point
 * 			The coordinates to be corrected
 * 
 * @return Translated coordinates
 * 
 * @since 3.8
 */
public Point2D translateToTrueArenaCoords(Point2D point)
{
	final double dpiScaleFactor = ShootOFFController.getDpiScaleFactorForScreen();

	final Point2D origin = arenaPane.getArenaScreenOrigin();

	return new Point2D(origin.getX() + (point.getX() * dpiScaleFactor),
			origin.getY() + (point.getY() * dpiScaleFactor));
}