001    /* BEE - Book Editing Environment for PAVLOV
002     * Copyright (C) 2004 T.J. Willis
003     * 
004     * This program is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU General Public License
006     * as published by the Free Software Foundation; either version 2
007     * of the License, or (at your option) any later version.
008     * 
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     * 
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, write to the Free Software
016     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017     *
018     * $Header: /cvsroot/pavlov/net/sourceforge/bee/VerificationTableCellRenderer.java,v 1.4 2004/05/10 14:46:07 tj_willis Exp $
019     */
020    package net.sourceforge.bee;
021    
022    import javax.swing.*;
023    import javax.swing.table.*;
024    
025    import java.awt.*;
026    
027    /**
028     * A TableCellRenerer that sets its background to red if there is an error
029     * in a question, i.e. duplicate ID's, invalid characters, etc.
030     *
031     * @author <a href="mailto:"></a>
032     * @version 1.0
033     */
034    public class VerificationTableCellRenderer
035      extends DefaultTableCellRenderer
036    {
037      private ChapterTableModel tmod;
038    
039        /**
040         * Creates a new <code>VerificationTableCellRenderer</code> instance.
041         *
042         * @param tMod a <code>ChapterTableModel</code> value
043         */
044        public VerificationTableCellRenderer(ChapterTableModel tMod)
045      {
046        tmod = tMod;
047      }
048    
049        /**
050         * Describe <code>getTableCellRendererComponent</code> method here.
051         *
052         * @param t a <code>JTable</code> value
053         * @param val an <code>Object</code> value
054         * @param sel a <code>boolean</code> value
055         * @param focus a <code>boolean</code> value
056         * @param r an <code>int</code> value
057         * @param c an <code>int</code> value
058         * @return a <code>Component</code> value
059         */
060        public Component getTableCellRendererComponent
061        (JTable t, Object val, boolean sel, boolean focus, int r, int c)
062      {
063        setEnabled(t == null || t.isEnabled());
064        //System.out.println(val.getClass());
065    
066        super.getTableCellRendererComponent(t, val, sel, focus, r,c);
067    
068        if(c==7 && val==null) setText("N/A");
069        if(val==null) return this;
070     
071        if(tmod.validEntry(r,c))
072          setBackground(null);
073        else
074          setBackground(Color.red);
075    
076        return this;
077      }
078    }
079    
080