001: // This program is free software; you can redistribute it and/or modify
002: // it under the terms of the GNU General Public License as published by
003: // the Free Software Foundation; either version 2 of the License, or
004: // (at your option) any later version.
005: //
006: // This program is distributed in the hope that it will be useful,
007: // but WITHOUT ANY WARRANTY; without even the implied warranty of
008: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
009: // GNU Library General Public License for more details.
010: //
011: // You should have received a copy of the GNU General Public License
012: // along with this program; if not, write to the Free Software
013: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
014: package org.columba.mail.gui.config.accountlist;
015:
016: import java.awt.Component;
017: import java.awt.Font;
018:
019: import javax.swing.BorderFactory;
020: import javax.swing.ImageIcon;
021: import javax.swing.JLabel;
022: import javax.swing.JTable;
023: import javax.swing.UIManager;
024: import javax.swing.border.Border;
025: import javax.swing.table.TableCellRenderer;
026:
027: import org.columba.core.resourceloader.IconKeys;
028: import org.columba.core.resourceloader.ImageLoader;
029:
030: public class StringAccountRenderer extends JLabel implements
031: TableCellRenderer {
032:
033: private static final java.util.logging.Logger LOG = java.util.logging.Logger
034: .getLogger("org.columba.mail.gui.config.accountlist"); //$NON-NLS-1$
035:
036: private Border unselectedBorder = null;
037:
038: private Border selectedBorder = null;
039:
040: private boolean isBordered = true;
041:
042: private Font boldFont;
043:
044: private ImageIcon image1 = ImageLoader
045: .getSmallIcon(IconKeys.COMPUTER);
046:
047: private ImageIcon image2 = ImageLoader
048: .getSmallIcon(IconKeys.SERVER);
049:
050: private boolean b;
051:
052: public StringAccountRenderer(boolean b) {
053: super ();
054: this .b = b;
055:
056: this .isBordered = true;
057:
058: setOpaque(true); // MUST do this for background to show up.
059:
060: boldFont = UIManager.getFont("Label.font");
061: boldFont = boldFont.deriveFont(Font.BOLD);
062:
063: }
064:
065: public Component getTableCellRendererComponent(JTable table,
066: Object value, boolean isSelected, boolean hasFocus,
067: int row, int column) {
068: // super.getTableCellRendererComponent( table, value, isSelected,
069: // hasFocus, row, column );
070: if (isBordered) {
071: if (isSelected) {
072: if (selectedBorder == null) {
073: selectedBorder = BorderFactory.createMatteBorder(2,
074: 5, 2, 5, table.getSelectionBackground());
075: }
076:
077: // setBorder(selectedBorder);
078: setBackground(table.getSelectionBackground());
079: setForeground(table.getSelectionForeground());
080: } else {
081: if (unselectedBorder == null) {
082: unselectedBorder = BorderFactory.createMatteBorder(
083: 2, 5, 2, 5, table.getBackground());
084: }
085:
086: setBackground(table.getBackground());
087:
088: // setBorder(unselectedBorder);
089: setForeground(table.getForeground());
090: }
091: }
092:
093: String str = null;
094:
095: try {
096: str = (String) value;
097: } catch (ClassCastException ex) {
098: LOG.info(" filter renderer: " + ex.getMessage()); //$NON-NLS-1$
099: str = "";
100: }
101:
102: if (b == true) {
103: if (str.equalsIgnoreCase("POP3")) {
104: setIcon(image1);
105: } else if (str.equalsIgnoreCase("IMAP4")) {
106: setIcon(image2);
107: }
108: }
109:
110: setText(str);
111:
112: return this;
113: }
114: }
|