1 /* 2 * Copyright (c) 2003-2008 by Cosylab d. d. 3 * 4 * This file is part of CosyBeans-Common. 5 * 6 * CosyBeans-Common is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * CosyBeans-Common is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package com.cosylab.gui.components.range2; 21 22 import java.io.Serializable; 23 24 /** 25 * This class stores values representing RangedValue. No checks are made for 26 * validity of the values. Only purpose of this class is to provide data 27 * transfer between <code>RangedValue</code> and <code>RangedValuePolicy</code>. 28 * As such, this class will normaly be used only internaly by 29 * <code>RangedValue</code>. 30 * 31 * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a> 32 * @version $id$ 33 */ 34 public final class RangedValue implements Serializable { 35 36 private static final long serialVersionUID = 1L; 37 38 private double min; 39 40 private double max; 41 42 private double val; 43 44 public RangedValue() { 45 this(0, 100, 1); 46 } 47 48 /** 49 * @param minimum double 50 * @param maximum double 51 * @param value double 52 */ 53 public RangedValue(double minimum, double maximum, double value) { 54 min = minimum; 55 max = maximum; 56 val = value; 57 } 58 59 /** 60 * Returns the minimum. 61 * 62 * @return minimum 63 */ 64 public final double getMinimum() { 65 return min; 66 } 67 68 /** 69 * Returns the maximum. 70 * 71 * @return maximum 72 */ 73 public final double getMaximum() { 74 return max; 75 } 76 77 /** 78 * Returns the value. 79 * 80 * @return value 81 */ 82 public final double getValue() { 83 return val; 84 } 85 86 /** 87 * Check if the value is valid within bounds. 88 * 89 * @return 90 */ 91 public final boolean isValid() { 92 return ((min <= val) && (val <= max)); 93 } 94 95 /* 96 * (non-Javadoc) 97 * @see java.lang.Object#toString() 98 */ 99 public String toString() { 100 return getClass().getName()+" { min = "+min+", max = "+max+", val = "+val+" }"; 101 } 102 103 /** 104 * Returns a new RangedValue with min/max the same as this object, but with the 105 * given value. 106 * 107 * @param value new value for the RangedValue 108 * @return new RangedValue 109 */ 110 public RangedValue deriveWithValue(double value) { 111 return new RangedValue(min, max, value); 112 } 113 114 /** 115 * Returns a new RangedValue with min and value the same as this object, but with the 116 * given maximum. 117 * 118 * @param maximum new maximum for the RangedValue 119 * @return new RangedValue 120 */ 121 public RangedValue deriveWithMax(double maximum) { 122 return new RangedValue(min, maximum, val); 123 } 124 125 /** 126 * Returns a new RangedValue with max and value the same as this object, but with the 127 * given minimum. 128 * 129 * @param value new minimum for the RangedValue 130 * @return new RangedValue 131 */ 132 public RangedValue deriveWithMin(double minimum) { 133 return new RangedValue(minimum, max, val); 134 } 135 136 }