01: /*
02: * @(#)DateQuarterGrouper.java 5/19/2006
03: *
04: * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
05: */
06:
07: package com.jidesoft.grouper.date;
08:
09: import com.jidesoft.converter.ConverterContext;
10: import com.jidesoft.converter.QuarterNameConverter;
11: import com.jidesoft.grouper.GroupResources;
12: import com.jidesoft.grouper.GrouperContext;
13:
14: import java.util.Calendar;
15: import java.util.Locale;
16:
17: public class DateQuarterGrouper extends DateGrouper {
18: public static GrouperContext CONTEXT = new GrouperContext(
19: "DateQuarter");
20:
21: private static Object[] _groups = null;
22:
23: public static Object[] getAvailableGroups() {
24: if (_groups == null) {
25: _groups = new Object[4];
26: for (int i = 0; i < _groups.length; i++) {
27: _groups[i] = i;
28: }
29: }
30: return _groups;
31: }
32:
33: public Object getValue(Object value) {
34: Object dateField = getCalendarField(value, Calendar.MONTH);
35: if (dateField instanceof Integer) {
36: return getAvailableGroups()[(Integer) dateField / 3];
37: } else {
38: return null;
39: }
40: }
41:
42: public String getName() {
43: return GroupResources.getResourceBundle(Locale.getDefault())
44: .getString("Date.quarter");
45: }
46:
47: @Override
48: public ConverterContext getConverterContext() {
49: return QuarterNameConverter.CONTEXT;
50: }
51:
52: // public static void main(String[] args) {
53: // ObjectGrouper grouper = new DateQuarterGrouper();
54: // Calendar calendar = Calendar.getInstance();
55: // for (int i = 0; i < 40; i++) {
56: // System.out.println(grouper.getValue(calendar));
57: // calendar.roll(Calendar.MONTH, 1);
58: // }
59: // }
60: }
|