001 package com.croftsoft.core.animation.painter; 002 003 import java.awt.Graphics2D; 004 import javax.swing.Icon; 005 import javax.swing.JComponent; 006 007 import com.croftsoft.core.lang.NullArgumentException; 008 009 /********************************************************************* 010 * Paints an Icon at an (x,y) position. 011 * 012 * @version 013 * 2003-07-11 014 * @since 015 * 2002-02-14 016 * @author 017 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 018 *********************************************************************/ 019 020 public class IconPainter 021 extends AbstractXYPainter 022 ////////////////////////////////////////////////////////////////////// 023 ////////////////////////////////////////////////////////////////////// 024 { 025 026 protected Icon icon; 027 028 ////////////////////////////////////////////////////////////////////// 029 ////////////////////////////////////////////////////////////////////// 030 031 public IconPainter ( 032 int x, 033 int y, 034 Icon icon ) 035 ////////////////////////////////////////////////////////////////////// 036 { 037 super ( x, y ); 038 039 setIcon ( icon ); 040 } 041 042 public IconPainter ( Icon icon ) 043 ////////////////////////////////////////////////////////////////////// 044 { 045 this ( 0, 0, icon ); 046 } 047 048 ////////////////////////////////////////////////////////////////////// 049 // accessor methods 050 ////////////////////////////////////////////////////////////////////// 051 052 public Icon getIcon ( ) { return icon; } 053 054 ////////////////////////////////////////////////////////////////////// 055 // mutator methods 056 ////////////////////////////////////////////////////////////////////// 057 058 public void setIcon ( Icon icon ) 059 ////////////////////////////////////////////////////////////////////// 060 { 061 NullArgumentException.check ( this.icon = icon ); 062 } 063 064 ////////////////////////////////////////////////////////////////////// 065 ////////////////////////////////////////////////////////////////////// 066 067 public void paint ( 068 JComponent component, 069 Graphics2D graphics ) 070 ////////////////////////////////////////////////////////////////////// 071 { 072 icon.paintIcon ( component, graphics, x, y ); 073 } 074 075 ////////////////////////////////////////////////////////////////////// 076 ////////////////////////////////////////////////////////////////////// 077 }