JAL-3130 trying to be Java 1.8 source compatible -- not sure if this is ultimately...
authorBen Soares <bsoares@dundee.ac.uk>
Thu, 4 Apr 2019 10:10:01 +0000 (11:10 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Thu, 4 Apr 2019 10:10:01 +0000 (11:10 +0100)
src/jalview/ext/htsjdk/VCFReader.java
src/jalview/gui/Desktop.java

index ceff642..04525f0 100644 (file)
@@ -116,7 +116,7 @@ public class VCFReader implements Closeable, Iterable<VariantContext>
   {
     final CloseableIterator<VariantContext> it = reader.iterator();
     
-    return new CloseableIterator<>()
+    return new CloseableIterator()
     {
       boolean atEnd = false;
 
index 4c0faa8..fc36047 100644 (file)
@@ -62,7 +62,8 @@ import java.awt.datatransfer.Clipboard;
 import java.awt.datatransfer.ClipboardOwner;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
-import java.awt.desktop.AboutEvent;
+import java.awt.desktop.QuitStrategy;
+/* not importing directly. Calling classes with full name in try block to allow Java 1.8 runtime
 import java.awt.desktop.AboutHandler;
 import java.awt.desktop.PreferencesEvent;
 import java.awt.desktop.PreferencesHandler;
@@ -70,6 +71,7 @@ import java.awt.desktop.QuitEvent;
 import java.awt.desktop.QuitHandler;
 import java.awt.desktop.QuitResponse;
 import java.awt.desktop.QuitStrategy;
+*/
 import java.awt.dnd.DnDConstants;
 import java.awt.dnd.DropTargetDragEvent;
 import java.awt.dnd.DropTargetDropEvent;
@@ -381,91 +383,111 @@ public class Desktop extends jalview.jbgui.GDesktop
 
       try
       {
+        Float specversion = Float.parseFloat(
+                System.getProperty("java.specification.version"));
 
-        if (Platform.isAMac())
+        if (specversion >= 9)
         {
-          if (desktopClass.getDeclaredMethod("setAboutHandler",
-                  new Class[]
-                  { AboutHandler.class }) != null)
+          if (Platform.isAMac())
           {
-
-            hdesktop.setAboutHandler(new AboutHandler()
+            if (desktopClass.getDeclaredMethod("setAboutHandler",
+                    new Class[]
+                    { java.awt.desktop.AboutHandler.class }) != null)
             {
-              @Override
-              public void handleAbout(AboutEvent e)
-              {
-                aboutMenuItem_actionPerformed(null);
-              }
-            });
 
-          }
+              hdesktop.setAboutHandler(new java.awt.desktop.AboutHandler()
+              {
+                @Override
+                public void handleAbout(java.awt.desktop.AboutEvent e)
+                {
+                  aboutMenuItem_actionPerformed(null);
+                }
+              });
 
-          if (desktopClass.getDeclaredMethod("setPreferencesHandler",
-                  new Class[]
-                  { PreferencesHandler.class }) != null)
-          {
+            }
 
-            hdesktop.setPreferencesHandler(new PreferencesHandler()
+            if (desktopClass.getDeclaredMethod("setPreferencesHandler",
+                    new Class[]
+                    { java.awt.desktop.PreferencesHandler.class }) != null)
             {
-              @Override
-              public void handlePreferences(PreferencesEvent e)
-              {
-                preferences_actionPerformed(null);
-              }
-            });
 
-          }
+              hdesktop.setPreferencesHandler(
+                      new java.awt.desktop.PreferencesHandler()
+              {
+                        @Override
+                        public void handlePreferences(
+                                java.awt.desktop.PreferencesEvent e)
+                        {
+                          preferences_actionPerformed(null);
+                        }
+                      });
 
-          if (desktopClass.getDeclaredMethod("setQuitHandler",
-                  new Class[]
-                  { QuitHandler.class }) != null)
-          {
+            }
 
-            hdesktop.setQuitHandler(new QuitHandler()
+            if (desktopClass.getDeclaredMethod("setQuitHandler",
+                    new Class[]
+                    { java.awt.desktop.QuitHandler.class }) != null)
             {
-              @Override
-              public void handleQuitRequestWith(QuitEvent e, QuitResponse r)
+
+              hdesktop.setQuitHandler(new java.awt.desktop.QuitHandler()
               {
-                boolean confirmQuit = jalview.bin.Cache
-                        .getDefault(CONFIRM_KEYBOARD_QUIT, true);
-                int n;
-                if (confirmQuit)
+                @Override
+                public void handleQuitRequestWith(
+                        java.awt.desktop.QuitEvent e,
+                        java.awt.desktop.QuitResponse r)
                 {
-                  n = JOptionPane.showConfirmDialog(null,
-                          MessageManager.getString("label.quit_jalview"),
-                          MessageManager.getString("action.quit"),
-                          JOptionPane.OK_CANCEL_OPTION,
-                          JOptionPane.PLAIN_MESSAGE, null);
-                }
-                else
-                {
-                  n = JOptionPane.OK_OPTION;
-                }
-                if (n == JOptionPane.OK_OPTION)
-                {
-                  System.out.println("Shortcut Quit confirmed by user");
-                  quit();
-                  r.performQuit(); // probably won't reach this line, but just
-                                   // in
-                                   // case
-                }
-                else
-                {
-                  r.cancelQuit();
-                  System.out.println("Shortcut Quit cancelled by user");
+                  boolean confirmQuit = jalview.bin.Cache
+                          .getDefault(CONFIRM_KEYBOARD_QUIT, true);
+                  int n;
+                  if (confirmQuit)
+                  {
+                    n = JOptionPane.showConfirmDialog(null,
+                            MessageManager.getString("label.quit_jalview"),
+                            MessageManager.getString("action.quit"),
+                            JOptionPane.OK_CANCEL_OPTION,
+                            JOptionPane.PLAIN_MESSAGE, null);
+                  }
+                  else
+                  {
+                    n = JOptionPane.OK_OPTION;
+                  }
+                  if (n == JOptionPane.OK_OPTION)
+                  {
+                    System.out.println("Shortcut Quit confirmed by user");
+                    quit();
+                    r.performQuit(); // probably won't reach this line, but just
+                                     // in
+                                     // case
+                  }
+                  else
+                  {
+                    r.cancelQuit();
+                    System.out.println("Shortcut Quit cancelled by user");
+                  }
                 }
-              }
-            });
-            hdesktop.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
+              });
+              hdesktop.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
 
+            }
           }
         }
+        else
+        {
+          System.out.println(
+                  "Not going to try setting APQ Handlers as java.spec.version is "
+                          + specversion);
+        }
 
-      } catch (NoSuchMethodException e)
+      } catch (Exception e)
       {
         System.out.println(
-                "NoSuchMethodException when looking for About, Preferences, Quit Handlers");
+                "Exception when looking for About, Preferences, Quit Handlers");
         e.printStackTrace();
+      } catch (Throwable t)
+      {
+        System.out.println(
+                "Throwable when looking for About, Preferences, Quit Handlers");
+        t.printStackTrace();
       }
 
       setAPQHandlers = true;