< prev index next >

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

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.chart;
  27 

  28 import javafx.css.Styleable;
  29 import javafx.css.CssMetaData;
  30 import javafx.css.PseudoClass;
  31 import javafx.css.StyleableBooleanProperty;
  32 import javafx.css.StyleableDoubleProperty;
  33 import javafx.css.StyleableObjectProperty;
  34 
  35 import javafx.css.converter.BooleanConverter;
  36 import javafx.css.converter.EnumConverter;
  37 import javafx.css.converter.PaintConverter;
  38 import javafx.css.converter.SizeConverter;
  39 
  40 import java.util.*;
  41 
  42 import javafx.animation.FadeTransition;
  43 import javafx.beans.binding.DoubleExpression;
  44 import javafx.beans.binding.ObjectExpression;
  45 import javafx.beans.binding.StringExpression;
  46 import javafx.beans.property.*;
  47 import javafx.beans.value.WritableValue;


 420     /**
 421      * See if the current range is valid, if it is not then any range dependent calulcations need to redone on the next layout pass
 422      *
 423      * @return true if current range calculations are valid
 424      */
 425     protected final boolean isRangeValid() { return rangeValid; }
 426 
 427     /**
 428      * Mark the current range invalid, this will cause anything that depends on the range to be recalculated on the
 429      * next layout.
 430      */
 431     protected final void invalidateRange() { rangeValid = false; }
 432 
 433     /**
 434      * This is used to check if any given animation should run. It returns true if animation is enabled and the node
 435      * is visible and in a scene.
 436      *
 437      * @return true if animations should happen
 438      */
 439     protected final boolean shouldAnimate(){
 440         return getAnimated() && impl_isTreeVisible() && getScene() != null;
 441     }
 442 
 443     /**
 444      * We suppress requestLayout() calls here by doing nothing as we don't want changes to our children to cause
 445      * layout. If you really need to request layout then call requestAxisLayout().
 446      */
 447     @Override public void requestLayout() {}
 448 
 449     /**
 450      * Request that the axis is laid out in the next layout pass. This replaces requestLayout() as it has been
 451      * overridden to do nothing so that changes to children's bounds etc do not cause a layout. This was done as a
 452      * optimization as the Axis knows the exact minimal set of changes that really need layout to be updated. So we
 453      * only want to request layout then, not on any child change.
 454      */
 455     public void requestAxisLayout() {
 456         super.requestLayout();
 457     }
 458 
 459     /**
 460      * Called when data has changed and the range may not be valid any more. This is only called by the chart if


 637     /**
 638      * Invoked during the layout pass to layout this axis and all its content.
 639      */
 640     @Override protected void layoutChildren() {
 641         final double width = getWidth();
 642         final double height = getHeight();
 643         final double tickMarkLength = (isTickMarkVisible() && getTickLength() > 0) ? getTickLength() : 0;
 644         final boolean isFirstPass = oldLength == 0;
 645         // auto range if it is not valid
 646         final Side side = getEffectiveSide();
 647         final double length = (side.isVertical()) ? height : width;
 648         boolean rangeInvalid = !isRangeValid();
 649         boolean lengthDiffers = oldLength != length;
 650         if (lengthDiffers || rangeInvalid) {
 651             // get range
 652             Object range;
 653             if(isAutoRanging()) {
 654                 // auto range
 655                 range = autoRange(length);
 656                 // set current range to new range
 657                 setRange(range, getAnimated() && !isFirstPass && impl_isTreeVisible() && rangeInvalid);
 658             } else {
 659                 range = getRange();
 660             }
 661             // calculate new tick marks
 662             List<T> newTickValues = calculateTickValues(length, range);
 663 
 664             // remove everything
 665             Iterator<TickMark<T>> tickMarkIterator = tickMarks.iterator();
 666             while (tickMarkIterator.hasNext()) {
 667                 TickMark<T> tick = tickMarkIterator.next();
 668                 final TickMark<T> tm = tick;
 669                 if (shouldAnimate()) {
 670                     FadeTransition ft = new FadeTransition(Duration.millis(250),tick.textNode);
 671                     ft.setToValue(0);
 672                     ft.setOnFinished(actionEvent -> {
 673                         getChildren().remove(tm.textNode);
 674                     });
 675                     ft.play();
 676                 } else {
 677                     getChildren().remove(tm.textNode);




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.chart;
  27 
  28 import com.sun.javafx.scene.NodeHelper;
  29 import javafx.css.Styleable;
  30 import javafx.css.CssMetaData;
  31 import javafx.css.PseudoClass;
  32 import javafx.css.StyleableBooleanProperty;
  33 import javafx.css.StyleableDoubleProperty;
  34 import javafx.css.StyleableObjectProperty;
  35 
  36 import javafx.css.converter.BooleanConverter;
  37 import javafx.css.converter.EnumConverter;
  38 import javafx.css.converter.PaintConverter;
  39 import javafx.css.converter.SizeConverter;
  40 
  41 import java.util.*;
  42 
  43 import javafx.animation.FadeTransition;
  44 import javafx.beans.binding.DoubleExpression;
  45 import javafx.beans.binding.ObjectExpression;
  46 import javafx.beans.binding.StringExpression;
  47 import javafx.beans.property.*;
  48 import javafx.beans.value.WritableValue;


 421     /**
 422      * See if the current range is valid, if it is not then any range dependent calulcations need to redone on the next layout pass
 423      *
 424      * @return true if current range calculations are valid
 425      */
 426     protected final boolean isRangeValid() { return rangeValid; }
 427 
 428     /**
 429      * Mark the current range invalid, this will cause anything that depends on the range to be recalculated on the
 430      * next layout.
 431      */
 432     protected final void invalidateRange() { rangeValid = false; }
 433 
 434     /**
 435      * This is used to check if any given animation should run. It returns true if animation is enabled and the node
 436      * is visible and in a scene.
 437      *
 438      * @return true if animations should happen
 439      */
 440     protected final boolean shouldAnimate(){
 441         return getAnimated() && NodeHelper.isTreeVisible(this) && getScene() != null;
 442     }
 443 
 444     /**
 445      * We suppress requestLayout() calls here by doing nothing as we don't want changes to our children to cause
 446      * layout. If you really need to request layout then call requestAxisLayout().
 447      */
 448     @Override public void requestLayout() {}
 449 
 450     /**
 451      * Request that the axis is laid out in the next layout pass. This replaces requestLayout() as it has been
 452      * overridden to do nothing so that changes to children's bounds etc do not cause a layout. This was done as a
 453      * optimization as the Axis knows the exact minimal set of changes that really need layout to be updated. So we
 454      * only want to request layout then, not on any child change.
 455      */
 456     public void requestAxisLayout() {
 457         super.requestLayout();
 458     }
 459 
 460     /**
 461      * Called when data has changed and the range may not be valid any more. This is only called by the chart if


 638     /**
 639      * Invoked during the layout pass to layout this axis and all its content.
 640      */
 641     @Override protected void layoutChildren() {
 642         final double width = getWidth();
 643         final double height = getHeight();
 644         final double tickMarkLength = (isTickMarkVisible() && getTickLength() > 0) ? getTickLength() : 0;
 645         final boolean isFirstPass = oldLength == 0;
 646         // auto range if it is not valid
 647         final Side side = getEffectiveSide();
 648         final double length = (side.isVertical()) ? height : width;
 649         boolean rangeInvalid = !isRangeValid();
 650         boolean lengthDiffers = oldLength != length;
 651         if (lengthDiffers || rangeInvalid) {
 652             // get range
 653             Object range;
 654             if(isAutoRanging()) {
 655                 // auto range
 656                 range = autoRange(length);
 657                 // set current range to new range
 658                 setRange(range, getAnimated() && !isFirstPass && NodeHelper.isTreeVisible(this) && rangeInvalid);
 659             } else {
 660                 range = getRange();
 661             }
 662             // calculate new tick marks
 663             List<T> newTickValues = calculateTickValues(length, range);
 664 
 665             // remove everything
 666             Iterator<TickMark<T>> tickMarkIterator = tickMarks.iterator();
 667             while (tickMarkIterator.hasNext()) {
 668                 TickMark<T> tick = tickMarkIterator.next();
 669                 final TickMark<T> tm = tick;
 670                 if (shouldAnimate()) {
 671                     FadeTransition ft = new FadeTransition(Duration.millis(250),tick.textNode);
 672                     ft.setToValue(0);
 673                     ft.setOnFinished(actionEvent -> {
 674                         getChildren().remove(tm.textNode);
 675                     });
 676                     ft.play();
 677                 } else {
 678                     getChildren().remove(tm.textNode);


< prev index next >