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