001    package de.mospace.swing.event;
002    
003    /* de.mospace.swing library
004     * Copyright (C) 2005 Moritz Ringler
005     * $Id: MessageEvent.java 12 2007-07-27 09:48:53Z ringler $
006     *
007     * This program is free software; you can redistribute it and/or
008     * modify it under the terms of the GNU General Public License
009     * as published by the Free Software Foundation; either version 2
010     * of the License, or (at your option) any later version.
011     *
012     * This program is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with this program; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020     */
021    
022    import java.util.EventObject;
023    
024    /**
025     * A simple event consisting of a String message and a timeout
026     * for the duration of the message display.
027     * @version $Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
028     * @author Moritz Ringler
029     */
030    public class MessageEvent extends EventObject{
031        /** Type argument
032        * for the 3- and 4-argument MessageEvent constructors -
033        * for information messages. */
034        public final static int TYPE_INFO = 0;
035        
036        /** Type argument
037        * for the 3- and 4-argument MessageEvent constructors -
038        * for error messages. */
039        public final static int TYPE_ERROR     = 1;
040        
041        /** Type argument
042        * for the 3- and 4-argument MessageEvent constructors -
043        * for warning messages. */
044        public final static int TYPE_WARNING   = 2;
045        
046        /** Timeout argument
047        * for the 4-argument MessageEvent constructor
048        * that tells MessageListeners to use their respective
049        * default timeouts. */
050        public final static int DEFAULT_TIMEOUT = -1;
051        
052        /** Timeout argument
053        * for the 4-argument MessageEvent constructor
054        * that tells MessageListeners to not clear the message display. */
055        public final static int NO_CLEAR = 0;
056        private String message = "";
057        private int timeout = DEFAULT_TIMEOUT;
058        private int type = TYPE_INFO;
059    
060        /** Constructs a new message event with the specified source, and message.
061        * Equivalent to
062        * <code>MessageEvent(source, message, TYPE_INFO, DEFAULT_TIMEOUT)</code>
063        * @param source the source for the new event
064        * @param message the message for the new event
065        */
066        public MessageEvent(Object source, String message){
067            super(source);
068            this.message = message;
069        }
070    
071        /** Constructs a new message event with the specified source, message, and
072        * type. Equivalent to
073        * <code>MessageEvent(source, message, type, DEFAULT_TIMEOUT)</code>
074        * @param source the source for the new event
075        * @param message the message for the new event
076        * @param type the type of message for the new event. One of
077        * TYPE_INFO, TYPE_ERROR, TYPE_WARNING
078        */
079        public MessageEvent(Object source, String message, int type){
080            this(source, message);
081            this.type = type;
082        }
083        
084        /** Constructs a new message event with the specified source, message,
085        * type, and timeout.
086        * @param source the source for the new event
087        * @param message the message for the new event
088        * @param type the type of message for the new event. One of
089        * TYPE_INFO, TYPE_ERROR, TYPE_WARNING
090        * @param timeout the time period during which a listener should display
091        * the message
092        */
093        public MessageEvent(Object source, String message, int type, int timeout){
094            this(source, message, type);
095            this.timeout = timeout;
096        }
097    
098        /** Returns the message of this message event.
099        * @return the message of this message event.
100        */
101        public String getMessage(){
102            return message;
103        }
104    
105        /** Returns the timeout for this message event.
106        * @return the timeout for this message event.
107        */
108        public int getTimeout(){
109            return timeout;
110        }
111    }