JAL-3949 - refactor logging from jalview.bin.Cache to jalview.bin.Console
[jalview.git] / src / jalview / gui / BlogReader.java
index edea2dc..3dc51ce 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -41,6 +42,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -198,7 +200,7 @@ public class BlogReader extends JPanel
       {
         if (parent != null)
         {
-          Cache.log.debug("News window closed.");
+          Console.debug("News window closed.");
           jd = null;
           parent.showNews(false);
         }
@@ -218,7 +220,7 @@ public class BlogReader extends JPanel
 
       }
     };
-  };
+  }
 
   private JLabel lblChannels = new JLabel();
 
@@ -246,16 +248,17 @@ public class BlogReader extends JPanel
 
   public BlogReader(Desktop desktop)
   {
-    Cache.log.debug("Constructing news reader.");
+    Console.debug("Constructing news reader.");
 
     parent = desktop;
     _channelModel = new ChannelListModel();
     // Construct our jalview news channel
     Channel chan = new Channel();
-    chan.setURL(jalview.bin.Cache.getDefault(
-            "JALVIEW_NEWS_RSS",
-            jalview.bin.Cache.getDefault("www.jalview.org",
-                    "http://www.jalview.org") + "/feeds/desktop/rss"));
+    chan.setURL(
+            Cache.getDefault("JALVIEW_NEWS_RSS",
+                    Cache.getDefault("www.jalview.org",
+                            "https://www.jalview.org")
+                            + "/feeds/desktop/rss"));
     loadLastM();
     _channelModel.addChannel(chan);
     updating = true;
@@ -275,10 +278,10 @@ public class BlogReader extends JPanel
     if (setvisible)
     {
 
-      Cache.log.debug("Will show jalview news automatically");
+      Console.debug("Will show jalview news automatically");
       showNews();
     }
-    Cache.log.debug("Completed construction of reader.");
+    Console.debug("Completed construction of reader.");
 
   }
 
@@ -317,8 +320,8 @@ public class BlogReader extends JPanel
             public void windowClosing(WindowEvent e)
             {
               ActionEvent actionEvent = new ActionEvent(this,
-                      ActionEvent.ACTION_FIRST, (String) exitAction
-                              .getValue(Action.NAME));
+                      ActionEvent.ACTION_FIRST,
+                      (String) exitAction.getValue(Action.NAME));
               exitAction.actionPerformed(actionEvent);
             }
 
@@ -338,7 +341,7 @@ public class BlogReader extends JPanel
                   MessageManager.getString("label.news_from_jalview"),
                   bounds.width, bounds.height);
           jd.frame.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
-          Cache.log.debug("Displaying news.");
+          Console.debug("Displaying news.");
           jd.waitForInput();
         }
       }
@@ -358,21 +361,20 @@ public class BlogReader extends JPanel
     java.util.Date earliest = null;
     try
     {
-      earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan
-              .getHTTPLastModified());
+      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
+      Console.debug("Scanning news items: newsnew=" + newsnew
               + " and lastDate is " + lastDate);
       for (Item i : (List<Item>) chan.getItems())
       {
+        Date published = i.getPublishDate();
         boolean isread = lastDate == null ? false
-                : (i.getPublishDate() != null && !lastDate.before(i
-                        .getPublishDate()));
+                : (published != null && !lastDate.before(published));
 
         if (!updating || updateItems)
         {
@@ -382,11 +384,11 @@ public class BlogReader extends JPanel
         {
           i.setRead(isread);
         }
-        if (i.getPublishDate() != null && !i.isRead())
+        if (published != null && !i.isRead())
         {
-          if (earliest == null || earliest.after(i.getPublishDate()))
+          if (earliest == null || earliest.after(published))
           {
-            earliest = i.getPublishDate();
+            earliest = published;
           }
         }
       }
@@ -423,9 +425,9 @@ public class BlogReader extends JPanel
       }
       if (lastDate != null)
       {
-        String formatted = Cache.setDateProperty(
-                "JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate);
-        Cache.log.debug("Saved last read date as " + formatted);
+        String formatted = Cache
+                .setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate);
+        Console.debug("Saved last read date as " + formatted);
       }
     }
   }
@@ -528,15 +530,15 @@ public class BlogReader extends JPanel
     _itemsValueChanged(listItems);
   }
 
-  public class LaunchJvBrowserOnItem extends AbstractAction implements
-          UpdatableAction
+  public class LaunchJvBrowserOnItem extends AbstractAction
+          implements UpdatableAction
   {
     JList _listItems = null;
 
     public LaunchJvBrowserOnItem(JList listItems)
     {
       super("Open in Browser");
-      this.putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
+      this.putValue(MNEMONIC_KEY, Integer.valueOf(KeyEvent.VK_O));
       this.putValue(Action.LONG_DESCRIPTION, "Open in Browser");
       _listItems = listItems;
     }
@@ -584,7 +586,8 @@ public class BlogReader extends JPanel
   private JPopupMenu _buildChannelsPopupMenu()
   {
     JPopupMenu popup = new JPopupMenu();
-    popup.add(new JMenuItem(new MarkChannelAsRead(listChannels, listItems)));
+    popup.add(
+            new JMenuItem(new MarkChannelAsRead(listChannels, listItems)));
     popup.add(new JMenuItem(
             new MarkChannelAsUnread(listChannels, listItems)));
     return popup;
@@ -608,8 +611,9 @@ public class BlogReader extends JPanel
     }
     DefaultListModel itemsModel = (DefaultListModel) listItems.getModel();
     itemsModel.clear();
-    Iterator iter = (channel.getItems() != null) ? channel.getItems()
-            .iterator() : Collections.EMPTY_LIST.iterator();
+    Iterator iter = (channel.getItems() != null)
+            ? channel.getItems().iterator()
+            : Collections.EMPTY_LIST.iterator();
     while (iter.hasNext())
     {
       itemsModel.addElement(iter.next());
@@ -705,8 +709,8 @@ public class BlogReader extends JPanel
           button.setVerticalTextPosition(AbstractButton.BOTTOM);
           button.setHorizontalTextPosition(AbstractButton.CENTER);
         }
-        else if (Boolean.toString(true).equals(
-                general.get("radioTextRight")))
+        else if (Boolean.toString(true)
+                .equals(general.get("radioTextRight")))
         {
           button.setVerticalTextPosition(AbstractButton.CENTER);
           button.setHorizontalTextPosition(AbstractButton.RIGHT);
@@ -748,15 +752,19 @@ public class BlogReader extends JPanel
     }
   }
 
+  /**
+   * @j2sIgnore
+   * @param args
+   */
   public static void main(String args[])
   {
     // this tests the detection of new news based on the last read date stored
     // in jalview properties
-    jalview.bin.Cache.loadProperties(null);
-    jalview.bin.Cache.initLogger();
+    Cache.loadProperties(null);
+    Console.initLogger();
     // test will advance read date each time
-    Calendar today = Calendar.getInstance(), lastread = Calendar
-            .getInstance();
+    Calendar today = Calendar.getInstance(),
+            lastread = Calendar.getInstance();
     lastread.set(1983, 01, 01);
     while (lastread.before(today))
     {
@@ -766,16 +774,16 @@ public class BlogReader extends JPanel
       System.out.println("Set last date to " + formattedDate);
       if (me.isNewsNew())
       {
-        Cache.log.debug("There is news to read.");
+        Console.debug("There is news to read.");
       }
       else
       {
-        Cache.log.debug("There is no new news.");
+        Console.debug("There is no new news.");
         me.xf.setTitle("Testing : Last read is " + me.lastDate);
         me.showNews();
         me.xf.toFront();
       }
-      Cache.log.debug("Waiting for closure.");
+      Console.debug("Waiting for closure.");
       do
       {
         try
@@ -784,16 +792,15 @@ public class BlogReader extends JPanel
         } catch (InterruptedException x)
         {
         }
-        ;
       } while (me.isVisible());
 
       if (me.isNewsNew())
       {
-        Cache.log.debug("Still new news after reader displayed.");
+        Console.debug("Still new news after reader displayed.");
       }
       if (lastread.getTime().before(me.lastDate))
       {
-        Cache.log.debug("The news was read.");
+        Console.debug("The news was read.");
         lastread.setTime(me.lastDate);
       }
       else
@@ -825,13 +832,10 @@ class ChannelsRenderer extends DefaultListCellRenderer
     if (value instanceof Channel)
     {
       Channel channel = (Channel) value;
-      component
-              .setText(MessageManager.formatMessage(
-                      "label.channel_title_item_count",
-                      new String[] {
-                          channel.getTitle(),
-                          Integer.valueOf(channel.getUnreadItemCount())
-                                  .toString() }));
+      component.setText(MessageManager
+              .formatMessage("label.channel_title_item_count", new String[]
+              { channel.getTitle(), Integer
+                      .valueOf(channel.getUnreadItemCount()).toString() }));
       component.setToolTipText(channel.getURL());
     }
     return component;
@@ -856,12 +860,11 @@ class ItemsRenderer extends DefaultListCellRenderer
       if (item.getPublishDate() != null)
       {
         component.setText(MessageManager.formatMessage(
-                "label.blog_item_published_on_date",
-                new String[] {
-                    DateFormat
-                            .getDateInstance(DateFormat.LONG,
-                                    MessageManager.getLocale())
-                            .format(item.getPublishDate()).toString(),
+                "label.blog_item_published_on_date", new String[]
+                { DateFormat
+                        .getDateInstance(DateFormat.LONG,
+                                MessageManager.getLocale())
+                        .format(item.getPublishDate()).toString(),
                     item.getTitle() }));
       }
       component.setToolTipText(item.getLink());