001 package com.croftsoft.apps.mars.view; 002 003 import java.awt.*; 004 import javax.swing.JComponent; 005 006 import com.croftsoft.core.lang.NullArgumentException; 007 import com.croftsoft.core.media.sound.AudioClipCache; 008 009 import com.croftsoft.apps.mars.model.AmmoDumpAccessor; 010 011 /********************************************************************* 012 * The view for an AmmoDump. 013 * 014 * @version 015 * 2003-04-17 016 * @since 017 * 2003-04-03 018 * @author 019 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 020 *********************************************************************/ 021 022 public final class AmmoDumpAnimator 023 extends ModelAnimator 024 ////////////////////////////////////////////////////////////////////// 025 ////////////////////////////////////////////////////////////////////// 026 { 027 028 private static final Color COLOR = Color.YELLOW; 029 030 private static final Color HIT_COLOR = Color.RED; 031 032 private static final String EXPLOSION_AUDIO_FILENAME = "explode.wav"; 033 034 // 035 036 private final AmmoDumpAccessor ammoDumpAccessor; 037 038 private final AudioClipCache audioClipCache; 039 040 ////////////////////////////////////////////////////////////////////// 041 ////////////////////////////////////////////////////////////////////// 042 043 public AmmoDumpAnimator ( 044 AmmoDumpAccessor ammoDumpAccessor, 045 AudioClipCache audioClipCache ) 046 ////////////////////////////////////////////////////////////////////// 047 { 048 super ( ammoDumpAccessor, COLOR ); 049 050 this.ammoDumpAccessor = ammoDumpAccessor; 051 052 NullArgumentException.check ( 053 this.audioClipCache = audioClipCache ); 054 } 055 056 ////////////////////////////////////////////////////////////////////// 057 ////////////////////////////////////////////////////////////////////// 058 059 public void update ( JComponent component ) 060 ////////////////////////////////////////////////////////////////////// 061 { 062 super.update ( component ); 063 064 if ( ammoDumpAccessor.isExploding ( ) ) 065 { 066 audioClipCache.play ( EXPLOSION_AUDIO_FILENAME ); 067 } 068 } 069 070 protected void getRepaintRectangle ( Rectangle repaintRectangle ) 071 ////////////////////////////////////////////////////////////////////// 072 { 073 if ( ammoDumpAccessor.isExploding ( ) ) 074 { 075 repaintRectangle.setBounds ( 076 ammoDumpAccessor.getExplosionShape ( ).getBounds ( ) ); 077 } 078 else 079 { 080 super.getRepaintRectangle ( repaintRectangle ); 081 } 082 } 083 084 public void paint ( 085 JComponent component, 086 Graphics2D graphics ) 087 ////////////////////////////////////////////////////////////////////// 088 { 089 if ( ammoDumpAccessor.isExploding ( ) ) 090 { 091 graphics.setColor ( HIT_COLOR ); 092 093 graphics.fill ( ammoDumpAccessor.getExplosionShape ( ) ); 094 } 095 else 096 { 097 super.paint ( component, graphics ); 098 } 099 } 100 101 ////////////////////////////////////////////////////////////////////// 102 ////////////////////////////////////////////////////////////////////// 103 }