JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / jalview / gui / PymolViewer.java
index 8dd2fc0..665b137 100644 (file)
@@ -14,7 +14,7 @@ import javax.swing.event.InternalFrameEvent;
 
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;
-import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.StructureViewerModel;
@@ -50,9 +50,7 @@ public class PymolViewer extends StructureViewerBase
           AlignmentPanel ap)
   {
     this();
-    openNewPymol(ap, new PDBEntry[] { pdb },
-            new SequenceI[][]
-            { seqs });
+    openNewPymol(ap, new PDBEntry[] { pdb }, new SequenceI[][] { seqs });
   }
 
   public PymolViewer(PDBEntry[] pe, boolean alignAdded, SequenceI[][] seqs,
@@ -161,11 +159,12 @@ public class PymolViewer extends StructureViewerBase
   public void run()
   {
     // todo pull up much of this
-  
+
     StringBuilder errormsgs = new StringBuilder(128);
     List<PDBEntry> filePDB = new ArrayList<>();
     List<Integer> filePDBpos = new ArrayList<>();
-    String[] curfiles = binding.getStructureFiles(); // files currently in viewer
+    String[] curfiles = binding.getStructureFiles(); // files currently in
+                                                     // viewer
     for (int pi = 0; pi < binding.getPdbCount(); pi++)
     {
       String file = null;
@@ -186,8 +185,7 @@ public class PymolViewer extends StructureViewerBase
         /*
          * got file already
          */
-        file = new File(thePdbEntry.getFile()).getAbsoluteFile()
-                .getPath();
+        file = new File(thePdbEntry.getFile()).getAbsoluteFile().getPath();
         // todo - skip if already loaded in PyMOL
       }
       if (file != null)
@@ -196,7 +194,7 @@ public class PymolViewer extends StructureViewerBase
         filePDBpos.add(Integer.valueOf(pi));
       }
     }
-        
+
     if (!filePDB.isEmpty())
     {
       /*
@@ -210,9 +208,19 @@ public class PymolViewer extends StructureViewerBase
           initPymol();
         } catch (Exception ex)
         {
-          Cache.log.error("Couldn't open PyMOL viewer!", ex);
+          Console.error("Couldn't open PyMOL viewer!", ex);
+          // if we couldn't open Pymol, no point continuing
+          return;
         }
       }
+      if (!binding.isViewerRunning())
+      {
+        // nothing to do
+        // TODO: ensure we tidy up JAL-3619
+
+        return;
+      }
+
       int num = -1;
       for (PDBEntry pe : filePDB)
       {
@@ -244,17 +252,15 @@ public class PymolViewer extends StructureViewerBase
 
             StructureFile pdb = binding.getSsm().setMapping(
                     binding.getSequence()[pos], binding.getChains()[pos],
-                    pe.getFile(), protocol,
-                    getProgressIndicator());
+                    pe.getFile(), protocol, getProgressIndicator());
             binding.stashFoundChains(pdb, pe.getFile());
           } catch (Exception ex)
           {
-            Cache.log.error(
-                    "Couldn't open " + pe.getFile() + " in Chimera viewer!",
-                    ex);
+            Console.error("Couldn't open " + pe.getFile() + " in "
+                    + getViewerName() + "!", ex);
           } finally
           {
-            // Cache.log.debug("File locations are " + files);
+            // Cache.debug("File locations are " + files);
           }
         }
       }
@@ -314,6 +320,7 @@ public class PymolViewer extends StructureViewerBase
                       getViewerName()),
               MessageManager.getString("label.error_loading_file"),
               JvOptionPane.ERROR_MESSAGE);
+      binding.closeViewer(true);
       this.dispose();
       return;
     }
@@ -323,8 +330,7 @@ public class PymolViewer extends StructureViewerBase
       boolean opened = binding.openSession(pymolSessionFile);
       if (!opened)
       {
-        Cache.log.error(
-                "An error occurred opening PyMOL session file "
+        Console.error("An error occurred opening PyMOL session file "
                 + pymolSessionFile);
       }
     }
@@ -348,7 +354,9 @@ public class PymolViewer extends StructureViewerBase
   {
     return "PyMOL";
   }
+
   JMenuItem writeFeatures = null;
+
   @Override
   protected void initMenus()
   {
@@ -359,8 +367,8 @@ public class PymolViewer extends StructureViewerBase
 
     writeFeatures = new JMenuItem(
             MessageManager.getString("label.create_viewer_attributes"));
-    writeFeatures.setToolTipText(MessageManager
-            .getString("label.create_viewer_attributes_tip"));
+    writeFeatures.setToolTipText(
+            MessageManager.getString("label.create_viewer_attributes_tip"));
     writeFeatures.addActionListener(new ActionListener()
     {
       @Override
@@ -371,7 +379,7 @@ public class PymolViewer extends StructureViewerBase
     });
     viewerActionMenu.add(writeFeatures);
   }
-  
+
   @Override
   protected void buildActionMenu()
   {
@@ -382,8 +390,8 @@ public class PymolViewer extends StructureViewerBase
   protected void sendFeaturesToPymol()
   {
     int count = binding.sendFeaturesToViewer(getAlignmentPanel());
-    statusBar.setText(
-            MessageManager.formatMessage("label.attributes_set", count));
+    statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+            count, getViewerName()));
   }
 
 }