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