List of usage examples for javafx.geometry Point2D getY
public final double getY()
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;// w ww . ja v a 2s . co 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 2s . c o 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.control.skin.LookupFieldSkin.java
private void positionAndShowPopup() { if (getPopup().getSkin() == null) { getSkinnable().getScene().getRoot().impl_processCSS(true); }//ww w . j a v a 2s. c o m 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: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 va2s . 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: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);// w ww . j ava 2s .c om 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: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// ww w . j a v a 2s .c o m * 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 w w w.j a v a2s .c o 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// w w w . j a va2 s. co m 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// w w w . jav a2 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 */// w w w . j a 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); } } }