Java Code Examples for javafx.scene.shape.Circle#setOnMousePressed()
The following examples show how to use
javafx.scene.shape.Circle#setOnMousePressed() .
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: World.java From charts with Apache License 2.0 | 6 votes |
public void addLocation(final Location LOCATION) { double x = (LOCATION.getLongitude() + 180) * (PREFERRED_WIDTH / 360) + MAP_OFFSET_X; double y = (PREFERRED_HEIGHT / 2) - (PREFERRED_WIDTH * (Math.log(Math.tan((Math.PI / 4) + (Math.toRadians(LOCATION.getLatitude()) / 2)))) / (2 * Math.PI)) + MAP_OFFSET_Y; Circle locationIcon = new Circle(x, y, size * 0.01); locationIcon.setFill(null == LOCATION.getColor() ? getLocationColor() : LOCATION.getColor()); StringBuilder tooltipBuilder = new StringBuilder(); if (!LOCATION.getName().isEmpty()) tooltipBuilder.append(LOCATION.getName()); if (!LOCATION.getInfo().isEmpty()) tooltipBuilder.append("\n").append(LOCATION.getInfo()); String tooltipText = tooltipBuilder.toString(); if (!tooltipText.isEmpty()) { Tooltip tooltip = new Tooltip(tooltipText); tooltip.setFont(Font.font(10)); Tooltip.install(locationIcon, tooltip); } if (null != LOCATION.getMouseEnterHandler()) locationIcon.setOnMouseEntered(new WeakEventHandler<>(LOCATION.getMouseEnterHandler())); if (null != LOCATION.getMousePressHandler()) locationIcon.setOnMousePressed(new WeakEventHandler<>(LOCATION.getMousePressHandler())); if (null != LOCATION.getMouseReleaseHandler()) locationIcon.setOnMouseReleased(new WeakEventHandler<>(LOCATION.getMouseReleaseHandler())); if (null != LOCATION.getMouseExitHandler()) locationIcon.setOnMouseExited(new WeakEventHandler<>(LOCATION.getMouseExitHandler())); locations.put(LOCATION, locationIcon); }
Example 2
Source File: BezierOffsetSnippet.java From gef with Eclipse Public License 2.0 | 4 votes |
protected void updateControlPoints() { controlPointsGroup.getChildren().clear(); for (int i = 0; i < controlPoints.size(); i++) { // get point Point cp = controlPoints.get(i); // create visual Circle cpVisual = new Circle(5); cpVisual.setCenterX(cp.x); cpVisual.setCenterY(cp.y); // bind colors cpVisual.strokeProperty().bind(controlPointsColorProperty); cpVisual.fillProperty().bind(controlPointsFillColorBinding); // add to view controlPointsGroup.getChildren().add(cpVisual); // register interactions final int index = i; final double[] cX = new double[] { 0d }; final double[] cY = new double[] { 0d }; final double[] initX = new double[] { 0d }; final double[] initY = new double[] { 0d }; cpVisual.setOnMousePressed((me) -> { validation = false; initX[0] = me.getSceneX(); initY[0] = me.getSceneY(); cX[0] = cpVisual.getCenterX(); cY[0] = cpVisual.getCenterY(); }); cpVisual.setOnMouseDragged((me) -> { Point pos = new Point(cX[0] + me.getSceneX() - initX[0], cY[0] + me.getSceneY() - initY[0]); controlPoints.set(index, pos); cpVisual.setCenterX(pos.x); cpVisual.setCenterY(pos.y); refreshAll(); }); cpVisual.setOnMouseReleased((me) -> { validation = true; refreshAll(); }); } }