01: package org.skunk.swing;
02:
03: import java.awt.Component;
04: import javax.swing.Icon;
05: import javax.swing.JTable;
06: import javax.swing.SwingConstants;
07: import javax.swing.table.DefaultTableCellRenderer;
08:
09: /**
10: * base class for table cell renderers that displays an icon.
11: */
12: public abstract class IconCellRenderer extends DefaultTableCellRenderer {
13: /**
14: * should return the icon which the table cell renderer should display.
15: * @param table the JTable
16: * @param value the value of the cell
17: * @param isSelected whether the cell is selected
18: * @param hasFocus whether the cell has focus
19: * @param row the row of the cell in the table
20: * @param column the column of the cell in the table
21: * @return the icon that should be displayed by the renderer
22: */
23: protected abstract Icon getIcon(JTable table, Object value,
24: boolean isSelected, boolean hasFocus, int row, int column);
25:
26: /**
27: * overidden to display the icon returned by <code>getIcon()</code>.
28: * @see getIcon.
29: */
30: public Component getTableCellRendererComponent(JTable table,
31: Object value, boolean isSelected, boolean hasFocus,
32: int row, int column) {
33: DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super
34: .getTableCellRendererComponent(table, value,
35: isSelected, hasFocus, row, column);
36:
37: renderer.setHorizontalAlignment(SwingConstants.CENTER);
38: renderer.setIcon(getIcon(table, value, isSelected, hasFocus,
39: row, column));
40: renderer.setText(null);
41: return renderer;
42: }
43: }
44:
45: /* $Log: IconCellRenderer.java,v $
46: /* Revision 1.3 2001/01/04 06:02:49 smulloni
47: /* added more javadoc documentation.
48: /*
49: /* Revision 1.2 2000/11/14 23:19:48 smullyan
50: /* interface changed to refer to Icon, not ImageIcon
51: /*
52: /* Revision 1.1 2000/11/10 22:40:10 smullyan
53: /* added icon to table for resource type; fixes to copy and move; disabling of
54: /* menu items that are inappropriate.
55: /* */
|