001         package com.croftsoft.apps.chat.view;
002    
003         import java.awt.*;
004         import java.awt.geom.*;
005         import java.io.*;
006         import java.util.*;
007         import javax.swing.JComponent;
008    
009         import com.croftsoft.core.animation.ComponentAnimator;
010         import com.croftsoft.core.animation.animator.ModelAnimator;
011         import com.croftsoft.core.animation.animator.WorldAnimator;
012         import com.croftsoft.core.animation.model.ModelAccessor;
013         import com.croftsoft.core.animation.model.WorldAccessor;
014         import com.croftsoft.core.animation.painter.ColorPainter;
015         import com.croftsoft.core.awt.image.ImageCache;
016         import com.croftsoft.core.lang.NullArgumentException;
017         import com.croftsoft.core.media.sound.AudioClipCache;
018    
019         import com.croftsoft.apps.chat.ChatConstants;
020         import com.croftsoft.apps.chat.model.ChatModelAccessor;
021    
022         /*********************************************************************
023         * ComponentAnimator for a ChatModel.
024         *
025         * @version
026         *   2003-07-23
027         * @since
028         *   2003-06-11
029         * @author
030         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
031         *********************************************************************/
032    
033         public final class  ChatModelAnimator
034           extends ModelAnimator
035         //////////////////////////////////////////////////////////////////////
036         //////////////////////////////////////////////////////////////////////
037         {
038    
039         private final ChatModelAccessor  chatModelAccessor;
040    
041         private final ImageCache         imageCache;
042    
043         private final AffineTransform    affineTransform;
044    
045         //////////////////////////////////////////////////////////////////////
046         //////////////////////////////////////////////////////////////////////
047    
048         public  ChatModelAnimator (
049           ChatModelAccessor  chatModelAccessor,
050           ImageCache         imageCache )
051         //////////////////////////////////////////////////////////////////////
052         {
053           super ( chatModelAccessor );
054    
055           this.chatModelAccessor = chatModelAccessor;
056    
057           NullArgumentException.check ( this.imageCache = imageCache );
058    
059           affineTransform = new AffineTransform ( );
060         }
061    
062         //////////////////////////////////////////////////////////////////////
063         //////////////////////////////////////////////////////////////////////
064    
065         public void  paint (
066           JComponent  component,
067           Graphics2D  graphics )
068         //////////////////////////////////////////////////////////////////////
069         {
070           if ( chatModelAccessor.isActive ( ) )
071           {
072             affineTransform.setToTranslation (
073               chatModelAccessor.getCenterX ( ) - ChatConstants.RADIUS,
074               chatModelAccessor.getCenterY ( ) - ChatConstants.RADIUS );
075    
076             try
077             {
078               graphics.drawImage (
079                 imageCache.get (
080                   chatModelAccessor.getAvatarType ( ).toLowerCase ( )
081                   + ChatConstants.AVATAR_IMAGE_FILENAME_EXTENSION ),
082                 affineTransform,
083                 null );
084             }
085             catch ( IOException  ex )
086             {
087               ex.printStackTrace ( );
088             }
089           }
090         }
091    
092         //////////////////////////////////////////////////////////////////////
093         //////////////////////////////////////////////////////////////////////
094         }