001    /*
002     *  jDTAUS - DTAUS fileformat.
003     *  Copyright (c) 2005 Christian Schulte <cs@schulte.it>
004     *
005     *  This library is free software; you can redistribute it and/or
006     *  modify it under the terms of the GNU Lesser General Public
007     *  License as published by the Free Software Foundation; either
008     *  version 2.1 of the License, or any later version.
009     *
010     *  This library is distributed in the hope that it will be useful,
011     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     *  Lesser General Public License for more details.
014     *
015     *  You should have received a copy of the GNU Lesser General Public
016     *  License along with this library; if not, write to the Free Software
017     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
018     *
019     */
020    package org.jdtaus.core.text;
021    
022    import java.util.EventObject;
023    
024    /**
025     * Event holding a message.
026     *
027     * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
028     * @version $Id: MessageEvent.java 2201 2007-03-21 23:59:00Z schulte2005 $
029     */
030    public class MessageEvent extends EventObject
031    {
032    
033        //--Constants---------------------------------------------------------------
034    
035        /** Event constant for information messages. */
036        public static final int INFORMATION = 1;
037    
038        /** Event constant for notification messages. */
039        public static final int NOTIFICATION = 2;
040    
041        /** Event constant for warning messages. */
042        public static final int WARNING = 3;
043    
044        //---------------------------------------------------------------Constants--
045        //--Constructors------------------------------------------------------------
046    
047        /**
048         * Creates a new instance of {@code MessageEvent}.
049         *
050         * @param source the source of the new event.
051         * @param message the message causing the new event.
052         * @param type constant indicating the type of the event.
053         *
054         * @throws IllegalArgumentException if {@code type} is not equal to
055         * one of the constants {@code INFORMATION}, {@code NOTIFICATION} and
056         * {@code WARNING}.
057         */
058        public MessageEvent(final Object source, final Message message,
059            final int type)
060        {
061    
062            super(source);
063            this.message = message;
064            this.type = type;
065    
066            if(type != MessageEvent.INFORMATION
067                && type != MessageEvent.NOTIFICATION
068                && type != MessageEvent.WARNING)
069            {
070    
071                throw new IllegalArgumentException(Integer.toString(type));
072            }
073        }
074    
075        //------------------------------------------------------------Constructors--
076        //--MessageEvent------------------------------------------------------------
077    
078        /**
079         * Message causing this event.
080         * @serial
081         */
082        private final Message message;
083    
084        /**
085         * Type of the event.
086         * @serial
087         */
088        private final int type;
089    
090        /**
091         * Getter for property {@code message}.
092         *
093         * @return the message causing this event.
094         */
095        public final Message getMessage()
096        {
097            return this.message;
098        }
099    
100        /**
101         * Getter for property {@code type}.
102         *
103         * @return the type of the event.
104         */
105        public final int getType()
106        {
107            return this.type;
108        }
109    
110        /**
111         * Creates a string representing the properties of the instance.
112         *
113         * @return a string representing the properties of the instance.
114         */
115        private String internalString()
116        {
117            return new StringBuffer(500).
118                append("\n\ttype=").append(this.type).
119                append("\n\tmessage=").append(this.message).
120                toString();
121    
122        }
123    
124        //------------------------------------------------------------MessageEvent--
125        //--Object------------------------------------------------------------------
126    
127        /**
128         * Returns a string representation of the object.
129         *
130         * @return a string representation of the object.
131         */
132        public String toString()
133        {
134            return super.toString() + this.internalString();
135        }
136    
137        //------------------------------------------------------------------Object--
138    
139    }