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 csheets.ui.sheet.SpreadsheetTable;
026    
027    /**
028     * A table decorator visualizes extension-specific data by drawing on top of
029     * a table's graphics context. Decorators should respect the enabled state set
030     * on them.
031     * @author Einar Pehrson
032     */
033    public abstract class TableDecorator {
034    
035            /** Whether the decorator should be used when rendering, default is false */
036            protected boolean enabled = false;
037    
038            /**
039             * Creates a new table decorator.
040             */
041            public TableDecorator() {}
042    
043            /**
044             * Decorates the given graphics context, by drawing visualizations of
045             * extension-specific data on it.
046             * @param g the graphics context on which drawing should be done
047             * @param table the table displaying the spreadsheet to visualize
048             */
049            public abstract void decorate(Graphics g, SpreadsheetTable table);
050    
051            /**
052             * Returns whether the decorator should be used when rendering.
053             * @return true if the decorator should be used when rendering
054             */     
055            public final boolean isEnabled() {
056                    return enabled;
057            }
058    
059            /**
060             * Sets whether the decorator should be used when rendering.
061             * @param enabled whether the decorator should be used when rendering
062             */
063            public final void setEnabled(boolean enabled) {
064                    this.enabled = enabled;
065            }
066    }