KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > gnupg > Views > KeysTableCellRenderer


1 package SnowMailClient.gnupg.Views;
2
3 import snow.sortabletable.*;
4 import snow.lookandfeel.*;
5 import SnowMailClient.SpamFilter.*;
6 import SnowMailClient.gnupg.model.*;
7
8 import javax.swing.*;
9 import javax.swing.border.*;
10 import javax.swing.table.*;
11 import java.awt.*;
12 import java.beans.*;
13
14 /** DefaultTableCellRenderer seems not to like transparent bg ???
15  ### can be optmized for performance...
16 */

17 public final class KeysTableCellRenderer extends JLabel implements TableCellRenderer
18 {
19   Font normalFont, boldFont;
20
21
22   public KeysTableCellRenderer()
23   {
24     super();
25     setup();
26   } // Constructor
27

28   /**
29    * Notification from the <code>UIManager</code> that the look and feel
30    * [L&F] has changed.
31    * Replaces the current UI object with the latest version from the
32    * <code>UIManager</code>.
33    */

34   public void updateUI()
35   {
36      super.updateUI();
37      setup();
38   }
39
40   private void setup()
41   {
42      normalFont = UIManager.getFont("Table.font");
43      int fontSize = normalFont.getSize();
44      boldFont = //new Font(normalFont.getFontName(), Font.BOLD, fontSize);
45
normalFont.deriveFont(Font.BOLD);
46      Border emptyBorder = new EmptyBorder(fontSize/4, fontSize/2, fontSize/4, fontSize/2);
47      this.setBorder(emptyBorder);
48
49   }
50
51   public Component getTableCellRendererComponent(
52          JTable table, Object JavaDoc value, boolean isSelected, boolean hasFocus,
53          int row, int column)
54   {
55      String JavaDoc text = value.toString();
56      this.setText(text);
57      setOpaque(false);
58
59      SortableTableModel sortableTableModel = (SortableTableModel) table.getModel();
60      int ind = sortableTableModel.getIndexInUnsortedFromTablePos(row);
61      KeysTableModel ktm = (KeysTableModel) sortableTableModel.getBasicTableModel();
62
63      GnuPGKeyID key = ktm.getKeyAt(ind);
64      this.setFont(normalFont);
65
66      // selection
67
if(isSelected)
68      {
69         setBackground(UIManager.getColor("Tree.selectionBackground"));
70         setOpaque(true);
71      }
72
73      int modelCol = sortableTableModel.getColumnForViewIndex(column);
74
75      boolean showRed = false;
76      boolean showGreen = false;
77      if(modelCol==1)
78      {
79         String JavaDoc trust = key.getCalculatedTrust();
80         if(trust.equals("u") || trust.equals("f"))
81         {
82           showGreen = true;
83         }
84         else if(trust.equals("m") || trust.equals("e") || trust.equals("n"))
85         {
86           showRed = true;
87         }
88      }
89      else if (modelCol==6)
90      {
91         if(key.hasExpired()) showRed=true;
92      }
93
94
95
96      if(showGreen)
97      {
98         if(isSelected)
99         {
100
101           setBackground(ThemesManager.getInstance().getGreen().darker());
102         }
103         else
104         {
105           setBackground(ThemesManager.getInstance().getGreen());
106         }
107         setOpaque(true);
108      }
109      else if(showRed)
110      {
111         if(isSelected)
112         {
113           setBackground(ThemesManager.getInstance().getRed().darker());
114         }
115         else
116         {
117           setBackground(ThemesManager.getInstance().getRed());
118         }
119         setOpaque(true);
120      }
121
122      return this;
123   }
124
125
126
127 } // KeysTableCellRenderer
Popular Tags