Skip to content

Commit 33f1f62

Browse files
Alexander ZuevAndy Goryachev
authored andcommitted
8298382: JavaFX ChartArea Accessibility Reader
Reviewed-by: kcr, angorya
1 parent e1f7d0c commit 33f1f62

File tree

3 files changed

+97
-7
lines changed

3 files changed

+97
-7
lines changed

modules/javafx.controls/src/main/java/javafx/scene/chart/PieChart.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,12 +25,14 @@
2525

2626
package javafx.scene.chart;
2727

28+
import java.text.MessageFormat;
2829
import java.util.ArrayList;
2930
import java.util.BitSet;
3031
import java.util.Collections;
3132
import java.util.List;
3233
import java.util.Objects;
3334

35+
import com.sun.javafx.scene.control.skin.resources.ControlResources;
3436
import javafx.animation.Animation;
3537
import javafx.animation.FadeTransition;
3638
import javafx.animation.Interpolator;
@@ -1007,7 +1009,10 @@ public Data(java.lang.String name, double value) {
10071009
textNode.accessibleTextProperty().bind( new StringBinding() {
10081010
{bind(nameProperty(), currentPieValueProperty());}
10091011
@Override protected String computeValue() {
1010-
return getName() + " represents " + getCurrentPieValue() + " percent";
1012+
String format = ControlResources.getString("PieChart.data.accessibleText");
1013+
MessageFormat mf = new MessageFormat(format);
1014+
Object[] args = {getName(), getCurrentPieValue()};
1015+
return mf.format(args);
10111016
}
10121017
});
10131018
}

modules/javafx.controls/src/main/java/javafx/scene/chart/XYChart.java

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@
2727

2828

2929
import com.sun.javafx.charts.Legend;
30+
31+
import java.text.MessageFormat;
3032
import java.util.ArrayList;
3133
import java.util.BitSet;
3234
import java.util.Collections;
@@ -37,6 +39,7 @@
3739
import java.util.Map;
3840
import java.util.Set;
3941

42+
import com.sun.javafx.scene.control.skin.resources.ControlResources;
4043
import javafx.animation.Interpolator;
4144
import javafx.animation.KeyFrame;
4245
import javafx.animation.KeyValue;
@@ -45,10 +48,12 @@
4548
import javafx.beans.property.ObjectProperty;
4649
import javafx.beans.property.ObjectPropertyBase;
4750
import javafx.beans.property.ReadOnlyObjectProperty;
51+
import javafx.beans.property.ReadOnlyObjectPropertyBase;
4852
import javafx.beans.property.ReadOnlyObjectWrapper;
4953
import javafx.beans.property.SimpleObjectProperty;
5054
import javafx.beans.property.StringProperty;
5155
import javafx.beans.property.StringPropertyBase;
56+
import javafx.beans.value.ObservableValue;
5257
import javafx.collections.FXCollections;
5358
import javafx.collections.ListChangeListener;
5459
import javafx.collections.ListChangeListener.Change;
@@ -171,19 +176,63 @@ public abstract class XYChart<X,Y> extends Chart {
171176
// -------------- PUBLIC PROPERTIES --------------------------------------------------------------------------------
172177

173178
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+
174197
/**
175198
* Get the X axis, by default it is along the bottom of the plot
176199
* @return the X axis of the chart
177200
*/
178201
public Axis<X> getXAxis() { return xAxis; }
179202

203+
private ObservableValue<Axis<X>> xAxisProperty() {
204+
return xAxisProperty;
205+
}
206+
180207
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+
181226
/**
182227
* Get the Y axis, by default it is along the left of the plot
183228
* @return the Y axis of this chart
184229
*/
185230
public Axis<Y> getYAxis() { return yAxis; }
186231

232+
private ObservableValue<Axis<Y>> yAxisProperty() {
233+
return yAxisProperty;
234+
}
235+
187236
/** XYCharts data */
188237
private ObjectProperty<ObservableList<Series<X,Y>>> data = new ObjectPropertyBase<>() {
189238
private ObservableList<Series<X,Y>> old;
@@ -1212,8 +1261,10 @@ public final static class Data<X,Y> {
12121261
private boolean setToRemove = false;
12131262
/** The series this data belongs to */
12141263
private Series<X,Y> series;
1264+
private ObjectProperty<Series<X, Y>> seriesProperty = new SimpleObjectProperty<>();
12151265
void setSeries(Series<X,Y> series) {
12161266
this.series = series;
1267+
this.seriesProperty.set(series);
12171268
}
12181269

12191270
/** The generic data value to be plotted on the X axis */
@@ -1316,11 +1367,36 @@ protected void invalidated() {
13161367
Node node = get();
13171368
if (node != null) {
13181369
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"));
13191383
node.accessibleTextProperty().bind(new StringBinding() {
1320-
{bind(currentXProperty(), currentYProperty());}
1384+
{
1385+
bind(currentXProperty(),
1386+
currentYProperty(),
1387+
seriesLabel,
1388+
xAxisLabel,
1389+
yAxisLabel);
1390+
}
13211391
@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;
13241400
}
13251401
});
13261402
}

modules/javafx.controls/src/main/resources/com/sun/javafx/scene/control/skin/resources/controls.properties

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -144,3 +144,12 @@ Dialog.warning.header=Warning
144144

145145
Dialog.confirm.title=Confirmation
146146
Dialog.confirm.header=Confirmation
147+
148+
### Charts ###
149+
# {seriesName} {xAxisName} is {currentX} {yAxisName} is {currentY}
150+
XYChart.series.accessibleText={0} {1} is {2} {3} is {4}
151+
XYChart.series.xaxis=X Axis
152+
XYChart.series.yaxis=Y Axis
153+
154+
# {sliceName} represents {currentValue} percent
155+
PieChart.data.accessibleText={0} represents {1} percent

0 commit comments

Comments
 (0)