1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.table;
  27 
  28 import java.awt.Component;
  29 import javax.swing.*;
  30 
  31 /**
  32  * This interface defines the method required by any object that
  33  * would like to be a renderer for cells in a <code>JTable</code>.
  34  *
  35  * @author Alan Chung
  36  */
  37 
  38 public interface TableCellRenderer {
  39 
  40     /**
  41      * Returns the component used for drawing the cell.  This method is
  42      * used to configure the renderer appropriately before drawing.
  43      * <p>
  44      * The <code>TableCellRenderer</code> is also responsible for rendering the
  45      * the cell representing the table's current DnD drop location if
  46      * it has one. If this renderer cares about rendering
  47      * the DnD drop location, it should query the table directly to
  48      * see if the given row and column represent the drop location:
  49      * <pre>
  50      *     JTable.DropLocation dropLocation = table.getDropLocation();
  51      *     if (dropLocation != null
  52      *             &amp;&amp; !dropLocation.isInsertRow()
  53      *             &amp;&amp; !dropLocation.isInsertColumn()
  54      *             &amp;&amp; dropLocation.getRow() == row
  55      *             &amp;&amp; dropLocation.getColumn() == column) {
  56      *
  57      *         // this cell represents the current drop location
  58      *         // so render it specially, perhaps with a different color
  59      *     }
  60      * </pre>
  61      * <p>
  62      * During a printing operation, this method will be called with
  63      * <code>isSelected</code> and <code>hasFocus</code> values of
  64      * <code>false</code> to prevent selection and focus from appearing
  65      * in the printed output. To do other customization based on whether
  66      * or not the table is being printed, check the return value from
  67      * {@link javax.swing.JComponent#isPaintingForPrint()}.
  68      *
  69      * @param   table           the <code>JTable</code> that is asking the
  70      *                          renderer to draw; can be <code>null</code>
  71      * @param   value           the value of the cell to be rendered.  It is
  72      *                          up to the specific renderer to interpret
  73      *                          and draw the value.  For example, if
  74      *                          <code>value</code>
  75      *                          is the string "true", it could be rendered as a
  76      *                          string or it could be rendered as a check
  77      *                          box that is checked.  <code>null</code> is a
  78      *                          valid value
  79      * @param   isSelected      true if the cell is to be rendered with the
  80      *                          selection highlighted; otherwise false
  81      * @param   hasFocus        if true, render cell appropriately.  For
  82      *                          example, put a special border on the cell, if
  83      *                          the cell can be edited, render in the color used
  84      *                          to indicate editing
  85      * @param   row             the row index of the cell being drawn.  When
  86      *                          drawing the header, the value of
  87      *                          <code>row</code> is -1
  88      * @param   column          the column index of the cell being drawn
  89      *
  90      * @return                  the component used for drawing the cell.
  91      *
  92      * @see javax.swing.JComponent#isPaintingForPrint()
  93      */
  94     Component getTableCellRendererComponent(JTable table, Object value,
  95                                             boolean isSelected, boolean hasFocus,
  96                                             int row, int column);
  97 }