001    /*
002     * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>.
003     *
004     * This file is part of
005     * CleanSheets - a spreadsheet application for the Java platform.
006     *
007     * CleanSheets is free software; you can redistribute it and/or modify
008     * it under the terms of the GNU General Public License as published by
009     * the Free Software Foundation; either version 2 of the License, or
010     * (at your option) any later version.
011     *
012     * CleanSheets is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with CleanSheets; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020     */
021    package csheets.ui.ext;
022    
023    import java.awt.Graphics;
024    
025    import javax.swing.JComponent;
026    
027    import csheets.core.Cell;
028    
029    /**
030     * A cell decorator visualizes extension-specific data by drawing on top of
031     * a cell's graphics context. Decorators should respect the enabled state set
032     * on them.
033     * @author Einar Pehrson
034     */
035    public abstract class CellDecorator {
036    
037            /** Whether the decorator should be used when rendering, default is false */
038            protected boolean enabled = false;
039    
040            /**
041             * Creates a new cell decorator.
042             */
043            public CellDecorator() {}
044    
045            /**
046             * Decorates the given graphics context, by drawing visualizations of
047             * extension-specific data on it.
048             * @param component the cell renderer component
049             * @param g the graphics context on which drawing should be done
050             * @param cell the cell being rendered
051             * @param selected whether the cell is selected
052             * @param hasFocus whether the cell has focus
053             */
054            public abstract void decorate(JComponent component, Graphics g, Cell cell,
055                            boolean selected, boolean hasFocus);
056    
057            /**
058             * Returns whether the decorator should be used when rendering.
059             * @return true if the decorator should be used when rendering
060             */     
061            public final boolean isEnabled() {
062                    return enabled;
063            }
064    
065            /**
066             * Sets whether the decorator should be used when rendering.
067             * @param enabled whether the decorator should be used when rendering
068             */
069            public final void setEnabled(boolean enabled) {
070                    this.enabled = enabled;
071            }
072    }