001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.record;
025:
026: import jacareto.system.Environment;
027:
028: import java.io.Serializable;
029:
030: import java.util.Calendar;
031: import java.util.GregorianCalendar;
032:
033: /**
034: * This class represents calendar record elements.
035: *
036: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
037: * @version 1.01
038: */
039: public class CalendarRecordable extends Recordable implements
040: Serializable {
041: /** The calendar. */
042: private Calendar calendar;
043:
044: /**
045: * Creates a new calendar recordable with the specified values.
046: *
047: * @param env the environment
048: * @param calendar the calendar object to record
049: */
050: public CalendarRecordable(Environment env, Calendar calendar) {
051: super (env);
052: setCalendar(calendar);
053: }
054:
055: /**
056: * Creates a new calendar recordable with the specified values.
057: *
058: * @param env the environment
059: * @param year the year
060: * @param month the month
061: * @param date the date
062: * @param hourOfDay the hour of the day
063: * @param minute the minute
064: * @param second the second
065: */
066: public CalendarRecordable(Environment env, int year, int month,
067: int date, int hourOfDay, int minute, int second) {
068: this (env, new GregorianCalendar(year, month, date, hourOfDay,
069: minute, second));
070: }
071:
072: /**
073: * Creates a new calendar recordable with the actual time and date.
074: *
075: * @param env the environment
076: */
077: public CalendarRecordable(Environment env) {
078: this (env, new GregorianCalendar());
079: }
080:
081: /**
082: * Creates a new calendar recordable with no environment and the actual time and date. The
083: * environment should be defined with the method {@link
084: * jacareto.system.EnvironmentMember#setEnvironment(Environment)} before environment instances
085: * will be accessed.
086: */
087: public CalendarRecordable() {
088: this (null, new GregorianCalendar());
089: }
090:
091: /**
092: * Sets the values of this recordable to the values of the given calendar object.
093: *
094: * @param calendar the calendar object.
095: */
096: public void setCalendar(Calendar calendar) {
097: this .calendar = calendar;
098: fireValuesChanged();
099: }
100:
101: /**
102: * Returns the Calendar instance belonging to this recordable.
103: *
104: * @return the calender
105: */
106: public Calendar getCalendar() {
107: return calendar;
108: }
109:
110: /**
111: * Sets the year of the calendar.
112: *
113: * @param year the new year
114: */
115: public void setYear(int year) {
116: if (year < calendar.getActualMinimum(Calendar.YEAR)) {
117: calendar.set(calendar.getActualMinimum(Calendar.YEAR),
118: getMonth(), getDate(), getHourOfDay(), getMinute(),
119: getSecond());
120: } else if (year > calendar.getActualMaximum(Calendar.YEAR)) {
121: calendar.set(calendar.getActualMaximum(Calendar.YEAR),
122: getMonth(), getDate(), getHourOfDay(), getMinute(),
123: getSecond());
124: } else {
125: calendar.set(year, getMonth(), getDate(), getHourOfDay(),
126: getMinute(), getSecond());
127: }
128:
129: fireValuesChanged();
130: }
131:
132: /**
133: * Sets the month of the calendar (value between 1 and 12!).
134: *
135: * @param month the new month
136: */
137: public void setMonth(int month) {
138: if (month < calendar.getActualMinimum(Calendar.MONTH)) {
139: calendar.set(getYear(), calendar
140: .getActualMinimum(Calendar.MONTH), getDate(),
141: getHourOfDay(), getMinute(), getSecond());
142: } else if (month > calendar.getActualMaximum(Calendar.MONTH)) {
143: calendar.set(getYear(), calendar
144: .getActualMaximum(Calendar.MONTH), getDate(),
145: getHourOfDay(), getMinute(), getSecond());
146: } else {
147: calendar.set(getYear(), month, getDate(), getHourOfDay(),
148: getMinute(), getSecond());
149: }
150:
151: fireValuesChanged();
152: }
153:
154: /**
155: * Sets the date of the calendar.
156: *
157: * @param date the new date
158: */
159: public void setDate(int date) {
160: if (date < calendar.getActualMinimum(Calendar.DATE)) {
161: calendar.set(getYear(), getMonth(), calendar
162: .getActualMinimum(Calendar.DATE), getHourOfDay(),
163: getMinute(), getSecond());
164: } else if (date > calendar.getActualMaximum(Calendar.DATE)) {
165: calendar.set(getYear(), getMonth(), calendar
166: .getActualMaximum(Calendar.DATE), getHourOfDay(),
167: getMinute(), getSecond());
168: } else {
169: calendar.set(getYear(), getMonth(), date, getHourOfDay(),
170: getMinute(), getSecond());
171: }
172:
173: fireValuesChanged();
174: }
175:
176: /**
177: * Sets the "hour of day" of the calendar.
178: *
179: * @param hourOfDay the new "hour of day"
180: */
181: public void setHourOfDay(int hourOfDay) {
182: if (hourOfDay < calendar.getActualMinimum(Calendar.HOUR_OF_DAY)) {
183: calendar.set(getYear(), getMonth(), getDate(), calendar
184: .getActualMinimum(Calendar.HOUR_OF_DAY),
185: getMinute(), getSecond());
186: } else if (hourOfDay > calendar
187: .getActualMaximum(Calendar.HOUR_OF_DAY)) {
188: calendar.set(getYear(), getMonth(), getDate(), calendar
189: .getActualMaximum(Calendar.HOUR_OF_DAY),
190: getMinute(), getSecond());
191: } else {
192: calendar.set(getYear(), getMonth(), getDate(), hourOfDay,
193: getMinute(), getSecond());
194: }
195:
196: fireValuesChanged();
197: }
198:
199: /**
200: * Sets the minute of the calendar.
201: *
202: * @param minute the new minute
203: */
204: public void setMinute(int minute) {
205: if (minute < calendar.getActualMinimum(Calendar.MINUTE)) {
206: calendar.set(getYear(), getMonth(), getDate(),
207: getHourOfDay(), calendar
208: .getActualMinimum(Calendar.MINUTE),
209: getSecond());
210: } else if (minute > calendar.getActualMaximum(Calendar.MINUTE)) {
211: calendar.set(getYear(), getMonth(), getDate(),
212: getHourOfDay(), calendar
213: .getActualMaximum(Calendar.MINUTE),
214: getSecond());
215: } else {
216: calendar.set(getYear(), getMonth(), getDate(),
217: getHourOfDay(), minute, getSecond());
218: }
219:
220: fireValuesChanged();
221: }
222:
223: /**
224: * Sets the second of the calendar.
225: *
226: * @param second the new second
227: */
228: public void setSecond(int second) {
229: if (second < calendar.getActualMinimum(Calendar.SECOND)) {
230: calendar.set(getYear(), getMonth(), getDate(),
231: getHourOfDay(), getMinute(), calendar
232: .getActualMinimum(Calendar.SECOND));
233: } else if (second > calendar.getActualMaximum(Calendar.SECOND)) {
234: calendar.set(getYear(), getMonth(), getDate(),
235: getHourOfDay(), getMinute(), calendar
236: .getActualMaximum(Calendar.SECOND));
237: } else {
238: calendar.set(getYear(), getMonth(), getDate(),
239: getHourOfDay(), getMinute(), second);
240: }
241:
242: fireValuesChanged();
243: }
244:
245: /**
246: * Returns the year.
247: *
248: * @return the year
249: */
250: public int getYear() {
251: return calendar.get(Calendar.YEAR);
252: }
253:
254: /**
255: * Returns the month.
256: *
257: * @return the month
258: */
259: public int getMonth() {
260: return calendar.get(Calendar.MONTH);
261: }
262:
263: /**
264: * Returns the date.
265: *
266: * @return the date
267: */
268: public int getDate() {
269: return calendar.get(Calendar.DATE);
270: }
271:
272: /**
273: * Returns the hour of the day
274: *
275: * @return the hour
276: */
277: public int getHourOfDay() {
278: return calendar.get(Calendar.HOUR_OF_DAY);
279: }
280:
281: /**
282: * Returns the minute
283: *
284: * @return the minute
285: */
286: public int getMinute() {
287: return calendar.get(Calendar.MINUTE);
288: }
289:
290: /**
291: * Returns the second
292: *
293: * @return the second
294: */
295: public int getSecond() {
296: return calendar.get(Calendar.SECOND);
297: }
298:
299: /**
300: * Returns the name of the calender recordable
301: *
302: * @return the name
303: */
304: public String getElementName() {
305: return getLanguage().getString(
306: "Recordables.CalendarRecordable.Name");
307: }
308:
309: /**
310: * Returns a description of the recordable.
311: *
312: * @return the description
313: */
314: public String getElementDescription() {
315: return getLanguage().getString(
316: "Recordables.CalendarRecordable.Description");
317: }
318:
319: /**
320: * Returns a String which describes the content of the recordable shortly.
321: *
322: * @return a string with a short description of the object
323: */
324: public String toShortString() {
325: return getLanguage().getString(
326: "Recordables.CalendarRecordable.Name")
327: + " (" + toString() + ")";
328: }
329:
330: /**
331: * Returns a string representation of this object.
332: *
333: * @return the string
334: */
335: public String toString() {
336: return ((getDate() < 10) ? "0" : "") + getDate() + "."
337: + (((getMonth() + 1) < 10) ? "0" : "")
338: + (getMonth() + 1) + "." + getYear() + ", "
339: + ((getHourOfDay() < 10) ? "0" : "") + getHourOfDay()
340: + ":" + ((getMinute() < 10) ? "0" : "") + getMinute()
341: + ":" + ((getSecond() < 10) ? "0" : "") + getSecond();
342: }
343:
344: public boolean hasProcTime() {
345: return false;
346: }
347: }
|