001         package com.croftsoft.core.animation.icon;
002    
003         import java.awt.*;
004         import javax.swing.Icon;
005    
006         import com.croftsoft.core.lang.NullArgumentException;
007    
008         /*********************************************************************
009         * An Icon that draws a colored square.
010         *
011         * @version
012         *   2003-03-17
013         * @since
014         *   2003-03-17
015         * @author
016         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
017         *********************************************************************/
018    
019         public final class  ColorTileIcon
020           implements Icon
021         //////////////////////////////////////////////////////////////////////
022         //////////////////////////////////////////////////////////////////////
023         {
024    
025         private final Color      color;
026    
027         private final Dimension  size;
028    
029         //////////////////////////////////////////////////////////////////////
030         //////////////////////////////////////////////////////////////////////
031    
032         public  ColorTileIcon (
033           Color      color,
034           Dimension  size )
035         //////////////////////////////////////////////////////////////////////
036         {
037           NullArgumentException.check ( this.color = color );
038    
039           this.size = size;
040         }
041    
042         public  ColorTileIcon ( Color  color )
043         //////////////////////////////////////////////////////////////////////
044         {
045           this ( color, ( Dimension ) null );
046         }
047    
048         //////////////////////////////////////////////////////////////////////
049         //////////////////////////////////////////////////////////////////////
050    
051         public int  getIconWidth  ( )
052         //////////////////////////////////////////////////////////////////////
053         {
054           if ( size == null )
055           {
056             return Integer.MAX_VALUE;
057           }
058           else
059           {
060             return size.width;
061           }
062         }
063    
064         public int  getIconHeight ( )
065         //////////////////////////////////////////////////////////////////////
066         {
067           if ( size == null )
068           {
069             return Integer.MAX_VALUE;
070           }
071           else
072           {
073             return size.height;
074           }
075         }
076    
077         //////////////////////////////////////////////////////////////////////
078         //////////////////////////////////////////////////////////////////////
079    
080         public void  paintIcon (
081           Component  component,
082           Graphics   graphics,
083           int        x,
084           int        y )
085         //////////////////////////////////////////////////////////////////////
086         {
087           graphics.setColor ( color );
088    
089           if ( size == null )
090           {
091             graphics.fillRect ( 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE );
092           }
093           else
094           {
095             graphics.fillRect ( x, y, size.width, size.height );
096           }
097         }
098    
099         //////////////////////////////////////////////////////////////////////
100         //////////////////////////////////////////////////////////////////////
101         }