private Point2D rotate(final Point2D a, final Point2D center, final double angle) { final double resultX = center.getX() + (a.getX() - center.getX()) * Math.cos(angle) - (a.getY() - center.getY()) * Math .sin(angle); final double resultY = center.getY() + (a.getX() - center.getX()) * Math.sin(angle) + (a.getY() - center.getY()) * Math .cos(angle); return new Point2D(resultX, resultY); }
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); }
private double[] circleFrom3Points(Point2D a, Point2D b, Point2D c) { double ax, ay, bx, by, cx, cy, x1, y11, dx1, dy1, x2, y2, dx2, dy2, ox, oy, dx, dy, radius; // Variables Used and to Declared ax = a.getX(); ay = a.getY(); //first Point X and Y bx = b.getX(); by = b.getY(); // Second Point X and Y cx = c.getX(); cy = c.getY(); // Third Point X and Y ////****************Following are Basic Procedure**********************/// x1 = (bx + ax) / 2; y11 = (by + ay) / 2; dy1 = bx - ax; dx1 = -(by - ay); x2 = (cx + bx) / 2; y2 = (cy + by) / 2; dy2 = cx - bx; dx2 = -(cy - by); ox = (y11 * dx1 * dx2 + x2 * dx1 * dy2 - x1 * dy1 * dx2 - y2 * dx1 * dx2) / (dx1 * dy2 - dy1 * dx2); oy = (ox - x1) * dy1 / dx1 + y11; dx = ox - ax; dy = oy - ay; radius = Math.sqrt(dx * dx + dy * dy); return new double[] {ox, oy, radius}; }
private Point2D scale(final Point2D a, final double scale) { return new Point2D(a.getX() * scale, a.getY() * scale); }
public CurveTransition(Point2D from, Point2D to) { this.from = from; double fromDx = from.getX() - centerX; double fromDy = from.getY() - centerY; fromTheta = Math.atan2(fromDy, fromDx); double toDx = to.getX() - centerX; double toDy = to.getY() - centerY; toTheta = Math.atan2(toDy, toDx); setInterpolator(Interpolator.EASE_BOTH); setDelay(Duration.millis(0)); setCycleDuration(Duration.millis(240)); }
@Override protected void interpolate(double frac) { double dif = Math.min(Math.abs(toTheta - fromTheta), 2 * Math.PI - Math.abs(toTheta - fromTheta)); if (dif == 2 * Math.PI - Math.abs(toTheta - fromTheta)) { int dir = -1; if (toTheta < fromTheta) { dir = 1; } dif = dir * dif; } else { dif = toTheta - fromTheta; } Point2D newP = rotate(from, new Point2D(centerX, centerY), frac * dif); colorSelector.setRotate(90 + Math.toDegrees(Math.atan2(newP.getY() - centerY, newP.getX() - centerX))); colorSelector.setTranslateX(newP.getX() - colorSelector.getPrefWidth() / 2); colorSelector.setTranslateY(newP.getY() - colorSelector.getPrefHeight() / 2); } }
private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dx = x - center.getX(); double dy = y - center.getY(); double distance = Math.sqrt((dx * dx) + (dy * dy)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
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; }
public void show(Node node){ if(!isShowing()){ if(node.getScene() == null || node.getScene().getWindow() == null) throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + ((Region)node).getHeight()); ((JFXAutoCompletePopupSkin<T>)getSkin()).animate(); } }
shapesNumber, -1); innerCircleCurve.setControlX1(controlPoint.getX()); innerCircleCurve.setControlY1(controlPoint.getY()); }); shapesNumber, -1); innerCircleCurve.setControlX1(controlPoint.getX()); innerCircleCurve.setControlY1(controlPoint.getY()); }); shapesNumber, 1); innerCircleCurve.setControlX2(controlPoint.getX()); innerCircleCurve.setControlY2(controlPoint.getY()); }); shapesNumber, 1); innerCircleCurve.setControlX2(controlPoint.getX()); innerCircleCurve.setControlY2(controlPoint.getY()); }); shapesNumber, -1); innerCircleCurve.setControlX1(controlPoint.getX()); innerCircleCurve.setControlY1(controlPoint.getY()); controlPoint = makeControlPoint(curves.get(1).getStartX(),
l = map(l, 0, 1, 0, 255); Point2D point = getPointFromSL((int) s, (int) l, slRadius); double pX = centerX - point.getX(); double pY = centerY - point.getY();
public void show(Node node) { if (text == null) { text = (Text) node.lookup(".text"); } node = text; if (!isShowing()) { if (node.getScene() == null || node.getScene().getWindow() == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + node.getLayoutBounds().getHeight() + shift); ((JFXAutoCompletePopupSkin<T>) getSkin()).animate(); } else { // if already showing update location if needed Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + node.getLayoutBounds().getHeight() + shift); } } }
/** * show the popup according to the specified position with a certain offset * * @param vAlign can be TOP/BOTTOM * @param hAlign can be LEFT/RIGHT * @param initOffsetX on the x axis * @param initOffsetY on the y axis */ public void show(Node node, PopupVPosition vAlign, PopupHPosition hAlign, double initOffsetX, double initOffsetY) { if (!isShowing()) { if (node.getScene() == null || node.getScene().getWindow() == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } Window parent = node.getScene().getWindow(); final Point2D origin = node.localToScene(0, 0); final double anchorX = parent.getX() + origin.getX() + node.getScene().getX() + (hAlign == PopupHPosition.RIGHT ? ((Region) node).getWidth() : 0); final double anchorY = parent.getY() + origin.getY() + node.getScene() .getY() + (vAlign == PopupVPosition.BOTTOM ? ((Region) node).getHeight() : 0); this.show(parent, anchorX, anchorY); ((JFXPopupSkin) getSkin()).reset(vAlign, hAlign, initOffsetX, initOffsetY); Platform.runLater(() -> ((JFXPopupSkin) getSkin()).animate()); } }
private Point2D getDisplayCoordiantes(Window owner, Scene scene) { Point2D nodeCoord = ValidableTextField.this.localToScene(0.0, ValidableTextField.this.getHeight()); double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2); double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() - 2); return new Point2D(anchorX, anchorY); } }
private void showPasswordFieldPopup() { Scene scene = this.getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing()) { Point2D nodeCoord = encryptionIndicator.localToScene(encryptionIndicator.getWidth() / 2, encryptionIndicator.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); passwordPopup.showFor(this, descriptor, anchorX, anchorY); } } }
@EventListener public void showPasswordFieldPopup(ShowPasswordFieldPopupRequest request) { Scene scene = this.getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing()) { Point2D nodeCoord = request.getRequestingNode().localToScene(request.getRequestingNode().getWidth() / 2, request.getRequestingNode().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); passwordPopup.showFor(this, request.getPdfDescriptor(), anchorX, anchorY); } } }
private ErrorTooltipManager(String message) { require(isNotBlank(message), "Tooltip message cannot be blank"); this.tooltip = new Tooltip(message); this.tooltip.getStyleClass().add(ERROR_TOOLTIP_CLASS); hideTimer.getKeyFrames().add(new KeyFrame(new Duration(5000))); hideTimer.setOnFinished(e -> { tooltip.hide(); ErrorTooltipManager.this.active = false; }); activationTimer.getKeyFrames().add(new KeyFrame(new Duration(250))); activationTimer.setOnFinished(e -> { if (!ErrorTooltipManager.this.active) { Scene scene = getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing() && ValidableTextField.this.isVisible()) { Point2D where = getDisplayCoordiantes(owner, scene); tooltip.show(ValidableTextField.this, where.getX(), where.getY()); ErrorTooltipManager.this.active = true; hideTimer.playFromStart(); } } } }); }
private static Text helpIcon(HelpPopup popup) { Text icon = MaterialDesignIconFactory.get().createIcon(MaterialDesignIcon.HELP_CIRCLE, "1.1em"); icon.setOnMouseEntered(e -> { Point2D p = icon.localToScreen(icon.getLayoutBounds().getMaxX(), icon.getLayoutBounds().getMaxY()); popup.show(icon, p.getX(), p.getY()); }); icon.setOnMouseExited(e -> popup.hide()); return icon; } }
@Override public void handle(javafx.scene.input.MouseEvent me) { Point2D cur = lowThumb.localToParent(me.getX(), me.getY()); double dragPos = (isHorizontal())? cur.getX() - preDragThumbPoint.getX() : -(cur.getY() - preDragThumbPoint.getY()); rangeSliderBehavior.lowThumbDragged(me, preDragPos + dragPos / trackLength); } });
@Override public void handle(MouseEvent e) { boolean orientation = ((RangeSlider) getSkinnable()).getOrientation() == Orientation.HORIZONTAL; double trackLength = orientation ? track.getWidth() : track.getHeight(); Point2D point2d = highThumb.localToParent(e.getX(), e.getY()); double d = ((RangeSlider) getSkinnable()).getOrientation() != Orientation.HORIZONTAL ? -(point2d.getY() - preDragThumbPoint.getY()) : point2d.getX() - preDragThumbPoint.getX(); rangeSliderBehavior.highThumbDragged(e, preDragPos + d / trackLength); } });