KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > viewer > tableviewer > AttributeTypeCellRenderer


1 package com.ca.directory.jxplorer.viewer.tableviewer;
2
3 import java.awt.Component JavaDoc;
4 import javax.swing.JTable JavaDoc;
5 import javax.swing.table.*;
6 import java.awt.*;
7     /*
8      * A minimal extension of DefaultTableCellRenderer allowing
9      * us to set some rows to bold font and others to normal font.
10      *
11      */

12                                                
13 public class AttributeTypeCellRenderer extends DefaultTableCellRenderer
14
15 {
16     Font normalFont;
17     Font boldFont;
18     Font boldBlueFont;
19     /**
20      * constructor calls the super class constructor, and
21      * initialises the fonts.
22      */

23     public AttributeTypeCellRenderer()
24     {
25         super();
26         normalFont = this.getFont();
27         boldFont = normalFont.deriveFont(java.awt.Font.BOLD);
28         boldBlueFont = normalFont.deriveFont(java.awt.Font.BOLD);
29     }
30
31     /**
32      * intercepts the super classes returned component, and sets the
33      * font on it before returning.
34      */

35     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
36         boolean isSelected, boolean hasFocus, int row, int column)
37     {
38         if (value instanceof AttributeType)
39         {
40             AttributeType attType = (AttributeType)value;
41             
42             Component JavaDoc c = super.getTableCellRendererComponent(table, attType.getValue(), isSelected, hasFocus, row, column);
43             
44             if (attType.isMandatory())
45             {
46                 c.setFont(boldFont);
47             }
48             else
49             {
50                 c.setFont(normalFont);
51             }
52             return c;
53             
54         }
55         else
56             return super.getTableCellRendererComponent(table, new String JavaDoc("error"), isSelected, hasFocus, row, column);
57     }
58 }
Popular Tags