KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > accountlist > StringAccountRenderer


1 // This program is free software; you can redistribute it and/or modify
2
// it under the terms of the GNU General Public License as published by
3
// the Free Software Foundation; either version 2 of the License, or
4
// (at your option) any later version.
5
//
6
// This program is distributed in the hope that it will be useful,
7
// but WITHOUT ANY WARRANTY; without even the implied warranty of
8
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
// GNU Library General Public License for more details.
10
//
11
// You should have received a copy of the GNU General Public License
12
// along with this program; if not, write to the Free Software
13
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
package org.columba.mail.gui.config.accountlist;
15
16 import java.awt.Component JavaDoc;
17 import java.awt.Font JavaDoc;
18
19 import javax.swing.BorderFactory JavaDoc;
20 import javax.swing.ImageIcon JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JTable JavaDoc;
23 import javax.swing.UIManager JavaDoc;
24 import javax.swing.border.Border JavaDoc;
25 import javax.swing.table.TableCellRenderer JavaDoc;
26
27 import org.columba.core.resourceloader.IconKeys;
28 import org.columba.core.resourceloader.ImageLoader;
29
30 public class StringAccountRenderer extends JLabel JavaDoc implements TableCellRenderer JavaDoc {
31
32     private static final java.util.logging.Logger JavaDoc LOG = java.util.logging.Logger
33             .getLogger("org.columba.mail.gui.config.accountlist"); //$NON-NLS-1$
34

35     private Border JavaDoc unselectedBorder = null;
36
37     private Border JavaDoc selectedBorder = null;
38
39     private boolean isBordered = true;
40
41     private Font JavaDoc boldFont;
42
43     private ImageIcon JavaDoc image1 = ImageLoader.getSmallIcon(IconKeys.COMPUTER);
44
45     private ImageIcon JavaDoc image2 = ImageLoader
46             .getSmallIcon(IconKeys.SERVER);
47
48     private boolean b;
49
50     public StringAccountRenderer(boolean b) {
51         super();
52         this.b = b;
53
54         this.isBordered = true;
55
56         setOpaque(true); // MUST do this for background to show up.
57

58         boldFont = UIManager.getFont("Label.font");
59         boldFont = boldFont.deriveFont(Font.BOLD);
60
61     }
62
63     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
64             boolean isSelected, boolean hasFocus, int row, int column) {
65         // super.getTableCellRendererComponent( table, value, isSelected,
66
// hasFocus, row, column );
67
if (isBordered) {
68             if (isSelected) {
69                 if (selectedBorder == null) {
70                     selectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
71                             5, table.getSelectionBackground());
72                 }
73
74                 // setBorder(selectedBorder);
75
setBackground(table.getSelectionBackground());
76                 setForeground(table.getSelectionForeground());
77             } else {
78                 if (unselectedBorder == null) {
79                     unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
80                             5, table.getBackground());
81                 }
82
83                 setBackground(table.getBackground());
84
85                 // setBorder(unselectedBorder);
86
setForeground(table.getForeground());
87             }
88         }
89
90         String JavaDoc str = null;
91
92         try {
93             str = (String JavaDoc) value;
94         } catch (ClassCastException JavaDoc ex) {
95             LOG.info(" filter renderer: " + ex.getMessage()); //$NON-NLS-1$
96
str = "";
97         }
98
99         if (b == true) {
100             if (str.equalsIgnoreCase("POP3")) {
101                 setIcon(image1);
102             } else if (str.equalsIgnoreCase("IMAP4")) {
103                 setIcon(image2);
104             }
105         }
106
107         setText(str);
108
109         return this;
110     }
111 }
112
Popular Tags