changeset 6506:99caa949ca39

RT-27548: simplify code that removes/adds Axis tick-marks.
author David Grieve<david.grieve@oracle.com>
date Tue, 18 Mar 2014 15:57:19 -0400
parents d3f5ba2e8117
children c73e9b0c222e
files modules/controls/src/main/java/javafx/scene/chart/Axis.java modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java
diffstat 2 files changed, 12 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/chart/Axis.java	Tue Mar 18 12:50:23 2014 -0700
+++ b/modules/controls/src/main/java/javafx/scene/chart/Axis.java	Tue Mar 18 15:57:19 2014 -0400
@@ -37,6 +37,7 @@
 import com.sun.javafx.css.converters.SizeConverter;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
 import javafx.animation.FadeTransition;
@@ -646,32 +647,11 @@
                     maxWidth = Math.round(Math.max(maxWidth, measureTickMarkSize(value, range).getWidth()));
                 }
             }
-            // we have to work out what new or removed tick marks there are, then create new tick marks and their
-            // text nodes where needed
-            // find everything added or removed
-            List<T> added = new ArrayList<T>();
-            List<TickMark<T>> removed = new ArrayList<TickMark<T>>();
-            if(tickMarks.isEmpty()) {
-                added.addAll(newTickValues);
-            } else {
-                // find removed
-                for (TickMark<T> tick: tickMarks) {
-                    if(!newTickValues.contains(tick.getValue())) removed.add(tick);
-                }
-                // find added
-                for(T newValue: newTickValues) {
-                    boolean found = false;
-                    for (TickMark<T> tick: tickMarks) {
-                        if(tick.getValue().equals(newValue)) {
-                            found = true;
-                            break;
-                        }
-                    }
-                    if(!found) added.add(newValue);
-                }
-            }
-            // remove everything that needs to go
-            for(TickMark<T> tick: removed) {
+
+            // remove everything
+            Iterator<TickMark<T>> tickMarkIterator = tickMarks.iterator();
+            while (tickMarkIterator.hasNext()) {
+                TickMark<T> tick = tickMarkIterator.next();
                 final TickMark<T> tm = tick;
                 if (shouldAnimate()) {
                     FadeTransition ft = new FadeTransition(Duration.millis(250),tick.textNode);
@@ -686,10 +666,11 @@
                     getChildren().remove(tm.textNode);
                 }
                 // we have to remove the tick mark immediately so we don't draw tick line for it or grid lines and fills
-                tickMarks.remove(tm);
+                tickMarkIterator.remove();
             }
+
             // add new tick marks for new values
-            for(T newValue: added) {
+            for(T newValue: newTickValues) {
                 final TickMark<T> tick = new TickMark<T>();
                 tick.setValue(newValue);
                 tick.textNode.setText(getTickMarkLabel(newValue));
--- a/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java	Tue Mar 18 12:50:23 2014 -0700
+++ b/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java	Tue Mar 18 15:57:19 2014 -0400
@@ -56,9 +56,6 @@
 
     private final Path minorTickPath  = new Path();
 
-    private boolean saveMinorTickVisible = false;
-    private boolean restoreMinorTickVisiblity = false;
-    
     private double offset;
     /** This is the minimum current data value and it is used while auto ranging. */
     private double dataMinValue;
@@ -359,21 +356,11 @@
         super.layoutChildren();
         int numMinorTicks = (getTickMarks().size() - 1)*(getMinorTickCount() - 1);
         double neededLength = (getTickMarks().size()+numMinorTicks)*2;
-        if (length < neededLength) {
-            if (!restoreMinorTickVisiblity) {
-                restoreMinorTickVisiblity = true;
-                saveMinorTickVisible = isMinorTickVisible();
-                setMinorTickVisible(false);
-            }
-        } else {
-            if (restoreMinorTickVisiblity) {
-                setMinorTickVisible(saveMinorTickVisible);
-                restoreMinorTickVisiblity = false;
-            }
-        }
+
         // Update minor tickmarks
         minorTickPath.getElements().clear();
-        if (getMinorTickLength() > 0) {
+        // Don't draw minor tick marks if there isn't enough space for them!
+        if ((neededLength < length) && (0 < getMinorTickLength())) {
             if (Side.LEFT.equals(side)) {
                 // snap minorTickPath to pixels
                 minorTickPath.setLayoutX(-0.5);