Example usage for javafx.geometry Point2D getX

List of usage examples for javafx.geometry Point2D getX

Introduction

In this page you can find the example usage for javafx.geometry Point2D getX.

Prototype

public final double getX() 

Source Link

Document

The x coordinate.

Usage

From source file:de.pixida.logtest.designer.automaton.LineIntersector.java

static PointPosition getPointSideOfLine(final Point2D point, final Point2D lineStart, final Point2D lineEnd) {
    final double value = (lineEnd.getX() - lineStart.getX()) * (point.getY() - lineStart.getY())
            - (point.getX() - lineStart.getX()) * (lineEnd.getY() - point.getY());
    if (Math.abs(value) < EPSILON) {
        return PointPosition.ON_SAME_LINE;
    }/*from ww  w . j  a  v a 2 s.  c o  m*/
    if (value < 0.0) {
        return PointPosition.RIGHT_OF_THE_LINE;
    }
    return PointPosition.LEFT_OF_THE_LINE;
}

From source file:Main.java

public static void addMarker(final XYChart<?, ?> chart, final StackPane chartWrap) {
    final Line valueMarker = new Line();
    final Node chartArea = chart.lookup(".chart-plot-background");

    chartArea.setOnMouseMoved(new EventHandler<MouseEvent>() {
        @Override/* w ww  .  j  a  va2 s.c o m*/
        public void handle(MouseEvent event) {
            Point2D scenePoint = chart.localToScene(event.getSceneX(), event.getSceneY());
            Point2D position = chartWrap.sceneToLocal(scenePoint.getX(), scenePoint.getY());

            Bounds chartAreaBounds = chartArea.localToScene(chartArea.getBoundsInLocal());
            valueMarker.setStartY(0);
            valueMarker.setEndY(chartWrap.sceneToLocal(chartAreaBounds).getMaxY()
                    - chartWrap.sceneToLocal(chartAreaBounds).getMinY());

            valueMarker.setStartX(0);
            valueMarker.setEndX(0);
            valueMarker.setTranslateX(position.getX() - chartWrap.getWidth() / 2);

            double ydelta = chartArea.localToScene(0, 0).getY() - chartWrap.localToScene(0, 0).getY();
            valueMarker.setTranslateY(-ydelta * 2);
        }
    });

    chartWrap.getChildren().add(valueMarker);
}

From source file:de.pixida.logtest.designer.automaton.LineIntersector.java

static Point2D calculateIntersection(final Point2D point, final Point2D vec, final Line line) {
    final Point2D q = new Point2D(line.getStartX(), line.getStartY());
    final Point2D w = new Point2D(line.getEndX(), line.getEndY()).subtract(q);

    // q + t1 * w = point + t2 * vec => q - point = (vec w) (t2 -t1)^T
    final double det = det2x2LineWiseDefined(vec.getX(), w.getX(), vec.getY(), w.getY());
    final double epsilon = 1E-5;
    if (Math.abs(det) < epsilon) {
        return null;
    }//from   w  ww . j a v a 2  s . c o  m
    final double detInv = 1.0 / det;
    final double t2 = det2x2LineWiseDefined(q.getX() - point.getX(), w.getX(), q.getY() - point.getY(),
            w.getY()) * detInv;

    final Point2D intersection = vec.multiply(t2).add(point);
    return intersection;
}

From source file:Main.java

public void placeMarker(Node newNode) {
    double nodeMinX = newNode.getLayoutBounds().getMinX();
    double nodeMinY = newNode.getLayoutBounds().getMinY();
    Point2D nodeInScene = newNode.localToScene(nodeMinX, nodeMinY);
    Point2D nodeInMarkerLocal = marker.sceneToLocal(nodeInScene);
    Point2D nodeInMarkerParent = marker.localToParent(nodeInMarkerLocal);

    marker.relocate(nodeInMarkerParent.getX() + marker.getLayoutBounds().getMinX(),
            nodeInMarkerParent.getY() + marker.getLayoutBounds().getMinY());
}

From source file:de.pixida.logtest.designer.automaton.RectangularNode.java

private Line createLineBetweenTwoPoints(final Point2D from, final Point2D to) {
    return new Line(from.getX(), from.getY(), to.getX(), to.getY());
}

From source file:de.pixida.logtest.designer.automaton.RectangularNode.java

@Override
protected void setPosition(final Point2D position) {
    this.rectangle.setX(Math.max(0d, position.getX()));
    this.rectangle.setY(Math.max(0d, position.getY()));
}

From source file:de.pixida.logtest.designer.automaton.Graph.java

public void onMouseDragged(final BaseObject baseObject, final MouseEvent event) {
    if (baseObject instanceof BaseNode) {
        final BaseNode baseNode = (BaseNode) baseObject;
        Validate.notNull(this.dragPressedPoint);
        Validate.notNull(this.dragOriginalObjectPosition);

        final Point2D mouseMovement = new Point2D(event.getX(), event.getY()).subtract(this.dragPressedPoint);
        if (mouseMovement.getX() != 0d || mouseMovement.getY() != 0d) {
            Point2D newRectPos = this.dragOriginalObjectPosition.add(mouseMovement);
            newRectPos = new Point2D(Math.max(0d, newRectPos.getX()), Math.max(0d, newRectPos.getY()));
            baseNode.moveTo(newRectPos);
            this.handleMinorChange();
        }/* w  w w. jav a2 s . c  o  m*/
    }
}

From source file:net.rptools.image.listeners.TransformHandler.java

/**
 * @see #transform(String, String, boolean, String, Point2D)
 * @param phase phase we are in/*from  www .  j a va  2  s  . co m*/
 * @param fix fixed point
 * @param transformType transform type
 * @param constraints contraints
 * @param newDrag new transform end point
 */
@ThreadPolicy(ThreadPolicy.ThreadId.JFX)
private void resizeIntern(final String phase, final Point2D fix, final String transformType,
        final String constraints, final Point2D newDrag) {
    if (phase.equals(START)) {
        previousDrag = newDrag;
    }

    if (previousDrag == null) {
        return;
    }

    double scalex = Math.abs((fix.getX() - newDrag.getX()) / (fix.getX() - previousDrag.getX()));
    if (!Double.isFinite(scalex) || scalex < SANITY_SCALE || scalex > 1 / SANITY_SCALE) {
        scalex = 1;
    }
    double scaley = Math.abs((fix.getY() - newDrag.getY()) / (fix.getY() - previousDrag.getY()));
    if (!Double.isFinite(scaley) || scaley < SANITY_SCALE || scaley > 1 / SANITY_SCALE) {
        scaley = 1;
    }
    final double oldRad = Math.atan2(fix.getY() - previousDrag.getY(), fix.getX() - previousDrag.getX());
    final double newRad = Math.atan2(fix.getY() - newDrag.getY(), fix.getX() - newDrag.getX());

    if (constraints.equals(ISO)) {
        final double tmp = Math.max(scalex, scaley);
        scalex = tmp;
        scaley = tmp;
    }

    String transform = "1.0;0.0;0.0;0.0;1.0;0.0";
    switch (transformType) {
    case "rotate":
        transform = GeometryHelper.createTransform(fix, newRad - oldRad);
        break;
    case "scalex":
        transform = GeometryHelper.createTransform(fix, scalex, 1);
        break;
    case "scaley":
        transform = GeometryHelper.createTransform(fix, 1, scaley);
        break;
    case "scalexy":
        transform = GeometryHelper.createTransform(fix, scalex, scaley);
        break;
    default:
        break;
    }
    LOGGER.info("transform={}", transform);

    previousDrag = newDrag;

    for (ModelViewBinding binding : getSelection().getBindings()) {
        binding.prependTransform(transform);
    }

    if (phase.equals(END)) {
        previousDrag = null;
    }
}

From source file:com.panemu.tiwulfx.form.BaseControl.java

public BaseControl(String propertyName, E control) {
    this.inputControl = control;
    this.propertyName = propertyName;
    HBox.setHgrow(control, Priority.ALWAYS);
    setAlignment(Pos.CENTER_LEFT);//from  w ww  . ja va 2  s .  c  om
    control.setMaxWidth(Double.MAX_VALUE);
    control.setMinHeight(USE_PREF_SIZE);
    getChildren().add(control);
    getChildren().add(imagePlaceHolder);

    required.addListener(imageListener);
    valid.addListener(imageListener);

    this.getStyleClass().add("form-control");
    value = new SimpleObjectProperty<>();
    bindValuePropertyWithControl(control);
    bindEditablePropertyWithControl(control);

    addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) {
                Point2D p = BaseControl.this.localToScene(0.0, 0.0);
                getPopup().show(BaseControl.this, p.getX() + getScene().getX() + getScene().getWindow().getX(),
                        p.getY() + getScene().getY() + getScene().getWindow().getY()
                                + getInputComponent().getHeight() - 1);
            } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
    getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            if (!isValid() && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
}

From source file:com.panemu.tiwulfx.form.BaseListControl.java

public BaseListControl(String propertyName, E control) {
    this.inputControl = control;
    this.propertyName = propertyName;
    HBox.setHgrow(control, Priority.ALWAYS);
    setAlignment(Pos.CENTER_LEFT);/*from ww w.j a  v  a 2s .c om*/
    control.setMaxWidth(Double.MAX_VALUE);
    control.setMinHeight(USE_PREF_SIZE);
    getChildren().add(control);
    getChildren().add(imagePlaceHolder);

    required.addListener(imageListener);
    valid.addListener(imageListener);

    this.getStyleClass().add("form-control");
    value = new SimpleListProperty<>();
    bindValuePropertyWithControl(control);
    bindEditablePropertyWithControl(control);

    addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) {
                Point2D p = BaseListControl.this.localToScene(0.0, 0.0);
                getPopup().show(BaseListControl.this,
                        p.getX() + getScene().getX() + getScene().getWindow().getX(),
                        p.getY() + getScene().getY() + getScene().getWindow().getY()
                                + getInputComponent().getHeight() - 1);
            } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
    getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            if (!isValid() && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
}