1 14 package org.compiere.util; 15 16 import java.text.*; 17 import java.util.*; 18 19 27 public final class DisplayType 28 { 29 30 public static final int String = 10; 31 32 public static final int Integer = 11; 33 34 public static final int Amount = 12; 35 36 public static final int ID = 13; 37 38 public static final int Text = 14; 39 40 public static final int Date = 15; 41 42 public static final int DateTime = 16; 43 44 public static final int List = 17; 45 46 public static final int Table = 18; 47 48 public static final int TableDir = 19; 49 50 public static final int YesNo = 20; 51 52 public static final int Location = 21; 53 54 public static final int Number = 22; 55 56 public static final int Binary = 23; 57 58 public static final int Time = 24; 59 60 public static final int Account = 25; 61 62 public static final int RowID = 26; 63 64 public static final int Color = 27; 65 66 public static final int Button = 28; 67 68 public static final int Quantity = 29; 69 70 public static final int Search = 30; 71 72 public static final int Locator = 31; 73 74 public static final int Image = 32; 75 76 public static final int Assignment = 33; 77 78 public static final int Memo = 34; 79 80 public static final int PAttribute = 35; 81 82 public static final int TextLong = 36; 83 84 97 98 100 101 private static final int MAX_DIGITS = 28; 103 private static final int INTEGER_DIGITS = 10; 104 105 private static final int MAX_FRACTION = 12; 106 107 private static final int AMOUNT_FRACTION = 2; 108 109 115 public static boolean isID (int displayType) 116 { 117 if (displayType == ID || displayType == Table || displayType == TableDir 118 || displayType == Search || displayType == Location || displayType == Locator 119 || displayType == Account || displayType == Assignment || displayType == PAttribute) 120 return true; 121 return false; 122 } 124 130 public static boolean isNumeric(int displayType) 131 { 132 if (displayType == Amount || displayType == Number 133 || displayType == Integer || displayType == Quantity) 134 return true; 135 return false; 136 } 138 144 public static boolean isDate (int displayType) 145 { 146 if (displayType == Date || displayType == DateTime || displayType == Time) 147 return true; 148 return false; 149 } 151 157 public static boolean isLookup(int displayType) 158 { 159 if (displayType == List || displayType == Table 160 || displayType == TableDir || displayType == Search) 161 return true; 162 return false; 163 } 165 166 167 173 public static DecimalFormat getNumberFormat(int displayType, Language language) 174 { 175 Language myLanguage = language; 176 if (myLanguage == null) 177 myLanguage = Language.getLanguage(); 178 Locale locale = myLanguage.getLocale(); 179 DecimalFormat format = null; 180 if (locale != null) 181 format = (DecimalFormat)NumberFormat.getNumberInstance(locale); 182 else 183 format = (DecimalFormat)NumberFormat.getNumberInstance(Locale.US); 184 if (displayType == Integer) 186 { 187 format.setParseIntegerOnly(true); 188 format.setMaximumIntegerDigits(INTEGER_DIGITS); 189 format.setMaximumFractionDigits(0); 190 } 191 else if (displayType == Quantity) 192 { 193 format.setMaximumIntegerDigits(MAX_DIGITS); 194 format.setMaximumFractionDigits(MAX_FRACTION); 195 } 196 else if (displayType == Amount) 197 { 198 format.setMaximumIntegerDigits(MAX_DIGITS); 199 format.setMaximumFractionDigits(AMOUNT_FRACTION); 200 format.setMinimumFractionDigits(AMOUNT_FRACTION); 201 } 202 else { 204 format.setMaximumIntegerDigits(MAX_DIGITS); 205 format.setMaximumFractionDigits(MAX_FRACTION); 206 format.setMinimumFractionDigits(1); 207 } 208 return format; 209 } 211 216 public static DecimalFormat getNumberFormat(int displayType) 217 { 218 return getNumberFormat (displayType, null); 219 } 221 222 223 224 228 public static SimpleDateFormat getDateFormat() 229 { 230 return getDateFormat (DisplayType.Date, null); 231 } 233 238 public static SimpleDateFormat getDateFormat (Language language) 239 { 240 return getDateFormat (DisplayType.Date, language); 241 } 243 248 public static SimpleDateFormat getDateFormat (int displayType) 249 { 250 return getDateFormat (displayType, null); 251 } 253 259 public static SimpleDateFormat getDateFormat (int displayType, Language language) 260 { 261 Language myLanguage = language; 262 if (myLanguage == null) 263 myLanguage = Language.getLanguage(); 264 if (displayType == DateTime) 266 return myLanguage.getDateTimeFormat(); 267 else if (displayType == Time) 268 return myLanguage.getTimeFormat(); 269 return myLanguage.getDateFormat(); } 273 277 static public SimpleDateFormat getDateFormat_JDBC() 278 { 279 return new SimpleDateFormat ("yyyy-MM-dd"); 280 } 282 289 public static Class getClass (int displayType, boolean yesNoAsBoolean) 290 { 291 if (displayType == String || displayType == Text || displayType == TextLong 292 || displayType == List || displayType == Memo) 293 return String .class; 294 else if (isID(displayType) || displayType == Integer) return Integer .class; 296 else if (isNumeric(displayType)) 297 return java.math.BigDecimal .class; 298 else if (isDate(displayType)) 299 return java.sql.Timestamp .class; 300 else if (displayType == YesNo) 301 return yesNoAsBoolean ? Boolean .class : String .class; 302 else if (displayType == Button) 303 return String .class; 304 return Object .class; 306 } 308 } | Popular Tags |