01: // This program is free software; you can redistribute it and/or modify
02: // it under the terms of the GNU General Public License as published by
03: // the Free Software Foundation; either version 2 of the License, or
04: // (at your option) any later version.
05: //
06: // This program is distributed in the hope that it will be useful,
07: // but WITHOUT ANY WARRANTY; without even the implied warranty of
08: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
09: // 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;
17:
18: import javax.swing.BorderFactory;
19: import javax.swing.JLabel;
20: import javax.swing.JTable;
21: import javax.swing.border.Border;
22: import javax.swing.table.TableCellRenderer;
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: * @author frd
30: *
31: * To change this generated comment edit the template variable "typecomment":
32: * Window>Preferences>Java>Templates.
33: * To enable and disable the creation of type comments go to
34: * Window>Preferences>Java>Code Generation.
35: */
36: public class NameRenderer extends JLabel implements TableCellRenderer {
37: Border unselectedBorder = null;
38: Border selectedBorder = null;
39: boolean isBordered = true;
40:
41: public NameRenderer() {
42: super ();
43: this .isBordered = true;
44: setOpaque(true); //MUST do this for background to show up.
45:
46: //setBorder( BorderFactory.createEmptyBorder(0,1,0,0) );
47: }
48:
49: public Component getTableCellRendererComponent(JTable table,
50: Object value, boolean isSelected, boolean hasFocus,
51: int row, int column) {
52: if (isBordered) {
53: if (isSelected) {
54: if (selectedBorder == null) {
55: selectedBorder = BorderFactory.createMatteBorder(2,
56: 5, 2, 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(
65: 2, 5, 2, 5, table.getBackground());
66: }
67:
68: setBackground(table.getBackground());
69: setBorder(unselectedBorder);
70: setForeground(table.getForeground());
71: }
72: }
73:
74: StringBuffer buf = new StringBuffer();
75:
76: AccountItem item = (AccountItem) value;
77:
78: buf.append(item.getName());
79:
80: if (MailConfig.getInstance().getAccountList()
81: .getDefaultAccountUid() == item.getUid()) {
82: buf.append(" ("
83: + MailResourceLoader.getString("dialog", "account",
84: "standard") + ")");
85: }
86:
87: setText(buf.toString());
88:
89: return this;
90: }
91: }
|