001 package com.croftsoft.apps.mars.view;
002
003 import java.awt.*;
004 import java.io.*;
005 import javax.swing.*;
006
007 import com.croftsoft.core.animation.ComponentAnimator;
008 import com.croftsoft.core.animation.animator.IconRowAnimator;
009 import com.croftsoft.core.awt.image.ImageCache;
010 import com.croftsoft.core.lang.NullArgumentException;
011
012 import com.croftsoft.apps.mars.model.TankAccessor;
013
014 /*********************************************************************
015 * Display the amount of ammo left in the tank.
016 *
017 * @version
018 * 2003-07-17
019 * @since
020 * 2003-03-28
021 * @author
022 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
023 *********************************************************************/
024
025 public final class TankAmmoAnimator
026 implements ComponentAnimator
027 //////////////////////////////////////////////////////////////////////
028 //////////////////////////////////////////////////////////////////////
029 {
030
031 private static final String BULLET_IMAGE_FILENAME = "bullet.png";
032
033 //
034
035 private final IconRowAnimator iconRowAnimator;
036
037 //
038
039 private TankAccessor tankAccessor;
040
041 //////////////////////////////////////////////////////////////////////
042 // constructor methods
043 //////////////////////////////////////////////////////////////////////
044
045 /*********************************************************************
046 * Main constructor.
047 *********************************************************************/
048 public TankAmmoAnimator (
049 TankAccessor tankAccessor,
050 ImageCache imageCache,
051 JComponent component )
052 throws IOException
053 //////////////////////////////////////////////////////////////////////
054 {
055 setTankAccessor ( tankAccessor );
056
057 iconRowAnimator = new IconRowAnimator (
058 new ImageIcon ( imageCache.get ( BULLET_IMAGE_FILENAME ) ),
059 tankAccessor.getAmmo ( ),
060 component );
061 }
062
063 //////////////////////////////////////////////////////////////////////
064 //////////////////////////////////////////////////////////////////////
065
066 public void setTankAccessor ( TankAccessor tankAccessor )
067 //////////////////////////////////////////////////////////////////////
068 {
069 NullArgumentException.check ( this.tankAccessor = tankAccessor );
070 }
071
072 //////////////////////////////////////////////////////////////////////
073 // interface ComponentAnimator methods
074 //////////////////////////////////////////////////////////////////////
075
076 public void update ( JComponent component )
077 //////////////////////////////////////////////////////////////////////
078 {
079 iconRowAnimator.setCount ( tankAccessor.getAmmo ( ) );
080
081 iconRowAnimator.update ( component );
082 }
083
084 public void paint (
085 JComponent component,
086 Graphics2D graphics )
087 //////////////////////////////////////////////////////////////////////
088 {
089 iconRowAnimator.paint ( component, graphics );
090 }
091
092 //////////////////////////////////////////////////////////////////////
093 //////////////////////////////////////////////////////////////////////
094 }