JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / project / Jalview2XML.java
index ab4a3eb..5618529 100644 (file)
@@ -82,6 +82,7 @@ import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.FeatureColour;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
+import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.Format;
 import jalview.util.MessageManager;
@@ -800,9 +801,6 @@ public class Jalview2XML
           String fileName, JarOutputStream jout)
   {
 
-    // BH: Question: What is this Dataset for, as it seems to
-    // duplicate the actual XML file data.
-
     for (String dssids : dsses.keySet())
     {
       AlignFrame _af = dsses.get(dssids);
@@ -1083,7 +1081,7 @@ public class Jalview2XML
            * only view *should* be coped with sensibly.
            */
           // This must have been loaded, is it still visible?
-          JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+          JInternalFrame[] frames = Desktop.desktop.getAllFrames();
           String matchedFile = null;
           for (int f = frames.length - 1; f > -1; f--)
           {
@@ -1235,9 +1233,9 @@ public class Jalview2XML
     {
       // FIND ANY ASSOCIATED TREES
       // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
-      if (Desktop.getDesktopPane() != null)
+      if (Desktop.desktop != null)
       {
-        JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+        JInternalFrame[] frames = Desktop.desktop.getAllFrames();
 
         for (int t = 0; t < frames.length; t++)
         {
@@ -1281,9 +1279,9 @@ public class Jalview2XML
     /*
      * save PCA viewers
      */
-    if (!storeDS && Desktop.getDesktopPane() != null)
+    if (!storeDS && Desktop.desktop != null)
     {
-      for (JInternalFrame frame : Desktop.getDesktopPane().getAllFrames())
+      for (JInternalFrame frame : Desktop.desktop.getAllFrames())
       {
         if (frame instanceof PCAPanel)
         {
@@ -1674,7 +1672,7 @@ public class Jalview2XML
       // using save and then load
       try
       {
-       fileName = fileName.replace('\\', '/');
+        fileName = fileName.replace('\\', '/');
         System.out.println("Writing jar entry " + fileName);
         JarEntry entry = new JarEntry(fileName);
         jout.putNextEntry(entry);
@@ -1921,11 +1919,11 @@ public class Jalview2XML
           final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
           boolean storeDataset)
   {
-    if (Desktop.getDesktopPane() == null)
+    if (Desktop.desktop == null)
     {
       return;
     }
-    JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
     for (int f = frames.length - 1; f > -1; f--)
     {
       if (frames[f] instanceof AppVarna)
@@ -2381,7 +2379,7 @@ public class Jalview2XML
     if (calcIdParam.getVersion().equals("1.0"))
     {
       final String[] calcIds = calcIdParam.getServiceURL().toArray(new String[0]);
-      Jws2Instance service = Jws2Discoverer.getInstance()
+      Jws2Instance service = Jws2Discoverer.getDiscoverer()
               .getPreferredServiceFor(calcIds);
       if (service != null)
       {
@@ -2773,52 +2771,52 @@ public class Jalview2XML
     return af;
   }
 
-       @SuppressWarnings("unused")
-       private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
+        @SuppressWarnings("unused")
+        private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
 
-               // BH 2018 allow for bytes already attached to File object
-               try {
-                       String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
+                // BH 2018 allow for bytes already attached to File object
+                try {
+                        String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
       byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile)
               : null;
-                       URL url = null;
-                       errorMessage = null;
-                       uniqueSetSuffix = null;
-                       seqRefIds = null;
-                       viewportsAdded.clear();
-                       frefedSequence = null;
-
-                       if (file.startsWith("http://")) {
-                               url = new URL(file);
-                       }
-                       final URL _url = url;
-                       return new jarInputStreamProvider() {
-
-                               @Override
-                               public JarInputStream getJarInputStream() throws IOException {
-                                       if (bytes != null) {
-//                                             System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
-                                               return new JarInputStream(new ByteArrayInputStream(bytes));
-                                       }
-                                       if (_url != null) {
-//                                             System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
-                                               return new JarInputStream(_url.openStream());
-                                       } else {
-//                                             System.out.println("Jalview2XML: opening file jarInputStream for " + file);
-                                               return new JarInputStream(new FileInputStream(file));
-                                       }
-                               }
-
-                               @Override
-                               public String getFilename() {
-                                       return file;
-                               }
-                       };
-               } catch (IOException e) {
-                       e.printStackTrace();
-                       return null;
-               }
-       }
+                        URL url = null;
+                        errorMessage = null;
+                        uniqueSetSuffix = null;
+                        seqRefIds = null;
+                        viewportsAdded.clear();
+                        frefedSequence = null;
+
+                        if (file.startsWith("http://")) {
+                                url = new URL(file);
+                        }
+                        final URL _url = url;
+                        return new jarInputStreamProvider() {
+
+                                @Override
+                                public JarInputStream getJarInputStream() throws IOException {
+                                        if (bytes != null) {
+//                                              System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
+                                                return new JarInputStream(new ByteArrayInputStream(bytes));
+                                        }
+                                        if (_url != null) {
+//                                              System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
+                                                return new JarInputStream(_url.openStream());
+                                        } else {
+//                                              System.out.println("Jalview2XML: opening file jarInputStream for " + file);
+                                                return new JarInputStream(new FileInputStream(file));
+                                        }
+                                }
+
+                                @Override
+                                public String getFilename() {
+                                        return file;
+                                }
+                        };
+                } catch (IOException e) {
+                        e.printStackTrace();
+                        return null;
+                }
+        }
 
   /**
    * Recover jalview session from a jalview project archive. Caller may
@@ -2857,12 +2855,8 @@ public class Jalview2XML
         {
           jarentry = jin.getNextJarEntry();
         }
-        String name = (jarentry == null ? null : jarentry.getName());
-        if (name != null && name.endsWith(".xml")
-        // The question here is what to do with the two
-        // .xml files in the jvp file. They are identical?
-        // && name.indexOf(" Dataset for ") < 0 // BH 2019.05.21
-        )
+
+        if (jarentry != null && jarentry.getName().endsWith(".xml"))
         {
           JAXBContext jc = JAXBContext
                   .newInstance("jalview.xml.binding.jalview");
@@ -2921,9 +2915,9 @@ public class Jalview2XML
       {
         // used to attempt to parse as V1 castor-generated xml
       }
-      if (Desktop.getInstance() != null)
+      if (Desktop.instance != null)
       {
-        Desktop.getInstance().stopLoading();
+        Desktop.instance.stopLoading();
       }
       if (af != null)
       {
@@ -2951,7 +2945,7 @@ public class Jalview2XML
      */
     for (AlignFrame fr : gatherToThisFrame.values())
     {
-      Desktop.getInstance().gatherViews(fr);
+      Desktop.instance.gatherViews(fr);
     }
 
     restoreSplitFrames();
@@ -2959,7 +2953,8 @@ public class Jalview2XML
     {
       if (ds.getCodonFrames() != null)
       {
-        Desktop.getInstance().getStructureSelectionManager()
+        StructureSelectionManager
+                .getStructureSelectionManager(Desktop.instance)
                 .registerMappings(ds.getCodonFrames());
       }
     }
@@ -2968,9 +2963,9 @@ public class Jalview2XML
       reportErrors();
     }
 
-    if (Desktop.getInstance() != null)
+    if (Desktop.instance != null)
     {
-      Desktop.getInstance().stopLoading();
+      Desktop.instance.stopLoading();
     }
 
     return af;
@@ -3051,7 +3046,7 @@ public class Jalview2XML
      */
     for (SplitFrame sf : gatherTo)
     {
-      Desktop.getInstance().gatherViews(sf);
+      Desktop.instance.gatherViews(sf);
     }
 
     splitFrameCandidates.clear();
@@ -3110,7 +3105,7 @@ public class Jalview2XML
           @Override
           public void run()
           {
-            JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+            JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                     finalErrorMessage,
                     "Error " + (saving ? "saving" : "loading")
                             + " Jalview file",
@@ -3580,7 +3575,8 @@ public class Jalview2XML
             {
               entry.setProperty(prop.getName(), prop.getValue());
             }
-            Desktop.getInstance().getStructureSelectionManager()
+            StructureSelectionManager
+                    .getStructureSelectionManager(Desktop.instance)
                     .registerPDBEntry(entry);
             // adds PDBEntry to datasequence's set (since Jalview 2.10)
             if (al.getSequenceAt(i).getDatasetSequence() != null)
@@ -4298,7 +4294,7 @@ public class Jalview2XML
             int height = safeInt(structureState.getHeight());
 
             // Probably don't need to do this anymore...
-            // Desktop.getDesktop().getComponentAt(x, y);
+            // Desktop.desktop.getComponentAt(x, y);
             // TODO: NOW: check that this recovers the PDB file correctly.
             String pdbFile = loadPDBFile(jprovider, pdbid.getId(),
                     pdbid.getFile());
@@ -4540,7 +4536,7 @@ public class Jalview2XML
           String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
           filedat = oldFiles.get(new File(reformatedOldFilename));
         }
-        newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
+        newFileLoc.append(Platform.escapeBackslashes(filedat.getFilePath()));
         pdbfilenames.add(filedat.getFilePath());
         pdbids.add(filedat.getPdbId());
         seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
@@ -4782,7 +4778,7 @@ public class Jalview2XML
     {
       try
       {
-        frames = Desktop.getDesktopPane().getAllFrames();
+        frames = Desktop.desktop.getAllFrames();
       } catch (ArrayIndexOutOfBoundsException e)
       {
         // occasional No such child exceptions are thrown here...
@@ -4861,14 +4857,14 @@ public class Jalview2XML
     af = new AlignFrame(al, safeInt(view.getWidth()),
             safeInt(view.getHeight()), uniqueSeqSetId, viewId) 
 //    {
-//     
-//     @Override
-//     protected void processKeyEvent(java.awt.event.KeyEvent e) {
-//             System.out.println("Jalview2XML   AF " + e);
-//             super.processKeyEvent(e);
-//             
-//     }
-//     
+//      
+//      @Override
+//      protected void processKeyEvent(java.awt.event.KeyEvent e) {
+//              System.out.println("Jalview2XML   AF " + e);
+//              super.processKeyEvent(e);
+//              
+//      }
+//      
 //    }
     ;
 
@@ -4980,18 +4976,8 @@ public class Jalview2XML
       viewport.setViewName(view.getViewName());
       af.setInitialTabVisible();
     }
-    int x = safeInt(view.getXpos());
-    int y = safeInt(view.getYpos());
-    int w = safeInt(view.getWidth());
-    int h = safeInt(view.getHeight());
-    // // BH we cannot let the title bar go off the top
-    // if (Platform.isJS())
-    // {
-    // x = Math.max(50 - w, x);
-    // y = Math.max(0, y);
-    // }
-
-    af.setBounds(x, y, w, h);
+    af.setBounds(safeInt(view.getXpos()), safeInt(view.getYpos()),
+            safeInt(view.getWidth()), safeInt(view.getHeight()));
     // startSeq set in af.alignPanel.updateLayout below
     af.alignPanel.updateLayout();
     ColourSchemeI cs = null;
@@ -5154,7 +5140,7 @@ public class Jalview2XML
         }
         else
         {
-          featureOrder.put(featureType, new Float(
+          featureOrder.put(featureType, Float.valueOf(
                   fs / jm.getFeatureSettings().getSetting().size()));
         }
         if (safeBoolean(setting.isDisplay()))
@@ -5166,7 +5152,7 @@ public class Jalview2XML
       for (int gs = 0; gs < jm.getFeatureSettings().getGroup().size(); gs++)
       {
         Group grp = jm.getFeatureSettings().getGroup().get(gs);
-        fgtable.put(grp.getName(), new Boolean(grp.isDisplay()));
+        fgtable.put(grp.getName(), Boolean.valueOf(grp.isDisplay()));
       }
       // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder,
       // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ?