7d4399dc7059af654471bdfba4d4caa082651ba3
[jalview.git] / src / jalview / gui / BlogReader.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 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, MessageManager.getString("label.news_from_jalview"),
335                   bounds.width, bounds.height);
336           jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
337           Cache.log.debug("Displaying news.");
338           jd.waitForInput();
339         }
340       }
341     });
342   }
343
344   /**
345    * update hasnew flag and mark all new messages as unread.
346    */
347   private boolean checkForNew(Channel chan, boolean updateItems)
348   {
349
350     if (!updating || updateItems)
351     {
352       newsnew = false;
353     }
354     java.util.Date earliest = null;
355     try
356     {
357       earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan
358               .getHTTPLastModified());
359     } catch (Exception x)
360     {
361     }
362     ;
363     if (chan != null && chan.getItems() != null)
364     {
365       Cache.log.debug("Scanning news items: newsnew=" + newsnew
366               + " and lastDate is " + lastDate);
367       for (Item i : (List<Item>) chan.getItems())
368       {
369         boolean isread = lastDate == null ? false
370                 : (i.getPublishDate() != null && !lastDate.before(i
371                         .getPublishDate()));
372
373         if (!updating || updateItems)
374         {
375           newsnew |= !isread;
376         }
377         if (updateItems)
378         {
379           i.setRead(isread);
380         }
381         if (i.getPublishDate() != null && !i.isRead())
382         {
383           if (earliest == null || earliest.after(i.getPublishDate()))
384           {
385             earliest = i.getPublishDate();
386           }
387         }
388       }
389     }
390     if (!updateItems && !updating && lastDate == null)
391     {
392       lastDate = earliest;
393     }
394     return newsnew;
395   }
396
397   java.util.Date lastDate = null;
398
399   private void loadLastM()
400   {
401     lastDate = Cache.getDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED");
402   }
403
404   private void saveLastM(Item item)
405   {
406     if (item != null)
407     {
408       if (item.getPublishDate() != null)
409       {
410         if (lastDate == null || item.getPublishDate().after(lastDate))
411         {
412           lastDate = item.getPublishDate();
413         }
414       }
415
416       if (_channelModel.getElementAt(0) != null)
417       {
418         checkForNew((Channel) _channelModel.getElementAt(0), false);
419       }
420       if (lastDate != null)
421       {
422         jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
423                 lastDate);
424         jalview.bin.Cache.log.debug("Saved last read date as "
425                 + jalview.bin.Cache.date_format.format(lastDate));
426
427       }
428     }
429   }
430
431   private void jbInit() throws Exception
432   {
433     setLayout(layoutMain);
434     panelMain.setLayout(borderLayout1);
435     topPanel.setLayout(borderLayout5);
436     bottomPanel.setLayout(borderLayout4);
437     topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
438     topBottomSplitPane.setDividerLocation(100);
439     topBottomSplitPane.setTopComponent(topPanel);
440     topBottomSplitPane.setBottomComponent(bottomPanel);
441     JScrollPane spTextDescription = new JScrollPane(textDescription);
442     textDescription.setText("");
443     statusBar.setText(new StringBuffer("[").append(MessageManager.getString("label.status")).append("]").toString());
444     buttonRefresh.addActionListener(new ActionListener()
445     {
446
447       @Override
448       public void actionPerformed(ActionEvent e)
449       {
450         refreshNews();
451       }
452     });
453     add(statusBar, BorderLayout.SOUTH);
454     toolBar.add(buttonRefresh);
455     toolBar.addSeparator();
456     JLabel about = new JLabel(
457             "brought to you by JSwingReader (jswingreader.sourceforge.net)");
458     toolBar.add(about);
459     toolBar.setFloatable(false);
460     add(toolBar, BorderLayout.NORTH);
461     panelMain.add(topBottomSplitPane, BorderLayout.CENTER);
462     add(panelMain, BorderLayout.CENTER);
463     JScrollPane spListItems = new JScrollPane(listItems);
464     listItems
465             .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
466     topPanel.add(spListItems, BorderLayout.CENTER);
467     bottomPanel.add(spTextDescription, BorderLayout.CENTER);
468     listChannels.setModel(_channelModel);
469
470     listItems.addMouseListener(new java.awt.event.MouseAdapter()
471     {
472       public void mouseClicked(MouseEvent e)
473       {
474         listItems_mouseClicked(e);
475       }
476     });
477     _popupItems = _buildItemsPopupMenu();
478     _popupChannels = _buildChannelsPopupMenu();
479     ContextMenuMouseAdapter popupAdapter = new ContextMenuMouseAdapter(
480             _popupItems);
481     ContextMenuMouseAdapter popupChannelsAdapter = new ContextMenuMouseAdapter(
482             _popupChannels);
483     listItems.addMouseListener(popupAdapter);
484     listItems.setCellRenderer(new ItemsRenderer());
485     lblChannels.setText(MessageManager.getString("label.channels"));
486   }
487
488   private void postInit()
489   {
490     // clear the default hyperlink listener and replace with our own.
491     for (HyperlinkListener hll : textDescription.getHyperlinkListeners())
492     {
493       textDescription.removeHyperlinkListener(hll);
494     }
495     textDescription.addHyperlinkListener(new HyperlinkListener()
496     {
497       public void hyperlinkUpdate(HyperlinkEvent e)
498       {
499         if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
500         {
501           Desktop.showUrl(e.getURL().toExternalForm());
502         }
503       }
504     });
505
506     listItems.addListSelectionListener(new ListSelectionListener()
507     {
508       public void valueChanged(ListSelectionEvent e)
509       {
510         if (e.getValueIsAdjusting() == false)
511         {
512           _itemsValueChanged(listItems);
513         }
514       }
515     });
516     listChannels.setSelectedIndex(1);
517     _updateAllActions();
518     _updateToolbarButtons();
519
520     _itemTimer = new ItemReadTimer(listChannels, listItems);
521     _itemsValueChanged(listItems);
522   }
523
524   public class LaunchJvBrowserOnItem extends AbstractAction implements
525           UpdatableAction
526   {
527     JList _listItems = null;
528
529     public LaunchJvBrowserOnItem(JList listItems)
530     {
531       super("Open in Browser");
532       this.putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
533       this.putValue(Action.LONG_DESCRIPTION, "Open in Browser");
534       _listItems = listItems;
535     }
536
537     public void actionPerformed(ActionEvent e)
538     {
539       Object o = _listItems.getSelectedValue();
540       if (o instanceof Item)
541       {
542         Item item = (Item) o;
543         item.setRead(true);
544         _listItems.repaint();
545
546         Desktop.showUrl(item.getLink());
547       }
548     }
549
550     public void update(Object o)
551     {
552       setEnabled(true);
553       if (_listItems == null || _listItems.getModel().getSize() == 0)
554       {
555         setEnabled(false);
556       }
557       else if (_listItems.getSelectedIndex() == -1)
558       {
559         setEnabled(false);
560       }
561     }
562
563   }
564
565   private JPopupMenu _buildItemsPopupMenu()
566   {
567     JPopupMenu popup = new JPopupMenu();
568     popup.add(new JMenuItem(new LaunchJvBrowserOnItem(listItems)));
569     popup.addSeparator();
570     popup.add(new JMenuItem(new MarkItemAsRead(listItems)));
571     popup.add(new JMenuItem(new MarkItemAsUnread(listItems)));
572     return popup;
573   }
574
575   private JPopupMenu _buildChannelsPopupMenu()
576   {
577     JPopupMenu popup = new JPopupMenu();
578     popup.add(new JMenuItem(new MarkChannelAsRead(listChannels, listItems)));
579     popup.add(new JMenuItem(
580             new MarkChannelAsUnread(listChannels, listItems)));
581     return popup;
582   }
583
584   private void initItems(Channel channel)
585   {
586     if (channel == null)
587     {
588       channel = new Channel();
589     }
590     if (!channel.isOpen() && channel.getURL() != null)
591     {
592       try
593       {
594         SimpleRSSParser.parse(channel);
595       } catch (Exception ex)
596       {
597         ex.printStackTrace();
598       }
599     }
600     DefaultListModel itemsModel = (DefaultListModel) listItems.getModel();
601     itemsModel.clear();
602     Iterator iter = (channel.getItems() != null) ? channel.getItems()
603             .iterator() : Collections.EMPTY_LIST.iterator();
604     while (iter.hasNext())
605     {
606       itemsModel.addElement(iter.next());
607     }
608     if (itemsModel.getSize() > 0)
609     {
610       listItems.setSelectedIndex(0);
611       _itemsValueChanged(listItems);
612     }
613     setStatusBarText(channel.getURL());
614     _updateAllActions();
615   }
616
617   private void _itemsValueChanged(JList itemList)
618   {
619     Item item = (Item) itemList.getSelectedValue();
620     if (item == null)
621     {
622       if (itemList.getModel().getSize() > 0)
623       {
624         item = (Item) itemList.getModel().getElementAt(0);
625       }
626       if (item == null)
627       {
628         item = new Item();
629       }
630       else
631       {
632         itemList.setSelectedIndex(0);
633       }
634     }
635
636     if (_itemTimer != null)
637     {
638       // prefer a shorter delay than 5s
639       _itemTimer.setDelay(300);
640       _itemTimer.start();
641       _itemTimer.setLastItem(item);
642       final Item lastitem = item;
643       _itemTimer.addActionListener(new ActionListener()
644       {
645
646         @Override
647         public void actionPerformed(ActionEvent e)
648         {
649           saveLastM(lastitem);
650         }
651       });
652     }
653
654     setStatusBarText(item.getLink());
655     textDescription.setBlogText(item);
656     _updateAllActions();
657   }
658
659   public void setStatusBarText(String text)
660   {
661     statusBar.setText(text);
662   }
663
664   private void _updateAllActions()
665   {
666     Iterator iter = _updatableActions.iterator();
667     while (iter.hasNext())
668     {
669       UpdatableAction action = (UpdatableAction) iter.next();
670       action.update(this);
671     }
672   }
673
674   private void _updateToolbarButtons()
675   {
676     Map general = (Map) Main.getPreferences().get("general");
677     if (general == null)
678     {
679       return;
680     }
681
682     Component[] components = toolBar.getComponents();
683     for (int i = 0; i < components.length; i++)
684     {
685       Component component = components[i];
686       if (component instanceof JButton)
687       {
688         JButton button = (JButton) component;
689         if (Boolean.toString(false).equals(general.get("useToolBarText")))
690         {
691           // Remove the text if preferences state no toolbar text
692           button.setText("");
693         }
694         if (Boolean.toString(true).equals(general.get("radioTextBelow")))
695         {
696           button.setVerticalTextPosition(AbstractButton.BOTTOM);
697           button.setHorizontalTextPosition(AbstractButton.CENTER);
698         }
699         else if (Boolean.toString(true).equals(
700                 general.get("radioTextRight")))
701         {
702           button.setVerticalTextPosition(AbstractButton.CENTER);
703           button.setHorizontalTextPosition(AbstractButton.RIGHT);
704         }
705       }
706     }
707   }
708
709   private void listItems_mouseClicked(MouseEvent e)
710   {
711     if (e.getClickCount() == 2 && e.getModifiersEx() == MouseEvent.NOBUTTON)
712     {
713       Item item = (Item) listItems.getSelectedValue();
714       item.setRead(true);
715       saveLastM(item);
716       if (_itemTimer != null)
717       {
718         _itemTimer.stop();
719       }
720
721       Action action = new LaunchJvBrowserOnItem(listItems);
722       ActionEvent event = new ActionEvent(this,
723               ActionEvent.ACTION_PERFORMED, "LaunchBrowserOnItem");
724       action.actionPerformed(event);
725     }
726   }
727
728   /**
729    * force the news panel to refresh
730    */
731   public void refreshNews()
732   {
733     try
734     {
735       initItems((Channel) _channelModel.getElementAt(0));
736
737     } catch (Exception x)
738     {
739     }
740   }
741
742   public static void main(String args[])
743   {
744     // this tests the detection of new news based on the last read date stored
745     // in jalview properties
746     jalview.bin.Cache.loadProperties(null);
747     jalview.bin.Cache.initLogger();
748     // test will advance read date each time
749     Calendar today = Calendar.getInstance(), lastread = Calendar
750             .getInstance();
751     lastread.set(1983, 01, 01);
752     while (lastread.before(today))
753     {
754       Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
755               lastread.getTime());
756       BlogReader me = new BlogReader();
757       System.out.println("Set last date to "
758               + jalview.bin.Cache.date_format.format(lastread.getTime()));
759       if (me.isNewsNew())
760       {
761         Cache.log.debug("There is news to read.");
762       }
763       else
764       {
765         Cache.log.debug("There is no new news.");
766         me.xf.setTitle("Testing : Last read is " + me.lastDate);
767         me.showNews();
768         me.xf.toFront();
769       }
770       Cache.log.debug("Waiting for closure.");
771       do
772       {
773         try
774         {
775           Thread.sleep(300);
776         } catch (InterruptedException x)
777         {
778         }
779         ;
780       } while (me.isVisible());
781
782       if (me.isNewsNew())
783       {
784         Cache.log.debug("Still new news after reader displayed.");
785       }
786       if (lastread.getTime().before(me.lastDate))
787       {
788         Cache.log.debug("The news was read.");
789         lastread.setTime(me.lastDate);
790       }
791       else
792       {
793         lastread.add(Calendar.MONTH, 1);
794       }
795
796     }
797   }
798
799   boolean isNewsNew()
800   {
801     return newsnew;
802   }
803 }
804
805 class ChannelsRenderer extends DefaultListCellRenderer
806 {
807   private final static Icon _icon = new ImageIcon(
808           Main.class.getResource("image/ComposeMail16.gif"));
809
810   public Component getListCellRendererComponent(JList list, Object value,
811           int index, boolean isSelected, boolean cellHasFocus)
812   {
813     JLabel component = (JLabel) super.getListCellRendererComponent(list,
814             value, index, isSelected, cellHasFocus);
815     component.setIcon(ChannelsRenderer._icon);
816     if (value instanceof Channel)
817     {
818       Channel channel = (Channel) value;
819       component
820               .setText(MessageManager.formatMessage(
821                       "label.channel_title_item_count",
822                       new String[]
823                       {
824                           channel.getTitle(),
825                           Integer.valueOf(channel.getUnreadItemCount())
826                                   .toString() }));
827       component.setToolTipText(channel.getURL());
828     }
829     return component;
830   }
831 }
832
833 class ItemsRenderer extends DefaultListCellRenderer
834 {
835   private final static Icon _icon = new ImageIcon(
836           Main.class.getResource("image/ComposeMail16.gif"));
837
838   public Component getListCellRendererComponent(JList list, Object value,
839           int index, boolean isSelected, boolean cellHasFocus)
840   {
841     JLabel component = (JLabel) super.getListCellRendererComponent(list,
842             value, index, isSelected, cellHasFocus);
843     component.setIcon(ItemsRenderer._icon);
844     if (value instanceof Item)
845     {
846       Item item = (Item) value;
847       if (item.getPublishDate() != null)
848       {
849         component.setText(MessageManager.formatMessage(
850                 "label.blog_item_published_on_date",
851                 new String[]
852                 {
853                     DateFormat
854                             .getDateInstance(DateFormat.LONG,
855                                     MessageManager.getLocale())
856                             .format(item.getPublishDate()).toString(),
857                     item.getTitle() }));
858       }
859       component.setToolTipText(item.getLink());
860       if (!item.isRead())
861       {
862         component.setFont(component.getFont().deriveFont(Font.BOLD));
863       }
864       else
865       {
866         component.setFont(component.getFont().deriveFont(Font.PLAIN));
867       }
868     }
869     return component;
870   }
871 }