JAL-1759 changed to non-deprecated Viewer.renderScreenImage()
[jalview.git] / src / jalview / gui / AppJmol.java
index 55288d0..f05a7d4 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -26,6 +26,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -147,9 +148,9 @@ public class AppJmol extends StructureViewerBase
     PDBEntry[] pdbentrys = new PDBEntry[files.length];
     for (int i = 0; i < pdbentrys.length; i++)
     {
-      PDBEntry pdbentry = new PDBEntry();
-      pdbentry.setFile(files[i]);
-      pdbentry.setId(ids[i]);
+      // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
+      PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
+              files[i]);
       pdbentrys[i] = pdbentry;
     }
     // / TODO: check if protocol is needed to be set, and if chains are
@@ -169,7 +170,7 @@ public class AppJmol extends StructureViewerBase
       seqColour.setSelected(false);
       viewerColour.setSelected(true);
     }
-    if (usetoColour)
+    else if (usetoColour)
     {
       useAlignmentPanelForColourbyseq(ap);
       jmb.setColourBySequence(true);
@@ -184,9 +185,10 @@ public class AppJmol extends StructureViewerBase
 
     this.addInternalFrameListener(new InternalFrameAdapter()
     {
+      @Override
       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
       {
-        closeViewer();
+        closeViewer(false);
       }
     });
     initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
@@ -406,9 +408,10 @@ public class AppJmol extends StructureViewerBase
     }
     this.addInternalFrameListener(new InternalFrameAdapter()
     {
+      @Override
       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
       {
-        closeViewer();
+        closeViewer(false);
       }
     });
 
@@ -427,118 +430,6 @@ public class AppJmol extends StructureViewerBase
     openNewJmol(ap, pe, seqs);
   }
 
-  public AlignmentPanel[] getAllAlignmentPanels()
-  {
-    AlignmentPanel[] t;
-    AlignmentPanel[] list = new AlignmentPanel[0];
-    for (String setid : _aps)
-    {
-      AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
-      if (panels != null)
-      {
-        t = new AlignmentPanel[list.length + panels.length];
-        System.arraycopy(list, 0, t, 0, list.length);
-        System.arraycopy(panels, 0, t, list.length, panels.length);
-        list = t;
-      }
-    }
-
-    return list;
-  }
-
-  /**
-   * set the primary alignmentPanel reference and add another alignPanel to the
-   * list of ones to use for colouring and aligning
-   * 
-   * @param nap
-   */
-  public void addAlignmentPanel(AlignmentPanel nap)
-  {
-    if (getAlignmentPanel() == null)
-    {
-      setAlignmentPanel(nap);
-    }
-    if (!_aps.contains(nap.av.getSequenceSetId()))
-    {
-      _aps.add(nap.av.getSequenceSetId());
-    }
-  }
-
-  /**
-   * remove any references held to the given alignment panel
-   * 
-   * @param nap
-   */
-  public void removeAlignmentPanel(AlignmentPanel nap)
-  {
-    try
-    {
-      _alignwith.remove(nap);
-      _colourwith.remove(nap);
-      if (getAlignmentPanel() == nap)
-      {
-        setAlignmentPanel(null);
-        for (AlignmentPanel aps : getAllAlignmentPanels())
-        {
-          if (aps != nap)
-          {
-            setAlignmentPanel(aps);
-            break;
-          }
-        }
-      }
-    } catch (Exception ex)
-    {
-    }
-    if (getAlignmentPanel() != null)
-    {
-      buildActionMenu();
-    }
-  }
-
-  public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
-  {
-    addAlignmentPanel(nap);
-    if (!_alignwith.contains(nap))
-    {
-      _alignwith.add(nap);
-    }
-  }
-
-  public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
-  {
-    if (_alignwith.contains(nap))
-    {
-      _alignwith.remove(nap);
-    }
-  }
-
-  public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
-          boolean enableColourBySeq)
-  {
-    useAlignmentPanelForColourbyseq(nap);
-    getBinding().setColourBySequence(enableColourBySeq);
-    seqColour.setSelected(enableColourBySeq);
-    viewerColour.setSelected(!enableColourBySeq);
-  }
-
-  public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
-  {
-    addAlignmentPanel(nap);
-    if (!_colourwith.contains(nap))
-    {
-      _colourwith.add(nap);
-    }
-  }
-
-  public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
-  {
-    if (_colourwith.contains(nap))
-    {
-      _colourwith.remove(nap);
-    }
-  }
-
   /**
    * pdb retrieval thread.
    */
@@ -638,7 +529,7 @@ public class AppJmol extends StructureViewerBase
     ;
     jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
             null);
-    jmb.newJmolPopup(true, "Jmol", true);
+    jmb.newJmolPopup("Jmol");
     if (command == null)
     {
       command = "";
@@ -716,8 +607,9 @@ public class AppJmol extends StructureViewerBase
     jmb.centerViewer(toshow);
   }
 
-  public void closeViewer()
+  public void closeViewer(boolean closeExternalViewer)
   {
+    // JMol does not use an external viewer
     jmb.closeViewer();
     setAlignmentPanel(null);
     _aps.clear();
@@ -760,9 +652,7 @@ public class AppJmol extends StructureViewerBase
           }
           try
           {
-            pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.getPdbEntry(
-                    pi)
-                    .getId());
+            pdbseq = pdbclient.getSequenceRecords(pdbid);
           } catch (OutOfMemoryError oomerror)
           {
             new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
@@ -779,8 +669,8 @@ public class AppJmol extends StructureViewerBase
           {
             // just transfer the file name from the first sequence's first
             // PDBEntry
-            file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
-                    .elementAt(0)).getFile()).getAbsolutePath();
+            file = new File(pdbseq.getSequenceAt(0).getPDBId()
+                    .elementAt(0).getFile()).getAbsolutePath();
             jmb.getPdbEntry(pi).setFile(file);
 
             files.append(" \"" + Platform.escapeString(file) + "\"");
@@ -955,11 +845,7 @@ public class AppJmol extends StructureViewerBase
     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
     try
     {
-      for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
-      {
-        cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
-        cap.appendText("\n");
-      }
+      cap.appendText(jmb.printMappings());
     } catch (OutOfMemoryError e)
     {
       new OOMWarning(
@@ -1015,8 +901,7 @@ public class AppJmol extends StructureViewerBase
 
     if (im.getGraphics() != null)
     {
-      Rectangle rect = new Rectangle(width, height);
-      jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
+      jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
       im.writeImage();
     }
   }
@@ -1052,7 +937,7 @@ public class AppJmol extends StructureViewerBase
       // Set the colour using the current view for the associated alignframe
       for (AlignmentPanel ap : _colourwith)
       {
-        jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
+        jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
       }
     }
   }
@@ -1193,14 +1078,12 @@ public class AppJmol extends StructureViewerBase
   {
     final Dimension currentSize = new Dimension();
 
-    final Rectangle rectClip = new Rectangle();
-
+    @Override
     public void paintComponent(Graphics g)
     {
       getSize(currentSize);
-      g.getClipBounds(rectClip);
 
-      if (jmb.fileLoadingError != null)
+      if (jmb != null && jmb.fileLoadingError != null)
       {
         g.setColor(Color.black);
         g.fillRect(0, 0, currentSize.width, currentSize.height);
@@ -1237,7 +1120,8 @@ public class AppJmol extends StructureViewerBase
       }
       else
       {
-        jmb.viewer.renderScreenImage(g, currentSize, rectClip);
+        jmb.viewer.renderScreenImage(g, currentSize.width,
+                currentSize.height);
       }
     }
   }
@@ -1351,4 +1235,10 @@ public class AppJmol extends StructureViewerBase
     return jmb == null ? null : jmb.viewer.getStateInfo();
   }
 
+  @Override
+  public ViewerType getViewerType()
+  {
+    return ViewerType.JMOL;
+  }
+
 }