KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > viewer > MarkAsReadTimer


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.message.viewer;
17
18 import java.util.Observable JavaDoc;
19 import java.util.Observer JavaDoc;
20 import java.util.Timer JavaDoc;
21 import java.util.logging.Logger JavaDoc;
22
23 import org.columba.core.xml.XmlElement;
24 import org.columba.mail.command.IMailFolderCommandReference;
25 import org.columba.mail.config.MailConfig;
26 import org.columba.mail.gui.message.IMessageController;
27
28
29 /**
30  * Title:
31  * Description: The MarkAsReadTimer marks a Message as read after a user defined
32  * time. This class self implements a actionListener. The class as a ActionListener is
33  * added to his own timer as ActionListener. So if the timer is started an then finished
34  * the timer calls the actionPerfomred Method of this class to do the marking thinks.
35  * Copyright: Copyright (c) 2001
36  * Company:
37  * @author fdietz, waffel
38  * @version 1.0
39  */

40 public class MarkAsReadTimer implements Observer JavaDoc {
41
42     /** JDK 1.4+ logging framework logger, used for logging. */
43     private static final Logger JavaDoc LOG = Logger.getLogger("org.columba.mail.gui.table.util");
44
45     // definition of a second
46
private static final int ONE_SECOND = 1000;
47
48     // timer to use
49
private int delay;
50     private boolean enabled;
51     
52     private Timer JavaDoc timer;
53     
54     // Singleton
55
private static MarkAsReadTimer myInstance = new MarkAsReadTimer();
56     
57     /**
58     * Creates a new MarkAsReadTimer. This should be only onced in a Session. The contructor
59     * fetched the time delay that the user configured.
60     */

61     protected MarkAsReadTimer() {
62         getConfigurationValues();
63
64         timer = new Timer JavaDoc();
65     }
66
67     /**
68      *
69      */

70     private void getConfigurationValues() {
71         XmlElement markasread = MailConfig.getInstance().get("options").getElement("/options/markasread");
72
73         // listen for configuration changes
74
markasread.addObserver(this);
75
76         // get interval value
77
String JavaDoc delayString = markasread.getAttribute("delay", "2");
78         delay = Integer.parseInt(delayString);
79
80         // enable timer
81
String JavaDoc enabledString = markasread.getAttribute("enabled", "true");
82         enabled = enabledString.equals("true") ? true : false;
83     }
84
85     public static MarkAsReadTimer getInstance() {
86         return myInstance;
87     }
88  
89     /**
90     * Restarts the timer. The given message is used later in the actionPerfomed mathod.
91     * This method is for example used by the ViewMessageCommand to restart the timer if a
92     * message is shown
93     */

94     public void start(IMessageController controller, IMailFolderCommandReference reference) {
95         if(enabled) {
96             timer.schedule( new MarkAsReadTimerTask(controller, reference), ONE_SECOND * delay);
97         }
98     }
99  
100     /* (non-Javadoc)
101      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
102      */

103     public void update(Observable JavaDoc arg0, Object JavaDoc arg1) {
104         LOG.info("/options/markasread#delay has changed");
105         
106         getConfigurationValues();
107     }
108 }
109
Popular Tags