Merge branch 'update/JAL-3949_jalview_bin_Console_to_cure_sanity_even_more' into...
[jalview.git] / src / jalview / gui / Desktop.java
index e214816..ad36492 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.gui;
 
+import java.util.Locale;
+
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -380,11 +382,11 @@ public class Desktop extends jalview.jbgui.GDesktop
           awtAppClassNameField.setAccessible(true);
           awtAppClassNameField.set(xToolkit, title);
         } else {
-          Cache.log.debug("XToolkit: awtAppClassName not found");
+          jalview.bin.Console.debug("XToolkit: awtAppClassName not found");
         }
       } catch (Exception e) {
-        Cache.debug("Error setting awtAppClassName");
-        Cache.trace(Cache.getStackTraceString(e));
+        jalview.bin.Console.debug("Error setting awtAppClassName");
+        jalview.bin.Console.trace(Cache.getStackTraceString(e));
       }
     }
 
@@ -399,8 +401,8 @@ public class Desktop extends jalview.jbgui.GDesktop
       System.out.println("Cannot set APQHandlers");
       // e.printStackTrace();
     } catch (Throwable t) {
-      Cache.warn("Error setting APQHandlers: " + t.toString());
-      Cache.trace(Cache.getStackTraceString(t));
+      jalview.bin.Console.warn("Error setting APQHandlers: " + t.toString());
+      jalview.bin.Console.trace(Cache.getStackTraceString(t));
     }
     setIconImages(ChannelProperties.getIconList());
 
@@ -485,10 +487,10 @@ public class Desktop extends jalview.jbgui.GDesktop
       new Thread(new Runnable() {
         @Override
         public void run() {
-          Cache.log.debug("Filechooser init thread started.");
+          jalview.bin.Console.debug("Filechooser init thread started.");
           String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
           JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
-          Cache.log.debug("Filechooser init thread finished.");
+          jalview.bin.Console.debug("Filechooser init thread finished.");
         }
       }).start();
       // Add the service change listener
@@ -496,7 +498,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
         @Override
         public void propertyChange(PropertyChangeEvent evt) {
-          Cache.log.debug("Firing service changed event for " + evt.getNewValue());
+          jalview.bin.Console.debug("Firing service changed event for " + evt.getNewValue());
           JalviewServicesChanged(evt);
         }
       });
@@ -549,7 +551,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     if (Cache.getDefault(Preferences.ADD_SS_ANN, true)) {
       ssm.setAddTempFacAnnot(Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true));
       ssm.setProcessSecondaryStructure(Cache.getDefault(Preferences.STRUCT_FROM_PDB, true));
-      ssm.setSecStructServices(Cache.getDefault(Preferences.USE_RNAVIEW, true));
+      // JAL-3915 - RNAView is no longer an option so this has no effect
+      ssm.setSecStructServices(Cache.getDefault(Preferences.USE_RNAVIEW, false));
     } else {
       ssm.setAddTempFacAnnot(false);
       ssm.setProcessSecondaryStructure(false);
@@ -563,10 +566,10 @@ public class Desktop extends jalview.jbgui.GDesktop
     new Thread(new Runnable() {
       @Override
       public void run() {
-        Cache.log.debug("Starting news thread.");
+        jalview.bin.Console.debug("Starting news thread.");
         jvnews = new BlogReader(me);
         showNews.setVisible(true);
-        Cache.log.debug("Completed news thread.");
+        jalview.bin.Console.debug("Completed news thread.");
       }
     }).start();
   }
@@ -577,11 +580,11 @@ public class Desktop extends jalview.jbgui.GDesktop
       new Thread(new Runnable() {
         @Override
         public void run() {
-          Cache.log.debug("Downloading data from identifiers.org");
+          jalview.bin.Console.debug("Downloading data from identifiers.org");
           try {
             UrlDownloadClient.download(IdOrgSettings.getUrl(), IdOrgSettings.getDownloadLocation());
           } catch (IOException e) {
-            Cache.log.debug("Exception downloading identifiers.org data" + e.getMessage());
+            jalview.bin.Console.debug("Exception downloading identifiers.org data" + e.getMessage());
           }
         }
       }).start();
@@ -594,7 +597,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   void showNews(boolean visible) {
-    Cache.log.debug((visible ? "Showing" : "Hiding") + " news.");
+    jalview.bin.Console.debug((visible ? "Showing" : "Hiding") + " news.");
     showNews.setSelected(visible);
     if (visible && !jvnews.isVisible()) {
       new Thread(new Runnable() {
@@ -640,14 +643,14 @@ public class Desktop extends jalview.jbgui.GDesktop
         iy = (int) (iy * sh);
         ih = (int) (ih * sh);
         while (ix >= screenSize.width) {
-          Cache.log.debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
+          jalview.bin.Console.debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
           ix -= screenSize.width;
         }
         while (iy >= screenSize.height) {
-          Cache.log.debug("Window geometry location recall error: shifting vertical to within screenbounds.");
+          jalview.bin.Console.debug("Window geometry location recall error: shifting vertical to within screenbounds.");
           iy -= screenSize.height;
         }
-        Cache.log.debug("Got last known dimensions for " + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
+        jalview.bin.Console.debug("Got last known dimensions for " + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
             + " height:" + ih);
       }
       // return dimensions for new instance
@@ -849,14 +852,9 @@ public class Desktop extends jalview.jbgui.GDesktop
       frame.requestFocus();
     } catch (java.beans.PropertyVetoException ve) {
     } catch (java.lang.ClassCastException cex) {
-      Cache.log.warn(
-<<<<<<< HEAD
+      jalview.bin.Console.warn(
           "Squashed a possible GUI implementation error. If you can recreate this, please look at https://issues.jalview.org/browse/JAL-869",
           cex);
-=======
-              "Squashed a possible GUI implementation error. If you can recreate this, please look at https://issues.jalview.org/browse/JAL-869",
-              cex);
->>>>>>> 48040645e (JAL-3741 http to https (and jar to jvp for exampleFile defaults!))
     }
   }
 
@@ -1021,15 +1019,6 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     JPanel panel = new JPanel(new GridLayout(2, 1));
     panel.add(label);
-<<<<<<< HEAD
-=======
-    panel.add(history);
-    history.setPreferredSize(new Dimension(400, 20));
-    history.setEditable(true);
-    history.addItem("https://www.");
-
-    String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
->>>>>>> 48040645e (JAL-3741 http to https (and jar to jvp for exampleFile defaults!))
 
     /*
      * the URL to fetch is input in Java: an editable combobox with history JS:
@@ -1069,7 +1058,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         String url = (history instanceof JTextField ? ((JTextField) history).getText()
             : ((JComboBox<String>) history).getEditor().getItem().toString().trim());
 
-        if (url.toLowerCase().endsWith(".jar")) {
+        if (url.toLowerCase(Locale.ROOT).endsWith(".jar")) {
           if (viewport != null) {
             new FileLoader().LoadFile(viewport, url, DataSourceType.URL, FileFormat.Jalview);
           } else {
@@ -1151,7 +1140,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   private void storeLastKnownDimensions(String string, Rectangle jc) {
-    Cache.log.debug("Storing last known dimensions for " + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
+    jalview.bin.Console.debug("Storing last known dimensions for " + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
         + " height:" + jc.height);
 
     Cache.setProperty(string + "SCREEN_X", jc.x + "");
@@ -1195,14 +1184,13 @@ public class Desktop extends jalview.jbgui.GDesktop
       // message.append("<br>...Checking latest version...</br>");
     } else if (!latestVersion.equals(Cache.getProperty("VERSION"))) {
       boolean red = false;
-      if (Cache.getProperty("VERSION").toLowerCase().indexOf("automated build") == -1) {
+      if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT).indexOf("automated build") == -1) {
         red = true;
         // Displayed when code version and jnlp version do not match and code
         // version is not a development build
         message.append("<div style=\"color: #FF0000;font-style: bold;\">");
       }
 
-<<<<<<< HEAD
       message.append("<br>!! Version ").append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
           .append(" is available for download from ")
           .append(Cache.getDefault("www.jalview.org", "https://www.jalview.org")).append(" !!");
@@ -1217,31 +1205,6 @@ public class Desktop extends jalview.jbgui.GDesktop
     message.append("</div>");
 
     return message.toString();
-=======
-      message.append("<br>!! Version "
-              + jalview.bin.Cache.getDefault("LATEST_VERSION",
-                      "..Checking..")
-              + " is available for download from "
-              + jalview.bin.Cache.getDefault("www.jalview.org",
-                      "https://www.jalview.org")
-              + " !!");
-      if (red)
-      {
-        message.append("</div>");
-      }
-    }
-    message.append("<br>Authors:  " + jalview.bin.Cache.getDefault(
-            "AUTHORFNAMES",
-            "The Jalview Authors (See AUTHORS file for current list)")
-            + "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
-            + "<br><br>For help, see the FAQ at <a href=\"https://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list"
-            + "<br><br>If  you use Jalview, please cite:"
-            + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
-            + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
-            + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
-            + "</html>");
-    return message;
->>>>>>> 48040645e (JAL-3741 http to https (and jar to jvp for exampleFile defaults!))
   }
 
   /**
@@ -1312,9 +1275,9 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   protected void garbageCollect_actionPerformed(ActionEvent e) {
     // We simply collect the garbage
-    Cache.log.debug("Collecting garbage...");
+    jalview.bin.Console.debug("Collecting garbage...");
     System.gc();
-    Cache.log.debug("Finished garbage collection.");
+    jalview.bin.Console.debug("Finished garbage collection.");
   }
 
   /*
@@ -1478,7 +1441,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           } catch (OutOfMemoryError oom) {
             new OOMWarning("Whilst saving current state to " + chosenFile.getName(), oom);
           } catch (Exception ex) {
-            Cache.log.error("Problems whilst trying to save to " + chosenFile.getName(), ex);
+            jalview.bin.Console.error("Problems whilst trying to save to " + chosenFile.getName(), ex);
             JvOptionPane.showMessageDialog(me,
                 MessageManager.formatMessage("label.error_whilst_saving_current_state_to",
                     new Object[] { chosenFile.getName() }),
@@ -1533,7 +1496,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             } catch (OutOfMemoryError oom) {
               new OOMWarning("Whilst loading project from " + choice, oom);
             } catch (Exception ex) {
-              Cache.log.error("Problems whilst loading project from " + choice, ex);
+              jalview.bin.Console.error("Problems whilst loading project from " + choice, ex);
               JvOptionPane.showMessageDialog(Desktop.desktop,
                   MessageManager.formatMessage("label.error_whilst_loading_project_from", new Object[] { choice }),
                   MessageManager.getString("label.couldnt_load_project"), JvOptionPane.WARNING_MESSAGE);
@@ -2020,7 +1983,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     try {
       openGroovyConsole();
     } catch (Exception ex) {
-      Cache.log.error("Groovy Shell Creation failed.", ex);
+      jalview.bin.Console.error("Groovy Shell Creation failed.", ex);
       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
 
           MessageManager.getString("label.couldnt_create_groovy_shell"),
@@ -2331,7 +2294,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             });
           }
         } else {
-          Cache.log.error("Errors reported by JABA discovery service. Check web services preferences.\n" + ermsg);
+          jalview.bin.Console.error("Errors reported by JABA discovery service. Check web services preferences.\n" + ermsg);
         }
       }
     }
@@ -2402,11 +2365,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         Desktop.showUrl(url);
       } catch (Exception x) {
         if (url != null) {
-          if (Cache.log != null) {
-            Cache.log.error("Couldn't handle string " + url + " as a URL.");
-          } else {
-            System.err.println("Couldn't handle string " + url + " as a URL.");
-          }
+          jalview.bin.Console.error("Couldn't handle string " + url + " as a URL.");
         }
         // ignore any exceptions due to dud links.
       }
@@ -2452,7 +2411,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         try {
           SwingUtilities.invokeAndWait(prompter);
         } catch (Exception q) {
-          Cache.log.warn("Unexpected Exception in dialog thread.", q);
+          jalview.bin.Console.warn("Unexpected Exception in dialog thread.", q);
         }
       }
     });
@@ -2486,7 +2445,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       @Override
       public void exportImage(Graphics g) throws Exception {
         paintAll(g);
-        Cache.log.info("Successfully written snapshot to file " + of.getAbsolutePath());
+        jalview.bin.Console.info("Successfully written snapshot to file " + of.getAbsolutePath());
       }
     };
     String title = "View of desktop";
@@ -2645,7 +2604,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     try {
       urlFlavour = new DataFlavor("application/x-java-url; class=java.net.URL");
     } catch (ClassNotFoundException cfe) {
-      Cache.log.debug("Couldn't instantiate the URL dataflavor.", cfe);
+      jalview.bin.Console.debug("Couldn't instantiate the URL dataflavor.", cfe);
     }
 
     if (urlFlavour != null && t.isDataFlavorSupported(urlFlavour)) {
@@ -2657,7 +2616,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         if (url != null) {
           protocols.add(DataSourceType.URL);
           files.add(url.toString());
-          Cache.log.debug("Drop handled as URL dataflavor " + files.get(files.size() - 1));
+          jalview.bin.Console.debug("Drop handled as URL dataflavor " + files.get(files.size() - 1));
           return;
         } else {
           if (Platform.isAMacAndNotJS()) {
@@ -2665,12 +2624,12 @@ public class Desktop extends jalview.jbgui.GDesktop
           }
         }
       } catch (Throwable ex) {
-        Cache.log.debug("URL drop handler failed.", ex);
+        jalview.bin.Console.debug("URL drop handler failed.", ex);
       }
     }
     if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
       // Works on Windows and MacOSX
-      Cache.log.debug("Drop handled as javaFileListFlavor");
+      jalview.bin.Console.debug("Drop handled as javaFileListFlavor");
       for (Object file : (List) t.getTransferData(DataFlavor.javaFileListFlavor)) {
         files.add(file);
         protocols.add(DataSourceType.FILE);
@@ -2680,25 +2639,25 @@ public class Desktop extends jalview.jbgui.GDesktop
       boolean added = false;
       String data = null;
       if (t.isDataFlavorSupported(uriListFlavor)) {
-        Cache.log.debug("Drop handled as uriListFlavor");
+        jalview.bin.Console.debug("Drop handled as uriListFlavor");
         // This is used by Unix drag system
         data = (String) t.getTransferData(uriListFlavor);
       }
       if (data == null) {
         // fallback to text: workaround - on OSX where there's a JVM bug
-        Cache.log.debug("standard URIListFlavor failed. Trying text");
+        jalview.bin.Console.debug("standard URIListFlavor failed. Trying text");
         // try text fallback
         DataFlavor textDf = new DataFlavor("text/plain;class=java.lang.String");
         if (t.isDataFlavorSupported(textDf)) {
           data = (String) t.getTransferData(textDf);
         }
 
-        Cache.log.debug("Plain text drop content returned " + (data == null ? "Null - failed" : data));
+        jalview.bin.Console.debug("Plain text drop content returned " + (data == null ? "Null - failed" : data));
 
       }
       if (data != null) {
         while (protocols.size() < files.size()) {
-          Cache.log.debug("Adding missing FILE protocol for " + files.get(protocols.size()));
+          jalview.bin.Console.debug("Adding missing FILE protocol for " + files.get(protocols.size()));
           protocols.add(DataSourceType.FILE);
         }
         for (java.util.StringTokenizer st = new java.util.StringTokenizer(data, "\r\n"); st.hasMoreTokens();) {
@@ -2709,7 +2668,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             continue;
           }
           java.net.URI uri = new java.net.URI(s);
-          if (uri.getScheme().toLowerCase().startsWith("http")) {
+          if (uri.getScheme().toLowerCase(Locale.ROOT).startsWith("http")) {
             protocols.add(DataSourceType.URL);
             files.add(uri.toString());
           } else {
@@ -2721,46 +2680,46 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
 
-      if (Cache.log.isDebugEnabled()) {
+      if (jalview.bin.Console.isDebugEnabled()) {
         if (data == null || !added) {
 
           if (t.getTransferDataFlavors() != null && t.getTransferDataFlavors().length > 0) {
-            Cache.log.debug("Couldn't resolve drop data. Here are the supported flavors:");
+            jalview.bin.Console.debug("Couldn't resolve drop data. Here are the supported flavors:");
             for (DataFlavor fl : t.getTransferDataFlavors()) {
-              Cache.log.debug("Supported transfer dataflavor: " + fl.toString());
+              jalview.bin.Console.debug("Supported transfer dataflavor: " + fl.toString());
               Object df = t.getTransferData(fl);
               if (df != null) {
-                Cache.log.debug("Retrieves: " + df);
+                jalview.bin.Console.debug("Retrieves: " + df);
               } else {
-                Cache.log.debug("Retrieved nothing");
+                jalview.bin.Console.debug("Retrieved nothing");
               }
             }
           } else {
-            Cache.log.debug("Couldn't resolve dataflavor for drop: " + t.toString());
+            jalview.bin.Console.debug("Couldn't resolve dataflavor for drop: " + t.toString());
           }
         }
       }
     }
     if (Platform.isWindowsAndNotJS()) {
-      Cache.log.debug("Scanning dropped content for Windows Link Files");
+      jalview.bin.Console.debug("Scanning dropped content for Windows Link Files");
 
       // resolve any .lnk files in the file drop
       for (int f = 0; f < files.size(); f++) {
-        String source = files.get(f).toString().toLowerCase();
+        String source = files.get(f).toString().toLowerCase(Locale.ROOT);
         if (protocols.get(f).equals(DataSourceType.FILE)
             && (source.endsWith(".lnk") || source.endsWith(".url") || source.endsWith(".site"))) {
           try {
             Object obj = files.get(f);
             File lf = (obj instanceof File ? (File) obj : new File((String) obj));
             // process link file to get a URL
-            Cache.log.debug("Found potential link file: " + lf);
+            jalview.bin.Console.debug("Found potential link file: " + lf);
             WindowsShortcut wscfile = new WindowsShortcut(lf);
             String fullname = wscfile.getRealFilename();
             protocols.set(f, FormatAdapter.checkProtocol(fullname));
             files.set(f, fullname);
-            Cache.log.debug("Parsed real filename " + fullname + " to extract protocol: " + protocols.get(f));
+            jalview.bin.Console.debug("Parsed real filename " + fullname + " to extract protocol: " + protocols.get(f));
           } catch (Exception ex) {
-            Cache.log.error("Couldn't parse " + files.get(f) + " as a link file.", ex);
+            jalview.bin.Console.error("Couldn't parse " + files.get(f) + " as a link file.", ex);
           }
         }
       }
@@ -2819,14 +2778,14 @@ public class Desktop extends jalview.jbgui.GDesktop
         AffineTransform t = gg.getTransform();
         double scaleX = t.getScaleX();
         double scaleY = t.getScaleY();
-        Cache.debug(debugScaleMessage + scaleX + " (X)");
-        Cache.debug(debugScaleMessage + scaleY + " (Y)");
+        jalview.bin.Console.debug(debugScaleMessage + scaleX + " (X)");
+        jalview.bin.Console.debug(debugScaleMessage + scaleY + " (Y)");
         debugScaleMessageDone = true;
       } else {
-        Cache.debug("Desktop graphics null");
+        jalview.bin.Console.debug("Desktop graphics null");
       }
     } catch (Exception e) {
-      Cache.debug(Cache.getStackTraceString(e));
+      jalview.bin.Console.debug(Cache.getStackTraceString(e));
     }
   }
 }