001: /*
002: * Created on May 6, 2004
003: *
004: * This file is part of Thingamablog. ( http://thingamablog.sf.net )
005: *
006: * Copyright (c) 2004, Bob Tantlinger All Rights Reserved.
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
021: * USA.
022: *
023: */
024: package net.sf.thingamablog.gui.app;
025:
026: import java.awt.Component;
027:
028: import javax.swing.ImageIcon;
029: import javax.swing.JTree;
030: import javax.swing.tree.DefaultTreeCellRenderer;
031:
032: import net.atlanticbb.tantlinger.ui.UIUtils;
033: import net.sf.thingamablog.feed.Feed;
034:
035: /**
036: * @author Bob Tantlinger
037: *
038: *
039: *
040: */
041: public class FeedTreeCellRenderer extends DefaultTreeCellRenderer {
042: /**
043: *
044: */
045: private static final long serialVersionUID = 1L;
046: private ImageIcon feed, errFeed;
047:
048: //private Font normalFont, boldFont;
049:
050: public FeedTreeCellRenderer() {
051: super ();
052: //normalFont = new Font("Dialog", Font.PLAIN, 11);
053: //boldFont = normalFont.deriveFont(Font.BOLD);
054: feed = UIUtils.getIcon(UIUtils.X16, "blogpages.png");
055: errFeed = UIUtils.getIcon(UIUtils.X16, "err_feed.png");
056: }
057:
058: public Component getTreeCellRendererComponent(JTree tree,
059: Object value, boolean sel, boolean expanded, boolean leaf,
060: int row, boolean hasFocus) {
061: if (leaf && value instanceof Feed) {
062: Feed ch = (Feed) value;
063: if (ch.getTitle() == null || ch.getTitle().equals("")) {
064: String uri = ch.getURL();
065: value = new String(uri);
066:
067: } else
068: value = new String(ch.getTitle());
069:
070: try {
071: int n = ch.getUnreadItems().length;
072: if (n > 0) {
073: value = value.toString() + " (" + n + ")";
074: //setFont(boldFont);
075: } else {
076: //setFont(normalFont);
077: }
078: //System.out.println(value);
079: } catch (Exception ex) {
080: //ex.printStackTrace();
081: }
082:
083: if (ch.isLastUpdateFailed()) {
084: setToolTipText(ch.getLastUpdateFailedReason());
085: setLeafIcon(errFeed);
086: } else {
087: setToolTipText(ch.getTitle());
088: setLeafIcon(feed);
089: }
090: } else {
091: //setFont(normalFont);
092: }
093:
094: Component c = super.getTreeCellRendererComponent(tree, value,
095: sel, expanded, leaf, row, hasFocus);
096:
097: return c;
098:
099: }
100: }
|