KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > dir > ColoredCellRenderer


1 package net.sf.jftp.gui.base.dir;
2
3 import java.awt.Color JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Insets JavaDoc;
6
7 import javax.swing.JComponent JavaDoc;
8 import javax.swing.JLabel JavaDoc;
9 import javax.swing.JTable JavaDoc;
10 import javax.swing.border.CompoundBorder JavaDoc;
11 import javax.swing.border.EmptyBorder JavaDoc;
12 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
13
14 public class ColoredCellRenderer extends DefaultTableCellRenderer JavaDoc {
15     
16
17
18     public Component JavaDoc getTableCellRendererComponent
19     (JTable JavaDoc table, Object JavaDoc value, boolean isSelected,boolean hasFocus, int row, int column)
20     {
21         Component JavaDoc cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
22
23         //System.out.println("-> "+row+"/"+column + " ("+TableUtils.STATUS_COLUMN+"), "+value);
24
/*
25         if(column == TableUtils.STATUS_COLUMN)
26         {
27             if(value == null || ((String)value) == null) {
28                 cell.setBackground(Color.RED);
29                 return cell;
30             }
31
32             String status = (String) value;
33
34             if(status.equals("0")) cell.setBackground(Color.BLUE);
35             else if(status.equals("1")) cell.setBackground(Color.GREEN);
36             else if(status.equals("2")) cell.setBackground(Color.YELLOW);
37             else if(status.equals("3")) cell.setBackground(Color.YELLOW);
38             else cell.setBackground(Color.RED);
39         }
40         else {
41          */

42          
43         if(isSelected) cell.setBackground(table.getSelectionBackground());
44         else cell.setBackground(table.getBackground());
45         
46         ((JComponent JavaDoc)cell).setBorder(
47                 new CompoundBorder JavaDoc(
48                      new EmptyBorder JavaDoc(new Insets JavaDoc(2,4,2,4)),
49                      ((JComponent JavaDoc)cell).getBorder()));
50         //}
51

52         if(column == 2 || column == 3) {
53             setHorizontalAlignment(JLabel.RIGHT);
54         }
55         else {
56             setHorizontalAlignment(JLabel.LEFT);
57         }
58         
59         if(column == 3) {
60           int x = ((DirEntry)value).getPermission();
61           if(x == DirEntry.R) {
62               cell.setBackground(Color.WHITE);
63               ((JLabel JavaDoc)cell).setText("r-");
64           }
65           else if(x == DirEntry.W) {
66               cell.setBackground(new Color JavaDoc(230,255,230));
67               ((JLabel JavaDoc)cell).setText("rw");
68           }
69           else if(x == DirEntry.DENIED) {
70               cell.setBackground(new Color JavaDoc(255,230,230));
71               ((JLabel JavaDoc)cell).setText("--");
72           }
73
74         }
75
76
77         return cell;
78         
79     }
80 }
81
82
Popular Tags