KickJava   Java API By Example, From Geeks To Geeks.

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


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
18 import javax.swing.BorderFactory JavaDoc;
19 import javax.swing.JLabel JavaDoc;
20 import javax.swing.JTable JavaDoc;
21 import javax.swing.border.Border JavaDoc;
22 import javax.swing.table.TableCellRenderer JavaDoc;
23
24 import org.columba.mail.config.AccountItem;
25 import org.columba.mail.config.MailConfig;
26 import org.columba.mail.util.MailResourceLoader;
27
28
29 /**
30  * @author frd
31  *
32  * To change this generated comment edit the template variable "typecomment":
33  * Window>Preferences>Java>Templates.
34  * To enable and disable the creation of type comments go to
35  * Window>Preferences>Java>Code Generation.
36  */

37 public class NameRenderer extends JLabel JavaDoc implements TableCellRenderer JavaDoc {
38     Border JavaDoc unselectedBorder = null;
39     Border JavaDoc selectedBorder = null;
40     boolean isBordered = true;
41
42     public NameRenderer() {
43         super();
44         this.isBordered = true;
45         setOpaque(true); //MUST do this for background to show up.
46

47         //setBorder( BorderFactory.createEmptyBorder(0,1,0,0) );
48
}
49
50     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
51         boolean isSelected, boolean hasFocus, int row, int column) {
52         if (isBordered) {
53             if (isSelected) {
54                 if (selectedBorder == null) {
55                     selectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
56                             5, table.getSelectionBackground());
57                 }
58
59                 setBorder(selectedBorder);
60                 setBackground(table.getSelectionBackground());
61                 setForeground(table.getSelectionForeground());
62             } else {
63                 if (unselectedBorder == null) {
64                     unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
65                             5, table.getBackground());
66                 }
67
68                 setBackground(table.getBackground());
69                 setBorder(unselectedBorder);
70                 setForeground(table.getForeground());
71             }
72         }
73
74         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
75
76         AccountItem item = (AccountItem) value;
77
78         buf.append(item.getName());
79
80         if (MailConfig.getInstance().getAccountList().getDefaultAccountUid() == item.getUid()) {
81             buf.append(" (" +
82                 MailResourceLoader.getString("dialog", "account", "standard") +
83                 ")");
84         }
85
86         setText(buf.toString());
87
88         return this;
89     }
90 }
91
Popular Tags