001package kiwi.ui.propeditor; 002 003import kiwi.text.FormatConstants; 004import kiwi.util.*; 005 006public class NumericPropertyType extends PropertyType 007 implements FormatConstants 008 { 009 private int format; 010 private boolean hasMaxValue = false, hasMinValue = false; 011 private double maxValue, minValue; 012 private int decimals = 2; 013 private boolean grouping = true; 014 015 public NumericPropertyType() 016 { 017 this(FormatConstants.INTEGER_FORMAT); 018 } 019 020 public NumericPropertyType(int format) 021 { 022 this.format = format; 023 } 024 025 public void setMaximumValue(double maxValue) 026 { 027 this.maxValue = maxValue; 028 hasMaxValue = true; 029 } 030 031 public double getMaximumValue() 032 { 033 return(maxValue); 034 } 035 036 public boolean hasMaximumValue() 037 { 038 return(hasMaxValue); 039 } 040 041 public void setMinimumValue(double minValue) 042 { 043 this.minValue = minValue; 044 hasMinValue = true; 045 } 046 047 public void clearMinimumValue() 048 { 049 hasMinValue = false; 050 } 051 052 public void clearMaximumValue() 053 { 054 hasMaxValue = false; 055 } 056 057 public double getMinimumValue() 058 { 059 return(minValue); 060 } 061 062 public boolean hasMinimumValue() 063 { 064 return(hasMinValue); 065 } 066 067 public int getFormat() 068 { 069 return(format); 070 } 071 072 public String formatValue(Object value) 073 { 074 LocaleManager lm = LocaleManager.getDefault(); 075 String s = null; 076 double dval = ((DoubleHolder)value).getValue(); 077 078 switch(format) 079 { 080 case CURRENCY_FORMAT: 081 s = lm.formatCurrency(dval, decimals, grouping); 082 break; 083 084 case PERCENTAGE_FORMAT: 085 s = lm.formatPercentage(dval, decimals, grouping); 086 break; 087 088 case INTEGER_FORMAT: 089 s = lm.formatInteger((long)dval, grouping); 090 break; 091 092 case DECIMAL_FORMAT: 093 default: 094 s = lm.formatDecimal(dval, decimals, grouping); 095 break; 096 } 097 098 return(s); 099 } 100 101 } 102 103/* end of source file */