001    package de.mospace.swing.icon;
002    
003    import java.awt.Color;
004    import java.awt.Component;
005    import java.awt.Graphics;
006    import javax.swing.Icon;
007    
008    /** A blank Java icon. 
009    * Original package: jp.gr.java_conf.tame.swing.icon
010    * This class is in the public domain.
011    * @version 1.0 02/26/99
012    */
013    public class BlankIcon implements Icon {
014        private Color fillColor;
015        private int size;
016        
017        /** Creates a transparent blank icon that is 11 px wide
018        * and 11 px high.*/
019        public BlankIcon() {
020            this(null, 11);
021        }
022        
023        /** Creates a new blank icon with the specified color and size.
024        * @param color the background color for the icon, if it is null the
025        * icon will be transparent
026        * @param size the size in pixels for the icon
027        */
028        public BlankIcon(Color color, int size) {
029            fillColor = color;
030            
031            this.size = size;
032        }
033        
034        /** Paints this icon on the specified graphics object at the
035        * specified location.
036        * @param c ignored, may be <code>null</code>
037        * @param g the graphics object to paint on
038        * @param x the x-offset for this icon
039        * @param y the y-offset for this icon
040        */
041        public void paintIcon(Component c, Graphics g, int x, int y) {
042            if (fillColor != null) {
043                g.setColor(fillColor);
044                g.drawRect(x, y, size-1, size-1);
045            }
046        }
047        
048        /**
049        * Gets the width of this icon.
050        *
051        * @return the width of this icon
052        */
053        public int getIconWidth() {
054            return size;
055        }
056        
057        /**
058        * Gets the height of this icon.
059        *
060        * @return the height of this icon
061        */
062        public int getIconHeight() {
063            return size;
064        }
065    }