Search in sources :

Example 1 with WeakEventHandler

use of javafx.event.WeakEventHandler in project Board-Instrumentation-Framework by intel.

the class VuMeterSkin method initGraphics.

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);
}
Also used : IntStream(java.util.stream.IntStream) Orientation(javafx.geometry.Orientation) SkinBase(javafx.scene.control.SkinBase) HBox(javafx.scene.layout.HBox) VuMeter(eu.hansolo.enzo.vumeter.VuMeter) Section(eu.hansolo.enzo.common.Section) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) WeakEventHandler(javafx.event.WeakEventHandler) DoubleProperty(javafx.beans.property.DoubleProperty) Skin(javafx.scene.control.Skin) VBox(javafx.scene.layout.VBox) AnimationTimer(javafx.animation.AnimationTimer) Region(javafx.scene.layout.Region) ListChangeListener(javafx.collections.ListChangeListener) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) HBox(javafx.scene.layout.HBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox) Section(eu.hansolo.enzo.common.Section)

Example 2 with WeakEventHandler

use of javafx.event.WeakEventHandler in project tilesfx by HanSolo.

the class SunburstChart method createSegment.

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;
}
Also used : Path(javafx.scene.shape.Path) Path(javafx.scene.shape.Path) Fonts(eu.hansolo.tilesfx.fonts.Fonts) TreeNode(eu.hansolo.tilesfx.tools.TreeNode) LineTo(javafx.scene.shape.LineTo) ArcTo(javafx.scene.shape.ArcTo) HashMap(java.util.HashMap) IntegerProperty(javafx.beans.property.IntegerProperty) InvalidationListener(javafx.beans.InvalidationListener) ArrayList(java.util.ArrayList) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) BorderWidths(javafx.scene.layout.BorderWidths) VPos(javafx.geometry.VPos) TreeNodeEvent(eu.hansolo.tilesfx.events.TreeNodeEvent) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) Map(java.util.Map) MoveTo(javafx.scene.shape.MoveTo) TextAlignment(javafx.scene.text.TextAlignment) Helper.clamp(eu.hansolo.tilesfx.tools.Helper.clamp) Tooltip(javafx.scene.control.Tooltip) Pane(javafx.scene.layout.Pane) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) GraphicsContext(javafx.scene.canvas.GraphicsContext) Node(javafx.scene.Node) Border(javafx.scene.layout.Border) ObjectPropertyBase(javafx.beans.property.ObjectPropertyBase) WeakEventHandler(javafx.event.WeakEventHandler) Canvas(javafx.scene.canvas.Canvas) IntegerPropertyBase(javafx.beans.property.IntegerPropertyBase) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BooleanPropertyBase(javafx.beans.property.BooleanPropertyBase) BorderStroke(javafx.scene.layout.BorderStroke) ArcType(javafx.scene.shape.ArcType) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) Region(javafx.scene.layout.Region) Paint(javafx.scene.paint.Paint) DefaultProperty(javafx.beans.DefaultProperty) EventType(eu.hansolo.tilesfx.events.TreeNodeEvent.EventType) StrokeLineCap(javafx.scene.shape.StrokeLineCap) ObservableList(javafx.collections.ObservableList) CornerRadii(javafx.scene.layout.CornerRadii) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) ArcTo(javafx.scene.shape.ArcTo) Tooltip(javafx.scene.control.Tooltip) TreeNodeEvent(eu.hansolo.tilesfx.events.TreeNodeEvent)

Aggregations

ObservableList (javafx.collections.ObservableList)2 WeakEventHandler (javafx.event.WeakEventHandler)2 Region (javafx.scene.layout.Region)2 Section (eu.hansolo.enzo.common.Section)1 VuMeter (eu.hansolo.enzo.vumeter.VuMeter)1 TreeNodeEvent (eu.hansolo.tilesfx.events.TreeNodeEvent)1 EventType (eu.hansolo.tilesfx.events.TreeNodeEvent.EventType)1 Fonts (eu.hansolo.tilesfx.fonts.Fonts)1 Helper (eu.hansolo.tilesfx.tools.Helper)1 Helper.clamp (eu.hansolo.tilesfx.tools.Helper.clamp)1 TreeNode (eu.hansolo.tilesfx.tools.TreeNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 IntStream (java.util.stream.IntStream)1 AnimationTimer (javafx.animation.AnimationTimer)1 DefaultProperty (javafx.beans.DefaultProperty)1 InvalidationListener (javafx.beans.InvalidationListener)1