01: package net.sf.jftp.gui.base.dir;
02:
03: import java.awt.Color;
04: import java.awt.Component;
05: import java.awt.Insets;
06:
07: import javax.swing.JComponent;
08: import javax.swing.JLabel;
09: import javax.swing.JTable;
10: import javax.swing.border.CompoundBorder;
11: import javax.swing.border.EmptyBorder;
12: import javax.swing.table.DefaultTableCellRenderer;
13:
14: public class ColoredCellRenderer extends DefaultTableCellRenderer {
15:
16: public Component getTableCellRendererComponent(JTable table,
17: Object value, boolean isSelected, boolean hasFocus,
18: int row, int column) {
19: Component cell = super .getTableCellRendererComponent(table,
20: value, isSelected, hasFocus, row, column);
21:
22: //System.out.println("-> "+row+"/"+column + " ("+TableUtils.STATUS_COLUMN+"), "+value);
23: /*
24: if(column == TableUtils.STATUS_COLUMN)
25: {
26: if(value == null || ((String)value) == null) {
27: cell.setBackground(Color.RED);
28: return cell;
29: }
30:
31: String status = (String) value;
32:
33: if(status.equals("0")) cell.setBackground(Color.BLUE);
34: else if(status.equals("1")) cell.setBackground(Color.GREEN);
35: else if(status.equals("2")) cell.setBackground(Color.YELLOW);
36: else if(status.equals("3")) cell.setBackground(Color.YELLOW);
37: else cell.setBackground(Color.RED);
38: }
39: else {
40: */
41:
42: if (isSelected)
43: cell.setBackground(table.getSelectionBackground());
44: else
45: cell.setBackground(table.getBackground());
46:
47: ((JComponent) cell).setBorder(new CompoundBorder(
48: new EmptyBorder(new Insets(2, 4, 2, 4)),
49: ((JComponent) cell).getBorder()));
50: //}
51:
52: if (column == 2 || column == 3) {
53: setHorizontalAlignment(JLabel.RIGHT);
54: } else {
55: setHorizontalAlignment(JLabel.LEFT);
56: }
57:
58: if (column == 3) {
59: int x = ((DirEntry) value).getPermission();
60: if (x == DirEntry.R) {
61: cell.setBackground(Color.WHITE);
62: ((JLabel) cell).setText("r-");
63: } else if (x == DirEntry.W) {
64: cell.setBackground(new Color(230, 255, 230));
65: ((JLabel) cell).setText("rw");
66: } else if (x == DirEntry.DENIED) {
67: cell.setBackground(new Color(255, 230, 230));
68: ((JLabel) cell).setText("--");
69: }
70:
71: }
72:
73: return cell;
74:
75: }
76: }
|