javafx.event.WeakEventHandler Java Examples
The following examples show how to use
javafx.event.WeakEventHandler.
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 |
private void registerListeners() { widthProperty().addListener(o -> resize()); heightProperty().addListener(o -> resize()); sceneProperty().addListener(o -> { if (!locations.isEmpty()) { addShapesToScene(locations.values()); } if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); } locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> { if (CHANGE.wasAdded()) { addShapesToScene(CHANGE.getValueAdded()); } else if(CHANGE.wasRemoved()) { Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved())); } }); }); }
Example #2
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 #3
Source File: World.java From worldfx with Apache License 2.0 | 6 votes |
private void registerListeners() { widthProperty().addListener(o -> resize()); heightProperty().addListener(o -> resize()); sceneProperty().addListener(o -> { if (!locations.isEmpty()) { addShapesToScene(locations.values()); } if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); } locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> { if (CHANGE.wasAdded()) { addShapesToScene(CHANGE.getValueAdded()); } else if(CHANGE.wasRemoved()) { Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved())); } }); }); }
Example #4
Source File: SunburstChart.java From OEE-Designer with MIT License | 5 votes |
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode NODE) { double startAngleRad = Math.toRadians(START_ANGLE + 90); double endAngleRad = Math.toRadians(END_ANGLE + 90); boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0; double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad); double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad); double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad); double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad); double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad); double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad); double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad); double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad); MoveTo moveTo1 = new MoveTo(x1, y1); LineTo lineTo2 = new LineTo(x2, y2); ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true); LineTo lineTo4 = new LineTo(x4, y4); ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false); Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1); path.setFill(FILL); path.setStroke(STROKE); String tooltipText = new StringBuilder(NODE.getData().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getData().getValue())).toString(); Tooltip.install(path, new Tooltip(tooltipText)); path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED)))); return path; }
Example #5
Source File: SunburstChart.java From charts with Apache License 2.0 | 5 votes |
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Paint FILL, final Color STROKE, final TreeNode NODE) { double startAngleRad = Math.toRadians(START_ANGLE + 90); double endAngleRad = Math.toRadians(END_ANGLE + 90); boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0; double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad); double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad); double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad); double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad); double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad); double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad); double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad); double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad); MoveTo moveTo1 = new MoveTo(x1, y1); LineTo lineTo2 = new LineTo(x2, y2); ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true); LineTo lineTo4 = new LineTo(x4, y4); ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false); Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1); path.setFill(FILL); path.setStroke(STROKE); String tooltipText = new StringBuilder(NODE.getItem().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getItem().getValue())).toString(); Tooltip.install(path, new Tooltip(tooltipText)); path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED)))); return path; }
Example #6
Source File: SunburstChart.java From tilesfx with Apache License 2.0 | 5 votes |
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode<ChartData> NODE) { double startAngleRad = Math.toRadians(START_ANGLE + 90); double endAngleRad = Math.toRadians(END_ANGLE + 90); boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0; double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad); double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad); double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad); double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad); double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad); double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad); double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad); double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad); MoveTo moveTo1 = new MoveTo(x1, y1); LineTo lineTo2 = new LineTo(x2, y2); ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true); LineTo lineTo4 = new LineTo(x4, y4); ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false); Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1); path.setFill(FILL); path.setStroke(STROKE); String tooltipText = new StringBuilder(NODE.getItem().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getItem().getValue())).toString(); Tooltip.install(path, new Tooltip(tooltipText)); path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED)))); return path; }
Example #7
Source File: World.java From worldfx with Apache License 2.0 | 5 votes |
private void initGraphics() { if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) { if (getPrefWidth() > 0 && getPrefHeight() > 0) { setPrefSize(getPrefWidth(), getPrefHeight()); } else { setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } getStyleClass().add("world"); Color fill = getFillColor(); Color stroke = getStrokeColor(); countryPaths.forEach((name, pathList) -> { Country country = Country.valueOf(name); pathList.forEach(path -> { path.setFill(null == country.getColor() ? fill : country.getColor()); path.setStroke(stroke); path.setStrokeWidth(0.2); path.setOnMouseEntered(new WeakEventHandler<>(_mouseEnterHandler)); path.setOnMousePressed(new WeakEventHandler<>(_mousePressHandler)); path.setOnMouseReleased(new WeakEventHandler<>(_mouseReleaseHandler)); path.setOnMouseExited(new WeakEventHandler<>(_mouseExitHandler)); }); pane.getChildren().addAll(pathList); }); group.getChildren().add(pane); getChildren().setAll(group); setBackground(new Background(new BackgroundFill(getBackgroundColor(), CornerRadii.EMPTY, Insets.EMPTY))); }
Example #8
Source File: World.java From worldfx with Apache License 2.0 | 5 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; FontIcon locationIcon = new FontIcon(null == LOCATION.getIconCode() ? locationIconCode : LOCATION.getIconCode()); locationIcon.setIconSize(LOCATION.getIconSize()); locationIcon.setTextOrigin(VPos.CENTER); locationIcon.setIconColor(null == LOCATION.getColor() ? getLocationColor() : LOCATION.getColor()); locationIcon.setX(x - LOCATION.getIconSize() * 0.5); locationIcon.setY(y); 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 #9
Source File: World.java From charts with Apache License 2.0 | 4 votes |
private void initGraphics() { if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) { if (getPrefWidth() > 0 && getPrefHeight() > 0) { setPrefSize(getPrefWidth(), getPrefHeight()); } else { setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } getStyleClass().add("world"); Color fill = getFillColor(); Color stroke = getStrokeColor(); countryPaths.forEach((name, pathList) -> { Country country = Country.valueOf(name); pathList.forEach(path -> { path.setFill(null == country.getColor() ? fill : country.getColor()); path.setStroke(stroke); path.setStrokeWidth(0.2); path.setOnMouseEntered(new WeakEventHandler<>(_mouseEnterHandler)); path.setOnMousePressed(new WeakEventHandler<>(_mousePressHandler)); path.setOnMouseReleased(new WeakEventHandler<>(_mouseReleaseHandler)); path.setOnMouseExited(new WeakEventHandler<>(_mouseExitHandler)); }); pane.getChildren().addAll(pathList); }); group.getChildren().add(pane); heatMap = HeatMapBuilder.create() .prefSize(1009, 665) .colorMapping(colorMapping) .spotRadius(spotRadius) .fadeColors(fadeColors) .opacityDistribution(opacityDistribution) .heatMapOpacity(heatMapOpacity) .build(); getChildren().setAll(group, heatMap); setBackground(new Background(new BackgroundFill(getBackgroundColor(), CornerRadii.EMPTY, Insets.EMPTY))); }
Example #10
Source File: VuMeterSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void initGraphics() { hBox = new HBox(); hBox.getStyleClass().setAll("vu-meter"); hBox.setSpacing(getSkinnable().getLedSpacing()); vBox = new VBox(); vBox.getStyleClass().setAll("vu-meter"); vBox.setSpacing(getSkinnable().getLedSpacing()); leds = FXCollections.observableArrayList(); for (int i = 0 ; i < getSkinnable().getNoOfLeds() ; i++) { Region led = new Region(); led.setOnMouseClicked(new WeakEventHandler<>(event -> active = !active)); led.setOnMouseEntered(new WeakEventHandler<>(event -> handleMouseEvent(event))); if (getSkinnable().getSections().isEmpty()) { led.getStyleClass().setAll("led"); } else { for (Section section : getSkinnable().getSections()) { if (section.contains(i * stepSize.doubleValue())) { led.getStyleClass().setAll("led", section.getStyleClass()); } } } leds.add(led); } if (Orientation.HORIZONTAL == getSkinnable().getOrientation()) { vBox.setManaged(false); vBox.setVisible(false); hBox.getChildren().setAll(leds); peakLedIndex = 0; } else { hBox.setManaged(false); hBox.setVisible(false); FXCollections.reverse(leds); vBox.getChildren().setAll(leds); peakLedIndex = leds.size() - 1; } // Add all nodes getChildren().setAll(hBox, vBox); }