RoundedRangeLimitedDoubleProperty.java
/*
* *************************************************************************************************************************************************************
*
* MapView: a JavaFX map renderer for tile-based servers
* http://tidalwave.it/projects/mapview
*
* Copyright (C) 2024 - 2026 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *************************************************************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*
* *************************************************************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/mapview-src
* git clone https://github.com/tidalwave-it/mapview-src
*
* *************************************************************************************************************************************************************
*/
package it.tidalwave.mapview.impl;
import jakarta.annotation.Nonnull;
import java.util.Objects;
/***************************************************************************************************************************************************************
* A specialisation of {@link RangeLimitedDoubleProperty} that also rounds values to the nearest integer, before applying the limits.
* @author Fabrizio Giudici
**************************************************************************************************************************************************************/
public class RoundedRangeLimitedDoubleProperty extends RangeLimitedDoubleProperty
{
/***********************************************************************************************************************************************************
* Creates a new instance.
* @param bean the owner bean
* @param name the property name
* @param initialValue the initial value
* @param min the minimum value
* @param max the maximum value
* @see #setLimits(double, double)
**********************************************************************************************************************************************************/
public RoundedRangeLimitedDoubleProperty (@Nonnull final Object bean,
@Nonnull final String name,
final double initialValue,
final double min,
final double max)
{
super(bean, name, Math.round(initialValue), min, max);
}
/***********************************************************************************************************************************************************
* {@inheritDoc}
**********************************************************************************************************************************************************/
@Override
public void set (final double value)
{
super.set(Math.round(value));
}
/***********************************************************************************************************************************************************
* {@inheritDoc}
**********************************************************************************************************************************************************/
@Override
public void setValue (@Nonnull final Number value)
{
Objects.requireNonNull(value, "value");
super.setValue(Math.round(value.doubleValue()));
}
}