Skip to content

Package: RangeLimitedDoubleProperty

RangeLimitedDoubleProperty

nameinstructionbranchcomplexitylinemethod
RangeLimitedDoubleProperty(Object, String, double, double, double)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
set(double)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setLimits(double, double)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setValue(Number)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * MapView: a JavaFX map renderer for tile-based servers
5: * http://tidalwave.it/projects/mapview
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/mapview-src
22: * git clone https://github.com/tidalwave-it/mapview-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.mapviewer.impl;
27:
28: import jakarta.annotation.Nonnull;
29: import jakarta.annotation.Nullable;
30: import java.util.Objects;
31: import javafx.beans.property.SimpleDoubleProperty;
32:
33: /***************************************************************************************************************************************************************
34: *
35: * A specialisation of {@link javafx.beans.property.DoubleProperty} that supports limits.
36: *
37: * @author Fabrizio Giudici
38: *
39: **************************************************************************************************************************************************************/
40: public class RangeLimitedDoubleProperty extends SimpleDoubleProperty
41: {
42: private double min;
43:
44: private double max;
45:
46: /***********************************************************************************************************************************************************
47: * Creates a new instance.
48: * @param bean the owner bean
49: * @param name the property name
50: * @param initialValue the initial value
51: * @param min the minimum value
52: * @param max the maximum value
53: * @see #setLimits(double, double)
54: **********************************************************************************************************************************************************/
55: public RangeLimitedDoubleProperty (@Nonnull final Object bean, @Nonnull final String name, final double initialValue, final double min, final double max)
56: {
57: super(bean, name, Math.clamp(initialValue, min, max));
58: this.min = min;
59: this.max = max;
60: }
61:
62: /***********************************************************************************************************************************************************
63: * {@inheritDoc}
64: **********************************************************************************************************************************************************/
65: @Override
66: public void set (final double value)
67: {
68: super.set(Math.clamp(value, min, max));
69: }
70:
71: /***********************************************************************************************************************************************************
72: * {@inheritDoc}
73: **********************************************************************************************************************************************************/
74: @Override
75: public void setValue (@Nullable final Number value)
76: {
77: Objects.requireNonNull(value, "value");
78: super.setValue(Math.clamp(value.doubleValue(), min, max));
79: }
80:
81: /***********************************************************************************************************************************************************
82: * Changes the limit. The current property value will be eventually changed to fit the limits, and a change event fired.
83: * @param min the minimum value
84: * @param max the maximum value
85: **********************************************************************************************************************************************************/
86: public void setLimits (final double min, final double max)
87: {
88: this.min = min;
89: this.max = max;
90: set(get());
91: }
92: }