001/* Class representing a type change for one Typeable object.
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.actor;
029
030import ptolemy.data.type.Type;
031import ptolemy.data.type.Typeable;
032import ptolemy.kernel.util.DebugEvent;
033import ptolemy.kernel.util.NamedObj;
034
035///////////////////////////////////////////////////////////////////
036//// TypeEvent
037
038/**
039 A TypeEvent represents a type change on a Typeable object.  This event is
040 generated by the Typeable whose type is changed, and is passed to the type
041 change listeners to notify them about the change.
042
043 @author Yuhong Xiong
044 @version $Id$
045 @since Ptolemy II 0.2
046 @Pt.ProposedRating Green (yuhong)
047 @Pt.AcceptedRating Green (cxh)
048 @see TypeListener
049 */
050public class TypeEvent implements DebugEvent {
051    ///////////////////////////////////////////////////////////////////
052    ////                         constructors                      ////
053
054    /** Construct a TypeEvent, with the specified Typeable and the
055     *  old and new types.
056     *  @param typeable The Typeable whose type is changed.
057     *  @param oldType The type of the Typeable before the change.
058     *  @param newType The type of the Typeable after the change.
059     */
060    public TypeEvent(Typeable typeable, Type oldType, Type newType) {
061        _typeable = typeable;
062        _oldType = oldType;
063        _newType = newType;
064    }
065
066    ///////////////////////////////////////////////////////////////////
067    ////                         public methods                    ////
068
069    /** Return the new type.
070     *  @return The type of the Typeable after the change.
071     */
072    public Type getNewType() {
073        return _newType;
074    }
075
076    /** Return the old type.
077     *  @return The type of the Typeable before the change.
078     */
079    public Type getOldType() {
080        return _oldType;
081    }
082
083    /** Return the Typeable whose type is changed.
084     *  @return The Typeable whose type is changed.
085     */
086    @Override
087    public NamedObj getSource() {
088        return (NamedObj) _typeable;
089    }
090
091    /** Return a string description for this type change. The string
092     *  is "The type on <i>typeable</i> has changed from <i>old
093     *  type</i> to <i>new type</i>", where <i>typeable</i> is the
094     *  name of the Typeable, and <i>old type</i> and <i>new type</i>
095     *  are the string representation of the types.
096     *  @return A string description for this type change.
097     */
098    @Override
099    public String toString() {
100        return "The type on " + getSource().getFullName() + " has changed "
101                + "from " + _oldType.toString() + " to " + _newType.toString();
102    }
103
104    ///////////////////////////////////////////////////////////////////
105    ////                       private fields                    ////
106    private Typeable _typeable;
107
108    private Type _oldType;
109
110    private Type _newType;
111}