001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: IntegerProperty.java,v 1.4 2004/09/22 14:32:50 jesper Exp $
023: package net.infonode.properties.types;
024:
025: import net.infonode.properties.base.PropertyGroup;
026: import net.infonode.properties.util.PropertyValueHandler;
027:
028: /**
029: * An integer property.
030: *
031: * @author $Author: jesper $
032: * @version $Revision: 1.4 $
033: */
034: public class IntegerProperty extends NumberProperty {
035: /**
036: * Constructor.
037: * Creates an unbounded integer property.
038: *
039: * @param group the property group
040: * @param name the property name
041: * @param description the property description
042: * @param valueHandler handles values for this property
043: */
044: public IntegerProperty(PropertyGroup group, String name,
045: String description, PropertyValueHandler valueHandler) {
046: this (group, name, description, Integer.MIN_VALUE,
047: Integer.MAX_VALUE, -1, valueHandler);
048: }
049:
050: /**
051: * Constructor.
052: *
053: * @param group the property group
054: * @param name the property name
055: * @param description the property description
056: * @param min the smallest value that this property can have
057: * @param max the largest value that this property can have
058: * @param preferredDigitCount the preferred number of digits to allocate space for in an editor for a property value
059: * @param valueHandler handles values for this property
060: */
061: public IntegerProperty(PropertyGroup group, String name,
062: String description, int min, int max,
063: int preferredDigitCount, PropertyValueHandler valueHandler) {
064: super (group, name, Integer.class, description, min, max,
065: preferredDigitCount, valueHandler);
066: }
067:
068: /**
069: * Creates an integer property that can only be set to zero and positive integers.
070: *
071: * @param group the property group
072: * @param name the property name
073: * @param description the property description
074: * @param preferredDigitCount the preferred number of digits to allocate space for in an editor for a property value
075: * @param valueHandler handles values for this property
076: * @return an an integer property that can only be set to zero and positive integers
077: */
078: public static IntegerProperty createPositive(PropertyGroup group,
079: String name, String description, int preferredDigitCount,
080: PropertyValueHandler valueHandler) {
081: return new IntegerProperty(group, name, description, 0,
082: Integer.MAX_VALUE, preferredDigitCount, valueHandler);
083: }
084:
085: /**
086: * Returns the integer value of this property in a value container.
087: *
088: * @param valueContainer the value container
089: * @return the integer value of this property
090: */
091: public int get(Object valueContainer) {
092: return (int) getLongValue(valueContainer);
093: }
094:
095: /**
096: * Sets the integer value of this property in a value container.
097: *
098: * @param valueContainer the value container
099: * @param value the float value
100: */
101: public void set(Object valueContainer, int value) {
102: setValue(valueContainer, new Integer(value));
103: }
104:
105: }
|