JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / gui / BlogReader.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.bin.Cache;
24 import jalview.util.MessageManager;
25
26 import java.awt.BorderLayout;
27 import java.awt.Component;
28 import java.awt.Dialog.ModalExclusionType;
29 import java.awt.Dimension;
30 import java.awt.Font;
31 import java.awt.Rectangle;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.KeyEvent;
35 import java.awt.event.MouseEvent;
36 import java.awt.event.WindowAdapter;
37 import java.awt.event.WindowEvent;
38 import java.beans.PropertyChangeListener;
39 import java.text.DateFormat;
40 import java.text.SimpleDateFormat;
41 import java.util.ArrayList;
42 import java.util.Calendar;
43 import java.util.Collections;
44 import java.util.Iterator;
45 import java.util.List;
46 import java.util.Map;
47
48 import javax.swing.AbstractAction;
49 import javax.swing.AbstractButton;
50 import javax.swing.Action;
51 import javax.swing.DefaultListCellRenderer;
52 import javax.swing.DefaultListModel;
53 import javax.swing.Icon;
54 import javax.swing.ImageIcon;
55 import javax.swing.JButton;
56 import javax.swing.JFrame;
57 import javax.swing.JLabel;
58 import javax.swing.JList;
59 import javax.swing.JMenuItem;
60 import javax.swing.JPanel;
61 import javax.swing.JPopupMenu;
62 import javax.swing.JScrollPane;
63 import javax.swing.JSplitPane;
64 import javax.swing.JToolBar;
65 import javax.swing.ListSelectionModel;
66 import javax.swing.SwingUtilities;
67 import javax.swing.event.HyperlinkEvent;
68 import javax.swing.event.HyperlinkListener;
69 import javax.swing.event.ListSelectionEvent;
70 import javax.swing.event.ListSelectionListener;
71
72 import org.robsite.jswingreader.action.MarkChannelAsRead;
73 import org.robsite.jswingreader.action.MarkChannelAsUnread;
74 import org.robsite.jswingreader.action.MarkItemAsRead;
75 import org.robsite.jswingreader.action.MarkItemAsUnread;
76 import org.robsite.jswingreader.action.UpdatableAction;
77 import org.robsite.jswingreader.model.Channel;
78 import org.robsite.jswingreader.model.ChannelListModel;
79 import org.robsite.jswingreader.model.Item;
80 import org.robsite.jswingreader.model.SimpleRSSParser;
81 import org.robsite.jswingreader.ui.BlogContentPane;
82 import org.robsite.jswingreader.ui.ItemReadTimer;
83 import org.robsite.jswingreader.ui.Main;
84 import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter;
85
86 /**
87  * Blog reading window, adapted from JSwingReader's
88  * org.robsite.jswingreader.ui.MainWindow class
89  */
90
91 public class BlogReader extends JPanel
92 {
93   private JButton buttonRefresh = new JButton();
94
95   private JToolBar toolBar = new JToolBar();
96
97   private JLabel statusBar = new JLabel();
98
99   private JPanel panelMain = new JPanel();
100
101   private BorderLayout layoutMain = new BorderLayout();
102
103   private BorderLayout borderLayout1 = new BorderLayout();
104
105   private JPanel topPanel = new JPanel();
106
107   private JPanel bottomPanel = new JPanel();
108
109   private JSplitPane topBottomSplitPane = new JSplitPane();
110
111   private JList listItems = new JList(new DefaultListModel());
112
113   // SWITCH IN JALVIEW HTML VIEWER PANE HERE
114   private BlogContentPane textDescription = new BlogContentPane();
115
116   // ADD IN JALVIEW BANNER FOR PRETTINESS
117   private BorderLayout borderLayout4 = new BorderLayout();
118
119   private BorderLayout borderLayout5 = new BorderLayout();
120
121   private ChannelListModel _channelModel = null;
122
123   private JList listChannels = new JList();
124
125   private Action exitAction = new Action()
126   {
127
128     @Override
129     public void actionPerformed(ActionEvent arg0)
130     {
131       if (xf != null)
132       {
133         xf.dispose();
134       }
135       xf = null;
136       jd = null;
137       if (parent != null)
138       {
139         parent.showNews(false);
140       }
141
142     }
143
144     @Override
145     public void setEnabled(boolean arg0)
146     {
147
148     }
149
150     @Override
151     public void removePropertyChangeListener(PropertyChangeListener arg0)
152     {
153       // TODO Auto-generated method stub
154
155     }
156
157     @Override
158     public void putValue(String arg0, Object arg1)
159     {
160       // TODO Auto-generated method stub
161
162     }
163
164     @Override
165     public boolean isEnabled()
166     {
167       // TODO Auto-generated method stub
168       return true;
169     }
170
171     @Override
172     public Object getValue(String arg0)
173     {
174       // TODO Auto-generated method stub
175       return null;
176     }
177
178     @Override
179     public void addPropertyChangeListener(PropertyChangeListener arg0)
180     {
181       // TODO Auto-generated method stub
182
183     }
184   };
185
186   private JFrame xf = null;
187
188   private JalviewDialog jd = null;
189
190   private JalviewDialog createDialog()
191   {
192
193     return jd = new JalviewDialog()
194     {
195
196       @Override
197       protected void raiseClosed()
198       {
199         if (parent != null)
200         {
201           Cache.log.debug("News window closed.");
202           jd = null;
203           parent.showNews(false);
204         }
205       }
206
207       @Override
208       protected void okPressed()
209       {
210         // TODO Auto-generated method stub
211
212       }
213
214       @Override
215       protected void cancelPressed()
216       {
217         // TODO Auto-generated method stub
218
219       }
220     };
221   };
222
223   private JLabel lblChannels = new JLabel();
224
225   private List _updatableActions = new ArrayList();
226
227   private ItemReadTimer _itemTimer = null;
228
229   private JPopupMenu _popupItems = null;
230
231   private JPopupMenu _popupChannels = null;
232
233   private String lastm = "";
234
235   private boolean newsnew = false;
236
237   private Desktop parent = null;
238
239   BlogReader()
240   {
241     this(null);
242   }
243
244   // should we ignore fake gui events
245   private boolean updating = false;
246
247   public BlogReader(Desktop desktop)
248   {
249     Cache.log.debug("Constructing news reader.");
250
251     parent = desktop;
252     _channelModel = new ChannelListModel();
253     // Construct our jalview news channel
254     Channel chan = new Channel();
255     chan.setURL(jalview.bin.Cache.getDefault(
256             "JALVIEW_NEWS_RSS",
257             jalview.bin.Cache.getDefault("www.jalview.org",
258                     "http://www.jalview.org") + "/feeds/desktop/rss"));
259     loadLastM();
260     _channelModel.addChannel(chan);
261     updating = true;
262     try
263     {
264       jbInit();
265       postInit();
266     } catch (Exception e)
267     {
268       e.printStackTrace();
269     }
270
271     initItems(chan);
272     updating = false;
273     boolean setvisible = checkForNew(chan, true);
274
275     if (setvisible)
276     {
277
278       Cache.log.debug("Will show jalview news automatically");
279       showNews();
280     }
281     Cache.log.debug("Completed construction of reader.");
282
283   }
284
285   /**
286    * check if the news panel's container is visible
287    */
288   public boolean isVisible()
289   {
290     if (parent == null)
291     {
292       return xf != null && xf.isVisible();
293     }
294     return jd != null && jd.isVisible();
295   }
296
297   /**
298    * display the container for the news panel
299    */
300   public void showNews()
301   {
302     final BlogReader me = this;
303     SwingUtilities.invokeLater(new Runnable()
304     {
305       @Override
306       public void run()
307       {
308         Rectangle bounds = new Rectangle(5, 5, 550, 350);
309         if (parent == null)
310         {
311           xf = new JFrame();
312           xf.setContentPane(me);
313           xf.addWindowListener(new WindowAdapter()
314           {
315             public void windowClosing(WindowEvent e)
316             {
317               ActionEvent actionEvent = new ActionEvent(this,
318                       ActionEvent.ACTION_FIRST, (String) exitAction
319                               .getValue(Action.NAME));
320               exitAction.actionPerformed(actionEvent);
321             }
322
323             public void windowOpened(WindowEvent e)
324             {
325             }
326           });
327           me.setSize(new Dimension(550, 350));
328           xf.setVisible(true);
329         }
330         else
331         {
332           createDialog();
333           bounds = new Rectangle(5, 5, 550, 350);
334           jd.initDialogFrame(me, false, false,
335                   MessageManager.getString("label.news_from_jalview"),
336                   bounds.width, bounds.height);
337           jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
338           Cache.log.debug("Displaying news.");
339           jd.waitForInput();
340         }
341       }
342     });
343   }
344
345   /**
346    * update hasnew flag and mark all new messages as unread.
347    */
348   private boolean checkForNew(Channel chan, boolean updateItems)
349   {
350
351     if (!updating || updateItems)
352     {
353       newsnew = false;
354     }
355     java.util.Date earliest = null;
356     try
357     {
358       earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan
359               .getHTTPLastModified());
360     } catch (Exception x)
361     {
362     }
363     ;
364     if (chan != null && chan.getItems() != null)
365     {
366       Cache.log.debug("Scanning news items: newsnew=" + newsnew
367               + " and lastDate is " + lastDate);
368       for (Item i : (List<Item>) chan.getItems())
369       {
370         boolean isread = lastDate == null ? false
371                 : (i.getPublishDate() != null && !lastDate.before(i
372                         .getPublishDate()));
373
374         if (!updating || updateItems)
375         {
376           newsnew |= !isread;
377         }
378         if (updateItems)
379         {
380           i.setRead(isread);
381         }
382         if (i.getPublishDate() != null && !i.isRead())
383         {
384           if (earliest == null || earliest.after(i.getPublishDate()))
385           {
386             earliest = i.getPublishDate();
387           }
388         }
389       }
390     }
391     if (!updateItems && !updating && lastDate == null)
392     {
393       lastDate = earliest;
394     }
395     return newsnew;
396   }
397
398   java.util.Date lastDate = null;
399
400   private void loadLastM()
401   {
402     lastDate = Cache.getDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED");
403   }
404
405   private void saveLastM(Item item)
406   {
407     if (item != null)
408     {
409       if (item.getPublishDate() != null)
410       {
411         if (lastDate == null || item.getPublishDate().after(lastDate))
412         {
413           lastDate = item.getPublishDate();
414         }
415       }
416
417       if (_channelModel.getElementAt(0) != null)
418       {
419         checkForNew((Channel) _channelModel.getElementAt(0), false);
420       }
421       if (lastDate != null)
422       {
423         jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
424                 lastDate);
425         jalview.bin.Cache.log.debug("Saved last read date as "
426                 + jalview.bin.Cache.date_format.format(lastDate));
427
428       }
429     }
430   }
431
432   private void jbInit() throws Exception
433   {
434     setLayout(layoutMain);
435     panelMain.setLayout(borderLayout1);
436     topPanel.setLayout(borderLayout5);
437     bottomPanel.setLayout(borderLayout4);
438     topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
439     topBottomSplitPane.setDividerLocation(100);
440     topBottomSplitPane.setTopComponent(topPanel);
441     topBottomSplitPane.setBottomComponent(bottomPanel);
442     JScrollPane spTextDescription = new JScrollPane(textDescription);
443     textDescription.setText("");
444     statusBar.setText(new StringBuffer("[")
445             .append(MessageManager.getString("label.status")).append("]")
446             .toString());
447     buttonRefresh.addActionListener(new ActionListener()
448     {
449
450       @Override
451       public void actionPerformed(ActionEvent e)
452       {
453         refreshNews();
454       }
455     });
456     add(statusBar, BorderLayout.SOUTH);
457     toolBar.add(buttonRefresh);
458     toolBar.addSeparator();
459     JLabel about = new JLabel(
460             "brought to you by JSwingReader (jswingreader.sourceforge.net)");
461     toolBar.add(about);
462     toolBar.setFloatable(false);
463     add(toolBar, BorderLayout.NORTH);
464     panelMain.add(topBottomSplitPane, BorderLayout.CENTER);
465     add(panelMain, BorderLayout.CENTER);
466     JScrollPane spListItems = new JScrollPane(listItems);
467     listItems
468             .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
469     topPanel.add(spListItems, BorderLayout.CENTER);
470     bottomPanel.add(spTextDescription, BorderLayout.CENTER);
471     listChannels.setModel(_channelModel);
472
473     listItems.addMouseListener(new java.awt.event.MouseAdapter()
474     {
475       public void mouseClicked(MouseEvent e)
476       {
477         listItems_mouseClicked(e);
478       }
479     });
480     _popupItems = _buildItemsPopupMenu();
481     _popupChannels = _buildChannelsPopupMenu();
482     ContextMenuMouseAdapter popupAdapter = new ContextMenuMouseAdapter(
483             _popupItems);
484     ContextMenuMouseAdapter popupChannelsAdapter = new ContextMenuMouseAdapter(
485             _popupChannels);
486     listItems.addMouseListener(popupAdapter);
487     listItems.setCellRenderer(new ItemsRenderer());
488     lblChannels.setText(MessageManager.getString("label.channels"));
489   }
490
491   private void postInit()
492   {
493     // clear the default hyperlink listener and replace with our own.
494     for (HyperlinkListener hll : textDescription.getHyperlinkListeners())
495     {
496       textDescription.removeHyperlinkListener(hll);
497     }
498     textDescription.addHyperlinkListener(new HyperlinkListener()
499     {
500       public void hyperlinkUpdate(HyperlinkEvent e)
501       {
502         if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
503         {
504           Desktop.showUrl(e.getURL().toExternalForm());
505         }
506       }
507     });
508
509     listItems.addListSelectionListener(new ListSelectionListener()
510     {
511       public void valueChanged(ListSelectionEvent e)
512       {
513         if (e.getValueIsAdjusting() == false)
514         {
515           _itemsValueChanged(listItems);
516         }
517       }
518     });
519     listChannels.setSelectedIndex(1);
520     _updateAllActions();
521     _updateToolbarButtons();
522
523     _itemTimer = new ItemReadTimer(listChannels, listItems);
524     _itemsValueChanged(listItems);
525   }
526
527   public class LaunchJvBrowserOnItem extends AbstractAction implements
528           UpdatableAction
529   {
530     JList _listItems = null;
531
532     public LaunchJvBrowserOnItem(JList listItems)
533     {
534       super("Open in Browser");
535       this.putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
536       this.putValue(Action.LONG_DESCRIPTION, "Open in Browser");
537       _listItems = listItems;
538     }
539
540     public void actionPerformed(ActionEvent e)
541     {
542       Object o = _listItems.getSelectedValue();
543       if (o instanceof Item)
544       {
545         Item item = (Item) o;
546         item.setRead(true);
547         _listItems.repaint();
548
549         Desktop.showUrl(item.getLink());
550       }
551     }
552
553     public void update(Object o)
554     {
555       setEnabled(true);
556       if (_listItems == null || _listItems.getModel().getSize() == 0)
557       {
558         setEnabled(false);
559       }
560       else if (_listItems.getSelectedIndex() == -1)
561       {
562         setEnabled(false);
563       }
564     }
565
566   }
567
568   private JPopupMenu _buildItemsPopupMenu()
569   {
570     JPopupMenu popup = new JPopupMenu();
571     popup.add(new JMenuItem(new LaunchJvBrowserOnItem(listItems)));
572     popup.addSeparator();
573     popup.add(new JMenuItem(new MarkItemAsRead(listItems)));
574     popup.add(new JMenuItem(new MarkItemAsUnread(listItems)));
575     return popup;
576   }
577
578   private JPopupMenu _buildChannelsPopupMenu()
579   {
580     JPopupMenu popup = new JPopupMenu();
581     popup.add(new JMenuItem(new MarkChannelAsRead(listChannels, listItems)));
582     popup.add(new JMenuItem(
583             new MarkChannelAsUnread(listChannels, listItems)));
584     return popup;
585   }
586
587   private void initItems(Channel channel)
588   {
589     if (channel == null)
590     {
591       channel = new Channel();
592     }
593     if (!channel.isOpen() && channel.getURL() != null)
594     {
595       try
596       {
597         SimpleRSSParser.parse(channel);
598       } catch (Exception ex)
599       {
600         ex.printStackTrace();
601       }
602     }
603     DefaultListModel itemsModel = (DefaultListModel) listItems.getModel();
604     itemsModel.clear();
605     Iterator iter = (channel.getItems() != null) ? channel.getItems()
606             .iterator() : Collections.EMPTY_LIST.iterator();
607     while (iter.hasNext())
608     {
609       itemsModel.addElement(iter.next());
610     }
611     if (itemsModel.getSize() > 0)
612     {
613       listItems.setSelectedIndex(0);
614       _itemsValueChanged(listItems);
615     }
616     setStatusBarText(channel.getURL());
617     _updateAllActions();
618   }
619
620   private void _itemsValueChanged(JList itemList)
621   {
622     Item item = (Item) itemList.getSelectedValue();
623     if (item == null)
624     {
625       if (itemList.getModel().getSize() > 0)
626       {
627         item = (Item) itemList.getModel().getElementAt(0);
628       }
629       if (item == null)
630       {
631         item = new Item();
632       }
633       else
634       {
635         itemList.setSelectedIndex(0);
636       }
637     }
638
639     if (_itemTimer != null)
640     {
641       // prefer a shorter delay than 5s
642       _itemTimer.setDelay(300);
643       _itemTimer.start();
644       _itemTimer.setLastItem(item);
645       final Item lastitem = item;
646       _itemTimer.addActionListener(new ActionListener()
647       {
648
649         @Override
650         public void actionPerformed(ActionEvent e)
651         {
652           saveLastM(lastitem);
653         }
654       });
655     }
656
657     setStatusBarText(item.getLink());
658     textDescription.setBlogText(item);
659     _updateAllActions();
660   }
661
662   public void setStatusBarText(String text)
663   {
664     statusBar.setText(text);
665   }
666
667   private void _updateAllActions()
668   {
669     Iterator iter = _updatableActions.iterator();
670     while (iter.hasNext())
671     {
672       UpdatableAction action = (UpdatableAction) iter.next();
673       action.update(this);
674     }
675   }
676
677   private void _updateToolbarButtons()
678   {
679     Map general = (Map) Main.getPreferences().get("general");
680     if (general == null)
681     {
682       return;
683     }
684
685     Component[] components = toolBar.getComponents();
686     for (int i = 0; i < components.length; i++)
687     {
688       Component component = components[i];
689       if (component instanceof JButton)
690       {
691         JButton button = (JButton) component;
692         if (Boolean.toString(false).equals(general.get("useToolBarText")))
693         {
694           // Remove the text if preferences state no toolbar text
695           button.setText("");
696         }
697         if (Boolean.toString(true).equals(general.get("radioTextBelow")))
698         {
699           button.setVerticalTextPosition(AbstractButton.BOTTOM);
700           button.setHorizontalTextPosition(AbstractButton.CENTER);
701         }
702         else if (Boolean.toString(true).equals(
703                 general.get("radioTextRight")))
704         {
705           button.setVerticalTextPosition(AbstractButton.CENTER);
706           button.setHorizontalTextPosition(AbstractButton.RIGHT);
707         }
708       }
709     }
710   }
711
712   private void listItems_mouseClicked(MouseEvent e)
713   {
714     if (e.getClickCount() == 2 && e.getModifiersEx() == MouseEvent.NOBUTTON)
715     {
716       Item item = (Item) listItems.getSelectedValue();
717       item.setRead(true);
718       saveLastM(item);
719       if (_itemTimer != null)
720       {
721         _itemTimer.stop();
722       }
723
724       Action action = new LaunchJvBrowserOnItem(listItems);
725       ActionEvent event = new ActionEvent(this,
726               ActionEvent.ACTION_PERFORMED, "LaunchBrowserOnItem");
727       action.actionPerformed(event);
728     }
729   }
730
731   /**
732    * force the news panel to refresh
733    */
734   public void refreshNews()
735   {
736     try
737     {
738       initItems((Channel) _channelModel.getElementAt(0));
739
740     } catch (Exception x)
741     {
742     }
743   }
744
745   public static void main(String args[])
746   {
747     // this tests the detection of new news based on the last read date stored
748     // in jalview properties
749     jalview.bin.Cache.loadProperties(null);
750     jalview.bin.Cache.initLogger();
751     // test will advance read date each time
752     Calendar today = Calendar.getInstance(), lastread = Calendar
753             .getInstance();
754     lastread.set(1983, 01, 01);
755     while (lastread.before(today))
756     {
757       Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
758               lastread.getTime());
759       BlogReader me = new BlogReader();
760       System.out.println("Set last date to "
761               + jalview.bin.Cache.date_format.format(lastread.getTime()));
762       if (me.isNewsNew())
763       {
764         Cache.log.debug("There is news to read.");
765       }
766       else
767       {
768         Cache.log.debug("There is no new news.");
769         me.xf.setTitle("Testing : Last read is " + me.lastDate);
770         me.showNews();
771         me.xf.toFront();
772       }
773       Cache.log.debug("Waiting for closure.");
774       do
775       {
776         try
777         {
778           Thread.sleep(300);
779         } catch (InterruptedException x)
780         {
781         }
782         ;
783       } while (me.isVisible());
784
785       if (me.isNewsNew())
786       {
787         Cache.log.debug("Still new news after reader displayed.");
788       }
789       if (lastread.getTime().before(me.lastDate))
790       {
791         Cache.log.debug("The news was read.");
792         lastread.setTime(me.lastDate);
793       }
794       else
795       {
796         lastread.add(Calendar.MONTH, 1);
797       }
798
799     }
800   }
801
802   boolean isNewsNew()
803   {
804     return newsnew;
805   }
806 }
807
808 class ChannelsRenderer extends DefaultListCellRenderer
809 {
810   private final static Icon _icon = new ImageIcon(
811           Main.class.getResource("image/ComposeMail16.gif"));
812
813   public Component getListCellRendererComponent(JList list, Object value,
814           int index, boolean isSelected, boolean cellHasFocus)
815   {
816     JLabel component = (JLabel) super.getListCellRendererComponent(list,
817             value, index, isSelected, cellHasFocus);
818     component.setIcon(ChannelsRenderer._icon);
819     if (value instanceof Channel)
820     {
821       Channel channel = (Channel) value;
822       component
823               .setText(MessageManager.formatMessage(
824                       "label.channel_title_item_count",
825                       new String[] {
826                           channel.getTitle(),
827                           Integer.valueOf(channel.getUnreadItemCount())
828                                   .toString() }));
829       component.setToolTipText(channel.getURL());
830     }
831     return component;
832   }
833 }
834
835 class ItemsRenderer extends DefaultListCellRenderer
836 {
837   private final static Icon _icon = new ImageIcon(
838           Main.class.getResource("image/ComposeMail16.gif"));
839
840   public Component getListCellRendererComponent(JList list, Object value,
841           int index, boolean isSelected, boolean cellHasFocus)
842   {
843     JLabel component = (JLabel) super.getListCellRendererComponent(list,
844             value, index, isSelected, cellHasFocus);
845     component.setIcon(ItemsRenderer._icon);
846     if (value instanceof Item)
847     {
848       Item item = (Item) value;
849       if (item.getPublishDate() != null)
850       {
851         component.setText(MessageManager.formatMessage(
852                 "label.blog_item_published_on_date",
853                 new String[] {
854                     DateFormat
855                             .getDateInstance(DateFormat.LONG,
856                                     MessageManager.getLocale())
857                             .format(item.getPublishDate()).toString(),
858                     item.getTitle() }));
859       }
860       component.setToolTipText(item.getLink());
861       if (!item.isRead())
862       {
863         component.setFont(component.getFont().deriveFont(Font.BOLD));
864       }
865       else
866       {
867         component.setFont(component.getFont().deriveFont(Font.PLAIN));
868       }
869     }
870     return component;
871   }
872 }