source: trunk/src/org/expeditee/gui/Reminders.java@ 919

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.0 KB
Line 
1/**
2 * Reminders.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.gui;
20
21import java.awt.Color;
22import java.util.Date;
23
24import org.expeditee.actions.Misc;
25import org.expeditee.items.Text;
26import org.expeditee.items.widgets.charts.TimeSeries;
27
28public class Reminders {
29
30 public synchronized static void init(final Frame reminderFrame) {
31 if(reminderFrame == null)
32 return;
33
34 for (Text text : reminderFrame.getBodyTextItems(false)) {
35 try {
36 final Text reminderItem = text;
37 final AttributeValuePair avp = new AttributeValuePair(text
38 .getText(), true);
39 final String dateString = avp.getAttributeOrValue();
40 final String reminderString;
41 if (avp.hasPair()) {
42 reminderString = avp.getValue() + " at "
43 + avp.getAttribute();
44 } else {
45 reminderString = dateString;
46 }
47
48 Date date = TimeSeries.parseDate(dateString);
49 long millisToWait = date.getTime() - new Date().getTime();
50 final long adjustedToWait;
51
52 // Adjust the time to wait if their is no time left
53 if (millisToWait < 0) {
54 adjustedToWait = 0;
55 } else {
56 adjustedToWait = millisToWait;
57 }
58 // Now create the reminder
59 new Thread() {
60 public void run() {
61 try {
62 Thread.sleep(adjustedToWait);
63 synchronized (_alertsRunning) {
64 _alertsRunning++;
65 }
66
67 do {
68 Misc.beep();
69 MessageBay.displayMessage(
70 "Reminder: " + reminderString, null,
71 Color.red, false, "StopReminder");
72 Thread.sleep(5000);
73 // newMessage.setColor(new Color(100, 70, 70));
74 // Thread.sleep(100);
75 // newMessage.setColor(Color.red);
76 } while (!_bStop);
77 synchronized (_alertsRunning) {
78 assert (_alertsRunning > 0);
79 _alertsRunning--;
80 reminderItem.setText("@" + reminderItem.getText());
81 FrameIO.ForceSaveFrame(reminderItem.getParent());
82 if (_alertsRunning == 0) {
83 _bStop = false;
84 }
85 }
86 } catch (Exception e) {
87 //e.printStackTrace();
88 }
89 }
90 }.start();
91 } catch (Exception e) {
92 MessageBay.errorMessage("Invalid reminder format: "
93 + text.getText());
94 }
95 }
96 }
97
98 private static Boolean _bStop = false;
99
100 private static Integer _alertsRunning = 0;
101
102 public synchronized static void stop() {
103 if (_alertsRunning > 0)
104 _bStop = true;
105 }
106}
Note: See TracBrowser for help on using the repository browser.