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:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

private Point2D getPrefPopupPosition() {
    Point2D p = getSkinnable().localToScene(0.0, 0.0);
    Point2D p2 = new Point2D(
            p.getX() + getSkinnable().getScene().getX() + getSkinnable().getScene().getWindow().getX(),
            p.getY() + getSkinnable().getScene().getY() + getSkinnable().getScene().getWindow().getY()
                    + getSkinnable().getHeight());
    return p2;/*from  www. j  a v  a 2  s.  c o  m*/
}

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

/**
 * Main work method./*from  w w  w  .  j  av  a  2s.c  o m*/
 * @param phase phase of drawing we are in
 * @param newEnd new end of current draw
 * @param pen pen color
 * @param fill fill color
 * @param radius pen radius
 */
@ThreadPolicy(ThreadPolicy.ThreadId.JFX)
private void draw(final String phase, final Point2D newEnd, final String pen, final String fill,
        final int radius) {
    LOGGER.debug("phase={}; draw={}; pen={}; fill={}; radius={}", phase, newEnd, pen, fill, radius);

    if (phase.equals(START)) {
        currentShape = new Polygon();
        getLayer().getDrawable().getChildren().add(currentShape);
    }

    if (currentShape == null) {
        return;
    }

    currentShape.getPoints().addAll(newEnd.getX(), newEnd.getY());

    switch (fill.charAt(0)) {
    case '#':
        currentShape.setFill(Color.web(fill));
        break;
    case '-':
        currentShape.setFill(null);
        break;
    default:
        if (currentFill == null) {
            currentFill = getLayer().loadImage(fill);
        }
        currentShape.setFill(
                new ImagePattern(currentFill, 0, 0, currentFill.getWidth(), currentFill.getHeight(), false));
    }
    switch (pen.charAt(0)) {
    case '#':
        currentShape.setStroke(Color.web(pen));
        break;
    case '-':
        currentShape.setStroke(null);
        break;
    default:
        if (currentPen == null) {
            currentPen = getLayer().loadImage(pen);
        }
        currentShape.setStroke(
                new ImagePattern(currentPen, 0, 0, currentPen.getWidth(), currentPen.getHeight(), false));
    }
    currentShape.setStrokeLineCap(StrokeLineCap.ROUND);
    currentShape.setStrokeLineJoin(StrokeLineJoin.ROUND);
    currentShape.setStrokeWidth(radius);

    if (phase.equals(END)) {
        finalizeDrawing();
        currentShape = null;
        currentPen = null;
        currentFill = null;
    }
    LOGGER.debug("draw polygon completed={}", currentShape == null);
}

From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

private void positionAndShowPopup() {
    if (getPopup().getSkin() == null) {
        getSkinnable().getScene().getRoot().impl_processCSS(true);
    }/*w ww .j  av a  2s.com*/

    Point2D p = getPrefPopupPosition();

    /**
     * In LookupColumn, sometimes the lookupfield disappears due to commit
     * editing before the popup appears. In this case,
     * lookupField.getScene() will be null.
     */
    Scene scene = lookupField.getScene();
    if (scene != null) {
        getPopup().show(scene.getWindow(), p.getX(), p.getY());
    }
}

From source file:com.rockhoppertech.symchords.fx.SymChordsController.java

protected void setupDragonDrop() {
    Image image = new Image(getClass().getResourceAsStream("/images/rocky-32-trans.png"));
    dragImageView = new ImageView(image);
    dragImageView.setFitHeight(32);/*  ww  w  .  j a  va  2  s . com*/
    dragImageView.setFitWidth(32);

    grandStaff.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent me) {

            if (!root.getChildren().contains(dragImageView)) {
                root.getChildren().add(dragImageView);
            }

            // dragImageView.setOpacity(0.5);
            dragImageView.toFront();
            dragImageView.setMouseTransparent(true);
            dragImageView.setVisible(true);
            dragImageView.relocate((int) (me.getSceneX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                    (int) (me.getSceneY() - dragImageView.getBoundsInLocal().getHeight() / 2));

            Dragboard db = grandStaff.startDragAndDrop(TransferMode.ANY);

            // TODO remove the custom image nonsense in javafx 8
            // javafx 8
            // db.setDragView(dragImageView);

            ClipboardContent content = new ClipboardContent();
            // MIDITrack track = grandStaff.getMIDITrack();
            MIDITrack track = model.getMIDITrack();
            content.put(midiTrackDataFormat, track);
            db.setContent(content);
            me.consume();
        }
    });

    grandStaff.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            dragImageView.setVisible(false);
            e.consume();
        }
    });

    // Parent root = grandStaff.getScene().getRoot();
    // stage.getScene().getRoot();

    if (root != null) {
        root.setOnDragOver(new EventHandler<DragEvent>() {
            public void handle(DragEvent e) {
                Point2D localPoint = grandStaff.getScene().getRoot()
                        .sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY()));
                dragImageView.relocate(
                        (int) (localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                        (int) (localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2));
                e.consume();
            }
        });
    }

    trackList.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /*
             * data is dragged over the target; accept it only if it is not
             * dragged from the same node and if it has MIDITrack data
             */
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                logger.debug("drag over");
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            // Don't consume the event. Let the layers below process the
            // DragOver event as well so that the
            // translucent container image will follow the cursor.
            // event.consume();
        }
    });

    trackList.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            /* show to the user that it is an actual gesture target */
            logger.debug("drag entered");
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                DropShadow dropShadow = new DropShadow();
                dropShadow.setRadius(5.0);
                dropShadow.setOffsetX(3.0);
                dropShadow.setOffsetY(3.0);
                dropShadow.setColor(Color.color(0.4, 0.5, 0.5));
                trackList.setEffect(dropShadow);
            }
            event.consume();
        }
    });

    trackList.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            trackList.setEffect(null);
            event.consume();
        }
    });

    trackList.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {

            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasContent(midiTrackDataFormat)) {
                MIDITrack track = (MIDITrack) db.getContent(midiTrackDataFormat);
                trackList.getItems().add(track);
                success = true;

            }
            /*
             * let the source know whether the data was successfully
             * transferred and used
             */
            event.setDropCompleted(success);
            event.consume();
        }
    });

    logger.debug("jvm mime {}", DataFlavor.javaJVMLocalObjectMimeType);
}

From source file:Main.java

private void drawAllAxes() {

    // If local and parent coordinate spaces are the same,
    // we will draw axes only once
    // Transform a non-zero (x, y) point from local to parent.
    // If we get the same point back, it means two coordinate spaces are the same
    double x = 100; // any value will do
    double y = 100; // any value will do

    Point2D p = mainRect.localToParent(x, y);

    if (p.getY() == y) {
        // We do not draw parent x-axis
        parentXArrow.setVisible(false);//from w  w  w.  ja v  a  2  s  . c o m
        parentXAxisLabel.setVisible(false);

        localXAxisLabel.setText("x-axis (Parent/Untransformed Local)");
        drawLocalAxis();
    } else {
        this.parentXArrow.setVisible(true);
        this.parentXAxisLabel.setVisible(true);

        localXAxisLabel.setText("x-axis (Transformed Local)");
        parentXAxisLabel.setText("x-axis (Parent/Untransformed Local)");
        drawLocalAxis();
        drawParentAxis();
    }

    if (p.getX() == x) {
        // We do not draw parent y-axis
        parentYArrow.setVisible(false);
        parentYAxisLabel.setVisible(false);

        localYAxisLabel.setText("y-axis (Parent/Untransformed Local)");
        drawLocalAxis();
    } else {
        parentYArrow.setVisible(true);
        parentYAxisLabel.setVisible(true);

        localYAxisLabel.setText("y-axis (Transformed Local)");
        parentYAxisLabel.setText("y-axis (Parent/Untransformed Local)");
        drawLocalAxis();
        drawParentAxis();
    }
}

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * Gets a location inside the component. If <code>offset</code> is
 * <code>null</code>, it returns the middle of the component otherwise it
 * adds the offset to the upper left corner.
 *
 * @param comp/* w  w w  .  ja  v  a  2  s.  com*/
 *            the component to get the location for
 * @param offset
 *            the offset
 * @throws IllegalArgumentException
 *             if <code>component</code> is null
 * @return the <b>global </b> coordinates of <code>component</code>
 */
private Point getLocation(Node comp, final Point offset) throws IllegalArgumentException {

    Validate.notNull(comp, "component must not be null"); //$NON-NLS-1$

    Scene s = comp.getScene();
    s.getRoot().layout();

    Point2D pos = comp.localToScreen(0, 0);

    double x = pos.getX();
    double y = pos.getY();
    if (offset == null) {
        final Bounds boundsInParent = comp.getBoundsInParent();
        x += boundsInParent.getWidth() / 2;
        y += boundsInParent.getHeight() / 2;
    } else {
        x += offset.x;
        y += offset.y;
    }

    return new Point(Rounding.round(x), Rounding.round(y));
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.ListViewAdapter.java

/** {@inheritDoc} **/
public void clickOnIndex(final Integer index, ClickOptions co) {
    final int actualItemCount = EventThreadQueuerJavaFXImpl.invokeAndWait("scrollIndexVisible", //$NON-NLS-1$
            new Callable<Integer>() {
                public Integer call() throws Exception {
                    final ObservableList items = getRealComponent().getItems();
                    int itemCount = items != null ? items.size() : -1;
                    return new Integer(itemCount);
                }/*from  ww w  .j  a v a2s  .co  m*/
            }).intValue();

    if (index >= actualItemCount || (index < 0)) {
        throw new StepExecutionException("List index '" + index //$NON-NLS-1$
                + "' is out of range", //$NON-NLS-1$
                EventFactory.createActionError(TestErrorEvent.INVALID_INDEX));
    }

    Rectangle r = EventThreadQueuerJavaFXImpl.invokeAndWait("scrollIndexVisible", //$NON-NLS-1$
            new Callable<Rectangle>() {
                public Rectangle call() throws Exception {
                    final T listView = getRealComponent();
                    listView.scrollTo(index.intValue());
                    listView.layout();
                    TraverseHelper<ListCell> helper = new TraverseHelper<ListCell>();
                    List<ListCell> lCells = helper.getInstancesOf(listView, ListCell.class);
                    for (ListCell cell : lCells) {
                        if (cell.getIndex() == index.intValue() && cell.getListView() == listView) {

                            Bounds b = cell.getBoundsInParent();
                            Point2D pos = cell.localToScreen(0, 0);
                            Point2D parentPos = listView.localToScreen(0, 0);
                            return new Rectangle(Rounding.round(pos.getX() - parentPos.getX()),
                                    Rounding.round(pos.getY() - parentPos.getY()), Rounding.round(b.getWidth()),
                                    Rounding.round(b.getHeight()));
                        }
                    }
                    return null;
                }
            });

    getRobot().click(getRealComponent(), r, co.setClickType(ClickOptions.ClickType.RELEASED));
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public Rectangle getNodeBounds(final Object node) {
    Rectangle result = EventThreadQueuerJavaFXImpl.invokeAndWait("getNodeBounds", new Callable<Rectangle>() { //$NON-NLS-1$
        @Override/* www .  ja  va 2  s  . c  om*/
        public Rectangle call() throws Exception {
            List<? extends TreeCell> tCells = ComponentHandler.getAssignableFrom(TreeCell.class);
            for (TreeCell<?> cell : tCells) {
                TreeItem<?> item = cell.getTreeItem();
                TreeView<?> tree = (TreeView<?>) getTree();
                if ((item != null && item.equals(node))) {
                    // Update the layout coordinates otherwise
                    // we would get old position values
                    tree.layout();

                    Point2D posTree = tree.localToScreen(0, 0);
                    Point2D posCell = cell.localToScreen(0, 0);
                    Bounds b = cell.getBoundsInParent();
                    Rectangle cBounds = new Rectangle(
                            Math.abs(Rounding.round((posCell.getX() - posTree.getX()))),
                            Math.abs(Rounding.round((posCell.getY() - posTree.getY()))),
                            Rounding.round(b.getWidth()), Rounding.round(b.getHeight()));
                    return cBounds;
                }
            }
            return null;
        }
    });
    return result;
}

From source file:org.eclipse.jubula.rc.javafx.tester.TreeTableViewTester.java

@Override
protected Object getNodeAtMousePosition() throws StepExecutionException {
    Point awtPoint = getRobot().getCurrentMousePosition();
    final Point2D point = new Point2D(awtPoint.x, awtPoint.y);
    Object result = EventThreadQueuerJavaFXImpl.invokeAndWait("getNodeAtMousePosition", new Callable<Object>() { //$NON-NLS-1$
        @Override/*from  w  w  w .  ja va 2  s  .c  o m*/
        public Object call() throws Exception {
            // Update the layout coordinates otherwise
            // we would get old position values
            ((TreeTableView<?>) getRealComponent()).layout();

            List<TreeTableCell> tCells = new NodeTraverseHelper<TreeTableCell>()
                    .getInstancesOf((Parent) getRealComponent(), TreeTableCell.class);
            for (TreeTableCell cell : tCells) {
                if (NodeBounds.checkIfContains(point, cell)) {
                    return cell;
                }
            }
            throw new StepExecutionException("No tree node found at mouse position: " //$NON-NLS-1$
                    + "X: " + point.getX() //$NON-NLS-1$
                    + "Y: " + point.getY(), //$NON-NLS-1$
                    EventFactory.createActionError(TestErrorEvent.NOT_FOUND));
        }
    });
    return result;
}

From source file:org.pdfsam.ui.selection.LoadingStatusIndicator.java

/**
 * Show a password request right below the wrapped Control
 *//*  www  .  ja  v  a 2  s .  co m*/
public void showPasswordRequest() {
    Scene scene = this.getScene();
    if (scene != null) {
        Window owner = scene.getWindow();
        if (owner != null && owner.isShowing()) {
            Point2D nodeCoord = this.localToScene(this.getWidth() / 2, this.getHeight() / 1.5);
            double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2);
            double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() + 2);
            popup.showFor(descriptorProvider.getPdfDocumentDescriptor(), this, anchorX, anchorY);
        }
    }
}