/** Indicate that an alarm occurred. */ public void triggerd() { if (mode.equals(TIMER) || mode.equals(ONCE)) { setAlarmtime(NO_ALARM); } else { setAlarmtime(UNKNOWN); calc_allowed = true; } }
/** * Set the alarm time. * * @param time The alarm time. */ public void setTime(Time time) { Time oldtime = this.time; this.time = time; setAlarmtime(UNKNOWN); this.calc_allowed = true; if (pcs != null) pcs.firePropertyChange("time", oldtime, time); // setNextAlarmtime(); }
/** Calculate and save the next alarmtime. */ public synchronized void setNextAlarmtime(long currenttime) { // Check repeated for different threads that want to enter here. if (!calc_allowed) return; // long currenttime = clock.getTime(); long ret = NO_ALARM; if (mode.equals(ONCE)) { Calendar acal = new GregorianCalendar( time.getYear(), time.getMonth(), time.getMonthday(), time.getHours(), time.getMinutes(), time.getSeconds()); // System.out.println(time.year+" "+time.month+" "+time.monthday+" "+ // time.hours+" "+time.minutes+" "+time.seconds); // System.out.println(acal.getTime()+" "+new Date(currenttime)); if (acal.getTimeInMillis() > currenttime) ret = acal.getTime().getTime(); calc_allowed = false; } else if (mode.equals(HOURLY)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.set(Calendar.MINUTE, time.getMinutes()); acal.set(Calendar.SECOND, time.getSeconds()); // System.out.println(acal.getTime()+" "+new Date(currenttime)); if (acal.getTime().getTime() < currenttime) acal.add(Calendar.HOUR_OF_DAY, 1); ret = acal.getTime().getTime(); } else if (mode.equals(DAILY)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.set(Calendar.HOUR_OF_DAY, time.getHours()); acal.set(Calendar.MINUTE, time.getMinutes()); acal.set(Calendar.SECOND, time.getSeconds()); if (acal.getTime().getTime() < currenttime) acal.add(Calendar.DAY_OF_MONTH, 1); ret = acal.getTime().getTime(); } else if (mode.equals(WEEKLY)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.set(Calendar.DAY_OF_WEEK, time.getWeekday()); acal.set(Calendar.HOUR_OF_DAY, time.getHours()); acal.set(Calendar.MINUTE, time.getMinutes()); acal.set(Calendar.SECOND, time.getSeconds()); if (acal.getTime().getTime() < currenttime) acal.add(Calendar.WEEK_OF_YEAR, 1); ret = acal.getTime().getTime(); } else if (mode.equals(MONTHLY)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.set(Calendar.DAY_OF_MONTH, time.getMonthday()); acal.set(Calendar.HOUR_OF_DAY, time.getHours()); acal.set(Calendar.MINUTE, time.getMinutes()); acal.set(Calendar.SECOND, time.getSeconds()); if (acal.getTime().getTime() < currenttime) acal.add(Calendar.MONTH, 1); ret = acal.getTime().getTime(); } else if (mode.equals(YEARLY)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.set(Calendar.MONTH, time.getMonth()); acal.set(Calendar.DAY_OF_MONTH, time.getMonthday()); acal.set(Calendar.HOUR_OF_DAY, time.getHours()); acal.set(Calendar.MINUTE, time.getMinutes()); acal.set(Calendar.SECOND, time.getSeconds()); if (acal.getTime().getTime() < currenttime) acal.add(Calendar.YEAR, 1); ret = acal.getTime().getTime(); } else if (mode.equals(TIMER)) { Calendar acal = new GregorianCalendar(); acal.setTime(new Date(currenttime)); acal.add(Calendar.HOUR_OF_DAY, time.getHours()); acal.add(Calendar.MINUTE, time.getMinutes()); acal.add(Calendar.SECOND, time.getSeconds()); if (acal.getTime().getTime() >= currenttime) ret = acal.getTime().getTime(); } // System.out.println("setNextAlarmtime: "+getMessage()+" "+currenttime+" alarm: "+ret); calc_allowed = false; setAlarmtime(ret); }