changeset 5228:31c7ced6e2e6

RT-27768 : PieChart adding new data lead to incorrect style class updating. reviwed by Jonathan.
author psomashe
date Wed, 02 Oct 2013 12:17:46 -0700
parents 67b0664167d6
children bd2f3d13cbf7
files modules/controls/src/main/java/javafx/scene/chart/PieChart.java
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/chart/PieChart.java	Wed Oct 02 14:53:01 2013 -0400
+++ b/modules/controls/src/main/java/javafx/scene/chart/PieChart.java	Wed Oct 02 12:17:46 2013 -0700
@@ -90,6 +90,7 @@
     private int defaultColorIndex = 0;
     private static final double LABEL_TICK_GAP = 6;
     private static final double LABEL_BALL_RADIUS = 2;
+    private static int uniqueId = 0;
     private double centerX;
     private double centerY;
     private double pieRadius;
@@ -145,7 +146,7 @@
             }
             for(int i=c.getFrom(); i<c.getTo(); i++) {
                 Data item = getData().get(i);
-                dataItemAdded(i, item);
+                dataItemAdded(item);
             }
             // update legend if any data has changed
             if (isLegendVisible() && (c.getRemoved().size() > 0 || c.getFrom() < c.getTo())) updateLegend();
@@ -336,6 +337,10 @@
 
     // -------------- METHODS --------------------------------------------------
 
+    private int getUniqueId() {
+        return uniqueId++;
+    }
+    
     private void dataNameChanged(Data item) {
         item.textNode.setText(item.getName());
         requestChartLayout();
@@ -356,7 +361,7 @@
         }
     }
 
-    private Node createArcRegion(int itemIndex, Data item) {
+    private Node createArcRegion(Data item) {
         Node arcRegion = item.getNode();
         // check if symbol has already been created
         if (arcRegion == null) {
@@ -365,26 +370,26 @@
             item.setNode(arcRegion);
         }
         // Note: not sure if we want to add or check, ie be more careful and efficient here
-        arcRegion.getStyleClass().setAll("chart-pie", "data" + itemIndex, item.defaultColorStyleString);
+        arcRegion.getStyleClass().setAll("chart-pie", "data" + getUniqueId(), item.defaultColorStyleString);
         if (item.getPieValue() < 0) {
             arcRegion.getStyleClass().add("negative");
         }
         return arcRegion;
     }
 
-    private Text createPieLabel(int itemIndex, Data item) {
+    private Text createPieLabel(Data item) {
         Text text = item.textNode;
         text.setText(item.getName());
         return text;
     }
 
-    private void dataItemAdded(int itemIndex, final Data item) {
+    private void dataItemAdded(final Data item) {
         // set default color styleClass
         item.defaultColorStyleString = "default-color"+(defaultColorIndex % 8);
         defaultColorIndex ++;
         // create shape
-        Node shape = createArcRegion(itemIndex, item);
-        final Text text = createPieLabel(itemIndex, item);
+        Node shape = createArcRegion(item);
+        final Text text = createPieLabel(item);
         item.getChart().getChartChildren().add(shape);
         if (shouldAnimate()) {
             // if the same data item is being removed, first stop the remove animation,