Search in sources :

Example 1 with TreeNodeEvent

use of eu.hansolo.tilesfx.events.TreeNodeEvent 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

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 DefaultProperty (javafx.beans.DefaultProperty)1 InvalidationListener (javafx.beans.InvalidationListener)1 BooleanProperty (javafx.beans.property.BooleanProperty)1 BooleanPropertyBase (javafx.beans.property.BooleanPropertyBase)1 IntegerProperty (javafx.beans.property.IntegerProperty)1 IntegerPropertyBase (javafx.beans.property.IntegerPropertyBase)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 ObjectPropertyBase (javafx.beans.property.ObjectPropertyBase)1 ObservableList (javafx.collections.ObservableList)1