001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.message.viewer;
017:
018: import java.util.Observable;
019: import java.util.Observer;
020: import java.util.Timer;
021: import java.util.logging.Logger;
022:
023: import org.columba.core.xml.XmlElement;
024: import org.columba.mail.command.IMailFolderCommandReference;
025: import org.columba.mail.config.MailConfig;
026: import org.columba.mail.gui.message.IMessageController;
027:
028: /**
029: * Title:
030: * Description: The MarkAsReadTimer marks a Message as read after a user defined
031: * time. This class self implements a actionListener. The class as a ActionListener is
032: * added to his own timer as ActionListener. So if the timer is started an then finished
033: * the timer calls the actionPerfomred Method of this class to do the marking thinks.
034: * Copyright: Copyright (c) 2001
035: * Company:
036: * @author fdietz, waffel
037: * @version 1.0
038: */
039: public class MarkAsReadTimer implements Observer {
040:
041: /** JDK 1.4+ logging framework logger, used for logging. */
042: private static final Logger LOG = Logger
043: .getLogger("org.columba.mail.gui.table.util");
044:
045: // definition of a second
046: private static final int ONE_SECOND = 1000;
047:
048: // timer to use
049: private int delay;
050: private boolean enabled;
051:
052: private Timer timer;
053:
054: // Singleton
055: private static MarkAsReadTimer myInstance = new MarkAsReadTimer();
056:
057: /**
058: * Creates a new MarkAsReadTimer. This should be only onced in a Session. The contructor
059: * fetched the time delay that the user configured.
060: */
061: protected MarkAsReadTimer() {
062: getConfigurationValues();
063:
064: timer = new Timer();
065: }
066:
067: /**
068: *
069: */
070: private void getConfigurationValues() {
071: XmlElement markasread = MailConfig.getInstance().get("options")
072: .getElement("/options/markasread");
073:
074: // listen for configuration changes
075: markasread.addObserver(this );
076:
077: // get interval value
078: String delayString = markasread.getAttribute("delay", "2");
079: delay = Integer.parseInt(delayString);
080:
081: // enable timer
082: String enabledString = markasread.getAttribute("enabled",
083: "true");
084: enabled = enabledString.equals("true") ? true : false;
085: }
086:
087: public static MarkAsReadTimer getInstance() {
088: return myInstance;
089: }
090:
091: /**
092: * Restarts the timer. The given message is used later in the actionPerfomed mathod.
093: * This method is for example used by the ViewMessageCommand to restart the timer if a
094: * message is shown
095: */
096: public void start(IMessageController controller,
097: IMailFolderCommandReference reference) {
098: if (enabled) {
099: timer.schedule(new MarkAsReadTimerTask(controller,
100: reference), ONE_SECOND * delay);
101: }
102: }
103:
104: /* (non-Javadoc)
105: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
106: */
107: public void update(Observable arg0, Object arg1) {
108: LOG.info("/options/markasread#delay has changed");
109:
110: getConfigurationValues();
111: }
112: }
|