Source code: com/clra/web/CalendarBean.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: CalendarBean.java,v $
5 * $Date: 2003/02/26 03:38:46 $
6 * $Revision: 1.3 $
7 */
8
9 package com.clra.web;
10
11 import java.io.Serializable;
12 import java.text.SimpleDateFormat;
13 import java.util.ArrayList;
14 import java.util.Calendar;
15 import java.util.GregorianCalendar;
16 import java.util.Iterator;
17
18 /**
19 * Represents a date in a GUI.
20 *
21 * @version $Revision: 1.3 $ $Date: 2003/02/26 03:38:46 $
22 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
23 */
24 public class CalendarBean implements Serializable {
25
26 private static String strAM = Text.getMessage( "time.am" );
27 private static String strPM = Text.getMessage( "time.pm" );
28
29 public static ArrayList yearList() {
30 return yearList( new GregorianCalendar().get(Calendar.YEAR) );
31 }
32
33 public static ArrayList yearList( int year ) {
34 if ( year < 0 ) throw new IllegalArgumentException("bad year == " + year);
35 ArrayList retVal = new ArrayList();
36 for ( int i = year - 1; i < year + 3; i++ ) {
37 String label = "" + i;
38 LabelValueBean lvb = new LabelValueBean( label, label );
39 retVal.add( lvb );
40 }
41 return retVal;
42 }
43
44 public static ArrayList monthList() {
45 ArrayList retVal = new ArrayList();
46 Calendar c = new GregorianCalendar();
47 c.set( Calendar.DATE, 1 );
48 SimpleDateFormat sdf = new SimpleDateFormat( "MMMM" );
49 for ( int i=0; i<12; i++ ) {
50 c.set( Calendar.MONTH, i );
51 String label = sdf.format( c.getTime() );
52 LabelValueBean lvb = new LabelValueBean( label, "" + i );
53 retVal.add( lvb );
54 }
55 return retVal;
56 }
57
58 public static ArrayList dayList() {
59 ArrayList retVal = new ArrayList();
60 for ( int i=1; i<32; i++ ) {
61 String label = "" + i;
62 LabelValueBean lvb = new LabelValueBean( label, "" + i );
63 retVal.add( lvb );
64 }
65 return retVal;
66 }
67
68 public static ArrayList hourList() {
69 ArrayList retVal = new ArrayList();
70 for ( int i=1; i<13; i++ ) {
71 String label = "" + i;
72 LabelValueBean lvb = new LabelValueBean( label, "" + i );
73 retVal.add( lvb );
74 }
75 return retVal;
76 }
77
78 public static ArrayList minuteList() {
79 ArrayList retVal = new ArrayList();
80 for ( int i=0; i<4; i++ ) {
81 int minute = 15*i;
82 String label = "" + minute;
83 if ( minute == 0 ) {
84 label = "00";
85 }
86 LabelValueBean lvb = new LabelValueBean( label, "" + minute );
87 retVal.add( lvb );
88 }
89 return retVal;
90 }
91
92 public static ArrayList ampmList() {
93
94 ArrayList retVal = new ArrayList();
95
96 LabelValueBean lvb = new LabelValueBean( strAM, "" + Calendar.AM );
97 retVal.add( lvb );
98
99 lvb = new LabelValueBean( strPM, "" + Calendar.PM );
100 retVal.add( lvb );
101
102 return retVal;
103 }
104
105 public static class Years implements Iterator {
106 private Iterator iterator = yearList().iterator();
107 public boolean hasNext() { return iterator.hasNext(); }
108 public Object next() { return iterator.next(); }
109 public void remove() { throw new UnsupportedOperationException(); }
110 }
111
112 public static class Months implements Iterator {
113 private Iterator iterator = monthList().iterator();
114 public boolean hasNext() { return iterator.hasNext(); }
115 public Object next() { return iterator.next(); }
116 public void remove() { throw new UnsupportedOperationException(); }
117 }
118
119 public static class Days implements Iterator {
120 private Iterator iterator = dayList().iterator();
121 public boolean hasNext() { return iterator.hasNext(); }
122 public Object next() { return iterator.next(); }
123 public void remove() { throw new UnsupportedOperationException(); }
124 }
125
126 public static class Hours implements Iterator {
127 private Iterator iterator = hourList().iterator();
128 public boolean hasNext() { return iterator.hasNext(); }
129 public Object next() { return iterator.next(); }
130 public void remove() { throw new UnsupportedOperationException(); }
131 }
132
133 public static class Minutes implements Iterator {
134 private Iterator iterator = minuteList().iterator();
135 public boolean hasNext() { return iterator.hasNext(); }
136 public Object next() { return iterator.next(); }
137 public void remove() { throw new UnsupportedOperationException(); }
138 }
139
140 public static class AmPm implements Iterator {
141 private Iterator iterator = ampmList().iterator();
142 public boolean hasNext() { return iterator.hasNext(); }
143 public Object next() { return iterator.next(); }
144 public void remove() { throw new UnsupportedOperationException(); }
145 }
146
147 } // CalendarBean
148
149 /*
150 * $Log: CalendarBean.java,v $
151 * Revision 1.3 2003/02/26 03:38:46 rphall
152 * Added copyright and GPL license
153 *
154 * Revision 1.2 2002/01/30 15:17:30 rphall
155 * Fixed a bug for day in month > 28
156 *
157 * Revision 1.2 2002/01/30 01:30:23 rphall
158 * Fixed bug for day in month > 28
159 *
160 * Revision 1.1 2001/12/01 14:06:05 rphall
161 * JSP bean
162 *
163 */
164