IconCellRenderer.java :  » Net » SkunkDAV » org » skunk » swing » Java Open Source

Java Open Source » Net » SkunkDAV 
SkunkDAV » org » skunk » swing » IconCellRenderer.java
package org.skunk.swing;

import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * base class for table cell renderers that displays an icon.
 */
public abstract class IconCellRenderer extends DefaultTableCellRenderer
{
    /**
     * should return the icon which the table cell renderer should display.
     * @param table the JTable
     * @param value the value of the cell
     * @param isSelected whether the cell is selected
     * @param hasFocus whether the cell has focus
     * @param row the row of the cell in the table
     * @param column the column of the cell in the table
     * @return the icon that should be displayed by the renderer
     */
    protected abstract Icon getIcon(JTable table, Object value,
           boolean isSelected,
           boolean hasFocus,
           int row,
           int column);

    /**
     * overidden to display the icon returned by <code>getIcon()</code>.
     * @see getIcon.
     */
    public Component getTableCellRendererComponent(JTable table, Object value,
               boolean isSelected, 
               boolean hasFocus,
               int row, 
               int column)
    {
  DefaultTableCellRenderer renderer=(DefaultTableCellRenderer) 
      super.getTableCellRendererComponent(table, 
            value, 
            isSelected, 
            hasFocus, 
            row, 
            column);
  
  renderer.setHorizontalAlignment(SwingConstants.CENTER);
  renderer.setIcon(getIcon(table, value, isSelected, hasFocus, row, column));
  renderer.setText(null);
  return renderer;
    }
}

/* $Log: IconCellRenderer.java,v $
/* Revision 1.3  2001/01/04 06:02:49  smulloni
/* added more javadoc documentation.
/*
/* Revision 1.2  2000/11/14 23:19:48  smullyan
/* interface changed to refer to Icon, not ImageIcon
/*
/* Revision 1.1  2000/11/10 22:40:10  smullyan
/* added icon to table for resource type; fixes to copy and move; disabling of
/* menu items that are inappropriate.
/* */

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.