|
1 | 1 | /* |
2 | | - * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
27 | 27 |
|
28 | 28 |
|
29 | 29 | import com.sun.javafx.charts.Legend; |
| 30 | + |
| 31 | +import java.text.MessageFormat; |
30 | 32 | import java.util.ArrayList; |
31 | 33 | import java.util.BitSet; |
32 | 34 | import java.util.Collections; |
|
37 | 39 | import java.util.Map; |
38 | 40 | import java.util.Set; |
39 | 41 |
|
| 42 | +import com.sun.javafx.scene.control.skin.resources.ControlResources; |
40 | 43 | import javafx.animation.Interpolator; |
41 | 44 | import javafx.animation.KeyFrame; |
42 | 45 | import javafx.animation.KeyValue; |
|
45 | 48 | import javafx.beans.property.ObjectProperty; |
46 | 49 | import javafx.beans.property.ObjectPropertyBase; |
47 | 50 | import javafx.beans.property.ReadOnlyObjectProperty; |
| 51 | +import javafx.beans.property.ReadOnlyObjectPropertyBase; |
48 | 52 | import javafx.beans.property.ReadOnlyObjectWrapper; |
49 | 53 | import javafx.beans.property.SimpleObjectProperty; |
50 | 54 | import javafx.beans.property.StringProperty; |
51 | 55 | import javafx.beans.property.StringPropertyBase; |
| 56 | +import javafx.beans.value.ObservableValue; |
52 | 57 | import javafx.collections.FXCollections; |
53 | 58 | import javafx.collections.ListChangeListener; |
54 | 59 | import javafx.collections.ListChangeListener.Change; |
@@ -171,19 +176,63 @@ public abstract class XYChart<X,Y> extends Chart { |
171 | 176 | // -------------- PUBLIC PROPERTIES -------------------------------------------------------------------------------- |
172 | 177 |
|
173 | 178 | private final Axis<X> xAxis; |
| 179 | + |
| 180 | + private ReadOnlyObjectProperty<Axis<X>> xAxisProperty = new ReadOnlyObjectPropertyBase<Axis<X>>() { |
| 181 | + @Override |
| 182 | + public Object getBean() { |
| 183 | + return this; |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | + public String getName() { |
| 188 | + return "xAxis"; |
| 189 | + } |
| 190 | + |
| 191 | + @Override |
| 192 | + public Axis<X> get() { |
| 193 | + return xAxis; |
| 194 | + } |
| 195 | + }; |
| 196 | + |
174 | 197 | /** |
175 | 198 | * Get the X axis, by default it is along the bottom of the plot |
176 | 199 | * @return the X axis of the chart |
177 | 200 | */ |
178 | 201 | public Axis<X> getXAxis() { return xAxis; } |
179 | 202 |
|
| 203 | + private ObservableValue<Axis<X>> xAxisProperty() { |
| 204 | + return xAxisProperty; |
| 205 | + } |
| 206 | + |
180 | 207 | private final Axis<Y> yAxis; |
| 208 | + |
| 209 | + private ReadOnlyObjectProperty<Axis<Y>> yAxisProperty = new ReadOnlyObjectPropertyBase<Axis<Y>>() { |
| 210 | + @Override |
| 211 | + public Object getBean() { |
| 212 | + return this; |
| 213 | + } |
| 214 | + |
| 215 | + @Override |
| 216 | + public String getName() { |
| 217 | + return "yAxis"; |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public Axis<Y> get() { |
| 222 | + return yAxis; |
| 223 | + } |
| 224 | + }; |
| 225 | + |
181 | 226 | /** |
182 | 227 | * Get the Y axis, by default it is along the left of the plot |
183 | 228 | * @return the Y axis of this chart |
184 | 229 | */ |
185 | 230 | public Axis<Y> getYAxis() { return yAxis; } |
186 | 231 |
|
| 232 | + private ObservableValue<Axis<Y>> yAxisProperty() { |
| 233 | + return yAxisProperty; |
| 234 | + } |
| 235 | + |
187 | 236 | /** XYCharts data */ |
188 | 237 | private ObjectProperty<ObservableList<Series<X,Y>>> data = new ObjectPropertyBase<>() { |
189 | 238 | private ObservableList<Series<X,Y>> old; |
@@ -1212,8 +1261,10 @@ public final static class Data<X,Y> { |
1212 | 1261 | private boolean setToRemove = false; |
1213 | 1262 | /** The series this data belongs to */ |
1214 | 1263 | private Series<X,Y> series; |
| 1264 | + private ObjectProperty<Series<X, Y>> seriesProperty = new SimpleObjectProperty<>(); |
1215 | 1265 | void setSeries(Series<X,Y> series) { |
1216 | 1266 | this.series = series; |
| 1267 | + this.seriesProperty.set(series); |
1217 | 1268 | } |
1218 | 1269 |
|
1219 | 1270 | /** The generic data value to be plotted on the X axis */ |
@@ -1316,11 +1367,36 @@ protected void invalidated() { |
1316 | 1367 | Node node = get(); |
1317 | 1368 | if (node != null) { |
1318 | 1369 | node.accessibleTextProperty().unbind(); |
| 1370 | + ObservableValue<String> seriesLabel = seriesProperty |
| 1371 | + .flatMap(Series::nameProperty) |
| 1372 | + .orElse(""); |
| 1373 | + ObservableValue<String> xAxisLabel= seriesProperty |
| 1374 | + .flatMap(Series::chartProperty) |
| 1375 | + .flatMap(XYChart::xAxisProperty) |
| 1376 | + .flatMap(Axis::labelProperty) |
| 1377 | + .orElse(ControlResources.getString("XYChart.series.xaxis")); |
| 1378 | + ObservableValue<String> yAxisLabel = seriesProperty |
| 1379 | + .flatMap(Series::chartProperty) |
| 1380 | + .flatMap(XYChart::yAxisProperty) |
| 1381 | + .flatMap(Axis::labelProperty) |
| 1382 | + .orElse(ControlResources.getString("XYChart.series.yaxis")); |
1319 | 1383 | node.accessibleTextProperty().bind(new StringBinding() { |
1320 | | - {bind(currentXProperty(), currentYProperty());} |
| 1384 | + { |
| 1385 | + bind(currentXProperty(), |
| 1386 | + currentYProperty(), |
| 1387 | + seriesLabel, |
| 1388 | + xAxisLabel, |
| 1389 | + yAxisLabel); |
| 1390 | + } |
1321 | 1391 | @Override protected String computeValue() { |
1322 | | - String seriesName = series != null ? series.getName() : ""; |
1323 | | - return seriesName + " X Axis is " + getCurrentX() + " Y Axis is " + getCurrentY(); |
| 1392 | + String seriesName = seriesLabel.getValue(); |
| 1393 | + String xAxisName = xAxisLabel.getValue(); |
| 1394 | + String yAxisName = yAxisLabel.getValue(); |
| 1395 | + String format = ControlResources.getString("XYChart.series.accessibleText"); |
| 1396 | + MessageFormat mf = new MessageFormat(format); |
| 1397 | + Object[] args = {seriesName, xAxisName, getCurrentX(), yAxisName, getCurrentY()}; |
| 1398 | + String retVal = mf.format(args); |
| 1399 | + return retVal; |
1324 | 1400 | } |
1325 | 1401 | }); |
1326 | 1402 | } |
|
0 commit comments