555 return Slider.this;
556 }
557
558 @Override
559 public String getName() {
560 return "blockIncrement";
561 }
562 };
563 }
564 return blockIncrement;
565 }
566
567 /**
568 * Adjusts {@link #valueProperty() value} to match <code>newValue</code>. The
569 * <code>value</code>is the actual amount between the
570 * {@link #minProperty() min} and {@link #maxProperty() max}. This function
571 * also takes into account {@link #snapToTicksProperty() snapToTicks}, which
572 * is the main difference between adjustValue and setValue. It also ensures
573 * that the value is some valid number between min and max.
574 *
575 * @expert This function is intended to be used by experts, primarily
576 * by those implementing new Skins or Behaviors. It is not common
577 * for developers or designers to access this function directly.
578 */
579 public void adjustValue(double newValue) {
580 // figure out the "value" associated with the specified position
581 final double _min = getMin();
582 final double _max = getMax();
583 if (_max <= _min) return;
584 newValue = newValue < _min ? _min : newValue;
585 newValue = newValue > _max ? _max : newValue;
586
587 setValue(snapValueToTicks(newValue));
588 }
589
590 /**
591 * Increments the value by {@link #blockIncrementProperty() blockIncrement}, bounded by max. If the
592 * max is less than or equal to the min, then this method does nothing.
593 */
594 public void increment() {
595 adjustValue(getValue() + getBlockIncrement());
596 }
597
601 */
602 public void decrement() {
603 adjustValue(getValue() - getBlockIncrement());
604 }
605
606 /**
607 * Ensures that min is always < max, that value is always
608 * somewhere between the two, and that if snapToTicks is set then the
609 * value will always be set to align with a tick mark.
610 */
611 private void adjustValues() {
612 if ((getValue() < getMin() || getValue() > getMax()) /* && !isReadOnly(value)*/)
613 setValue(Utils.clamp(getMin(), getValue(), getMax()));
614 }
615
616 /**
617 * Utility function which, given the specified value, will position it
618 * either aligned with a tick, or simply clamp between min & max value,
619 * depending on whether snapToTicks is set.
620 *
621 * @expert This function is intended to be used by experts, primarily
622 * by those implementing new Skins or Behaviors. It is not common
623 * for developers or designers to access this function directly.
624 */
625 private double snapValueToTicks(double val) {
626 double v = val;
627 if (isSnapToTicks()) {
628 double tickSpacing = 0;
629 // compute the nearest tick to this value
630 if (getMinorTickCount() != 0) {
631 tickSpacing = getMajorTickUnit() / (Math.max(getMinorTickCount(),0)+1);
632 } else {
633 tickSpacing = getMajorTickUnit();
634 }
635 int prevTick = (int)((v - getMin())/ tickSpacing);
636 double prevTickValue = (prevTick) * tickSpacing + getMin();
637 double nextTickValue = (prevTick + 1) * tickSpacing + getMin();
638 v = Utils.nearest(prevTickValue, v, nextTickValue);
639 }
640 return Utils.clamp(getMin(), v, getMax());
641 }
|
555 return Slider.this;
556 }
557
558 @Override
559 public String getName() {
560 return "blockIncrement";
561 }
562 };
563 }
564 return blockIncrement;
565 }
566
567 /**
568 * Adjusts {@link #valueProperty() value} to match <code>newValue</code>. The
569 * <code>value</code>is the actual amount between the
570 * {@link #minProperty() min} and {@link #maxProperty() max}. This function
571 * also takes into account {@link #snapToTicksProperty() snapToTicks}, which
572 * is the main difference between adjustValue and setValue. It also ensures
573 * that the value is some valid number between min and max.
574 *
575 * Note: This function is intended to be used by experts, primarily
576 * by those implementing new Skins or Behaviors. It is not common
577 * for developers or designers to access this function directly.
578 * @param newValue the new adjusted value
579 */
580 public void adjustValue(double newValue) {
581 // figure out the "value" associated with the specified position
582 final double _min = getMin();
583 final double _max = getMax();
584 if (_max <= _min) return;
585 newValue = newValue < _min ? _min : newValue;
586 newValue = newValue > _max ? _max : newValue;
587
588 setValue(snapValueToTicks(newValue));
589 }
590
591 /**
592 * Increments the value by {@link #blockIncrementProperty() blockIncrement}, bounded by max. If the
593 * max is less than or equal to the min, then this method does nothing.
594 */
595 public void increment() {
596 adjustValue(getValue() + getBlockIncrement());
597 }
598
602 */
603 public void decrement() {
604 adjustValue(getValue() - getBlockIncrement());
605 }
606
607 /**
608 * Ensures that min is always < max, that value is always
609 * somewhere between the two, and that if snapToTicks is set then the
610 * value will always be set to align with a tick mark.
611 */
612 private void adjustValues() {
613 if ((getValue() < getMin() || getValue() > getMax()) /* && !isReadOnly(value)*/)
614 setValue(Utils.clamp(getMin(), getValue(), getMax()));
615 }
616
617 /**
618 * Utility function which, given the specified value, will position it
619 * either aligned with a tick, or simply clamp between min & max value,
620 * depending on whether snapToTicks is set.
621 *
622 * Note: This function is intended to be used by experts, primarily
623 * by those implementing new Skins or Behaviors. It is not common
624 * for developers or designers to access this function directly.
625 */
626 private double snapValueToTicks(double val) {
627 double v = val;
628 if (isSnapToTicks()) {
629 double tickSpacing = 0;
630 // compute the nearest tick to this value
631 if (getMinorTickCount() != 0) {
632 tickSpacing = getMajorTickUnit() / (Math.max(getMinorTickCount(),0)+1);
633 } else {
634 tickSpacing = getMajorTickUnit();
635 }
636 int prevTick = (int)((v - getMin())/ tickSpacing);
637 double prevTickValue = (prevTick) * tickSpacing + getMin();
638 double nextTickValue = (prevTick + 1) * tickSpacing + getMin();
639 v = Utils.nearest(prevTickValue, v, nextTickValue);
640 }
641 return Utils.clamp(getMin(), v, getMax());
642 }
|