more focus fixing (JAL-943)
[jalview.git] / src / jalview / gui / BlogReader.java
index 3b7df48..989d6c9 100644 (file)
@@ -46,14 +46,11 @@ import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
-import javax.swing.text.DateFormatter;
 
-import org.robsite.jswingreader.action.AboutAction;
 import org.robsite.jswingreader.action.MarkChannelAsRead;
 import org.robsite.jswingreader.action.MarkChannelAsUnread;
 import org.robsite.jswingreader.action.MarkItemAsRead;
 import org.robsite.jswingreader.action.MarkItemAsUnread;
-import org.robsite.jswingreader.action.RefreshChannelAction;
 import org.robsite.jswingreader.action.UpdatableAction;
 import org.robsite.jswingreader.model.Channel;
 import org.robsite.jswingreader.model.ChannelListModel;
@@ -63,9 +60,6 @@ import org.robsite.jswingreader.ui.BlogContentPane;
 import org.robsite.jswingreader.ui.ItemReadTimer;
 import org.robsite.jswingreader.ui.Main;
 import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter;
-import org.robsite.jswingreader.util.BrowserUtils;
-
-import quicktime.std.movies.media.TextDescription;
 
 /**
  * Blog reading window, adapted from JSwingReader's
@@ -74,8 +68,6 @@ import quicktime.std.movies.media.TextDescription;
 
 public class BlogReader extends GBlogReader
 {
-  private JButton buttonAbout = new JButton();
-
   private JButton buttonRefresh = new JButton();
 
   private JToolBar toolBar = new JToolBar();
@@ -92,10 +84,6 @@ public class BlogReader extends GBlogReader
 
   private JPanel bottomPanel = new JPanel();
 
-  private BorderLayout borderLayout2 = new BorderLayout();
-
-  private BorderLayout borderLayout3 = new BorderLayout();
-
   private JSplitPane topBottomSplitPane = new JSplitPane();
 
   private JList listItems = new JList(new DefaultListModel());
@@ -260,18 +248,24 @@ public class BlogReader extends GBlogReader
    */
   private boolean checkForNew(Channel chan, boolean updateItems)
   {
+    
     if (!updating || updateItems)
     {
       newsnew = false;
     }
+    java.util.Date earliest=null;
+    try {
+      earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan.getHTTPLastModified());
+    } catch (Exception x) {};
     if (chan != null && chan.getItems() != null)
     {
+      Cache.log.debug("Scanning news items: newsnew="+newsnew+" and lastDate is "+lastDate);
       for (Item i : (List<Item>) chan.getItems())
       {
-        boolean isread = (lastDate != null && i.getPublishDate() != null && !lastDate
+        boolean isread = lastDate==null ? false : (i.getPublishDate() != null && !lastDate
                 .before(i.getPublishDate()));
 
-        if (i.getPublishDate() != null && (!updating || updateItems))
+        if (!updating || updateItems)
         {
           newsnew |= !isread;
         }
@@ -279,8 +273,19 @@ public class BlogReader extends GBlogReader
         {
           i.setRead(isread);
         }
+        if (i.getPublishDate()!=null && !i.isRead())
+        {
+          if (earliest==null || earliest.after(i.getPublishDate()))
+          {
+            earliest=i.getPublishDate();
+          }
+        }
       }
     }
+    if (!updateItems && !updating && lastDate==null)
+    {
+      lastDate=earliest;
+    }
     return newsnew;
   }
 
@@ -293,22 +298,28 @@ public class BlogReader extends GBlogReader
 
   private void saveLastM(Item item)
   {
-    if (item != null && item.getPublishDate() != null
-            && (lastDate == null || item.getPublishDate().after(lastDate)))
+    if (item != null)
     {
-      lastDate = item.getPublishDate();
-      if (lastDate != null)
+      if (item.getPublishDate() != null)
       {
-        jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
-                lastDate);
-        jalview.bin.Cache.log.info("Saved last read date as "
-                + jalview.bin.Cache.date_format.format(lastDate));
-
+        if (lastDate==null || item.getPublishDate().after(lastDate))
+        {
+          lastDate = item.getPublishDate();
+        }
       }
+      
       if (_channelModel.getElementAt(0) != null)
       {
         checkForNew((Channel) _channelModel.getElementAt(0), false);
       }
+      if (lastDate != null)
+      {
+        jalview.bin.Cache.setDateProperty(
+                "JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate);
+        jalview.bin.Cache.log.info("Saved last read date as "
+                + jalview.bin.Cache.date_format.format(lastDate));
+
+      }
     }
   }