1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.tethys.javafx.chart;
18
19 import javafx.collections.ObservableList;
20 import javafx.scene.Node;
21 import javafx.scene.chart.PieChart;
22 import javafx.scene.chart.PieChart.Data;
23 import javafx.scene.control.Tooltip;
24 import javafx.scene.input.MouseEvent;
25
26 import io.github.tonywasher.joceanus.tethys.core.chart.TethysUICorePieChart;
27 import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
28 import io.github.tonywasher.joceanus.tethys.javafx.base.TethysUIFXNode;
29
30
31
32
33 public class TethysUIFXPieChart
34 extends TethysUICorePieChart {
35
36
37
38 private final TethysUIFXNode theNode;
39
40
41
42
43 private final PieChart theChart;
44
45
46
47
48
49
50 TethysUIFXPieChart(final TethysUICoreFactory<?> pFactory) {
51
52 super(pFactory);
53
54
55 theChart = new PieChart();
56 theChart.setLabelsVisible(true);
57 theNode = new TethysUIFXNode(theChart);
58 }
59
60 @Override
61 public TethysUIFXNode getNode() {
62 return theNode;
63 }
64
65 @Override
66 public void setVisible(final boolean pVisible) {
67 theNode.setManaged(pVisible);
68 theNode.setVisible(pVisible);
69 }
70
71 @Override
72 public void setEnabled(final boolean pEnabled) {
73 theChart.setDisable(!pEnabled);
74 }
75
76 @Override
77 public void setPreferredWidth(final Integer pWidth) {
78 theChart.setPrefWidth(pWidth);
79 }
80
81 @Override
82 public void setPreferredHeight(final Integer pHeight) {
83 theChart.setPrefHeight(pHeight);
84 }
85
86 @Override
87 public void updatePieChart(final TethysUIPieChartData pData) {
88
89 super.updatePieChart(pData);
90
91
92 theChart.setTitle(pData.getTitle());
93 }
94
95 @Override
96 protected void resetData() {
97
98 final ObservableList<Data> myData = theChart.getData();
99 myData.clear();
100
101
102 super.resetData();
103 }
104
105 @Override
106 protected void createSlice(final TethysUIPieChartSection pSection) {
107
108 super.createSlice(pSection);
109
110
111 final String myName = pSection.getName();
112 final Data mySlice = new Data(myName, pSection.getValue().doubleValue());
113 final ObservableList<Data> myData = theChart.getData();
114 myData.add(mySlice);
115 final Node myNode = mySlice.getNode();
116
117
118 final String myTooltip = getToolTip(myName);
119 Tooltip.install(myNode, new Tooltip(myTooltip));
120
121
122 myNode.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> selectSection(myName));
123 }
124 }