still trying to prevent null painting
[jalview.git] / src / jalview / appletgui / AppletJmol.java
index 375fe4d..14e6704 100644 (file)
@@ -30,7 +30,6 @@ import jalview.io.*;
 import org.jmol.api.*;
 import org.jmol.adapter.smarter.SmarterJmolAdapter;
 
-
 import org.jmol.popup.*;
 import jalview.schemes.*;
 
@@ -68,6 +67,7 @@ public class AppletJmol extends Frame
   TextField inputLine;
   TextArea history;
   SequenceI[] sequence;
+  String [] chains;
   StructureSelectionManager ssm;
   RenderPanel renderPanel;
   AlignmentPanel ap;
@@ -79,11 +79,13 @@ public class AppletJmol extends Frame
 
   public AppletJmol(PDBEntry pdbentry,
                     SequenceI[] seq,
+                    String[] chains,
                     AlignmentPanel ap,
                     String protocol)
   {
     this.ap = ap;
     this.sequence = seq;
+    this.chains = chains;
     this.pdbentry = pdbentry;
 
    String alreadyMapped = StructureSelectionManager
@@ -93,14 +95,14 @@ public class AppletJmol extends Frame
     if (alreadyMapped != null)
     {
        StructureSelectionManager.getStructureSelectionManager()
-            .setMapping(seq, pdbentry.getFile(), protocol);
-        return;
+            .setMapping(seq, chains, pdbentry.getFile(), protocol);
+       //PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW?
+       //FOR NOW, LETS JUST OPEN A NEW WINDOW
     }
 
     renderPanel = new RenderPanel();
 
     this.add(renderPanel, BorderLayout.CENTER);
-
     viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter());
 
     viewer.setAppletContext("jalview",
@@ -167,9 +169,7 @@ public class AppletJmol extends Frame
           viewer.openFile(pdbentry.getFile());
     }
 
-    this.setBounds(400, 400, 400, 400);
-
-    this.setVisible(true);
+    jalview.bin.JalviewLite.addFrame(this, "Jmol", 400,400);
   }
 
   public void loadInline(String string)
@@ -441,14 +441,15 @@ public class AppletJmol extends Frame
       resetLastRes.append(":" + chain);
     }
 
-    eval.append(";color gold;wireframe 100");
+    eval.append(";wireframe 100");//;color gold
 
     Color col = new Color(viewer.getAtomArgb(atomIndex));
 
-    resetLastRes.append(";color["
-                        + col.getRed() + ","
-                        + col.getGreen() + ","
-                        + col.getBlue() + "];wireframe 0");
+    resetLastRes.append(";wireframe 0;"//color["
+                       // + col.getRed() + ","
+                       // + col.getGreen() + ","
+                       // + col.getBlue() + "]"
+                       );
 
     viewer.evalStringQuiet(eval.toString());
 
@@ -462,7 +463,16 @@ public class AppletJmol extends Frame
 //End StructureListener
 ////////////////////////////
 
+  public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile)
+  {
+    if (!pdbfile.equals(pdbentry.getFile()))
+      return null;
+
+    return new Color(viewer.getAtomArgb(atomIndex));
+  }
+
   FeatureRenderer fr;
+  String lastCommand;
   public void colourBySequence(AlignmentPanel ap)
   {
     if(!colourBySequence)
@@ -474,7 +484,7 @@ public class AppletJmol extends Frame
     if (mapping.length < 1)
       return;
 
-    SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();
+    SequenceRenderer sr = new SequenceRenderer(ap.av);
 
     boolean showFeatures = false;
     if (ap.av.showSequenceFeatures)
@@ -495,7 +505,8 @@ public class AppletJmol extends Frame
     {
       for (int m = 0; m < mapping.length; m++)
       {
-        if (mapping[m].getSequence() == sequence[s])
+        if (mapping[m].getSequence() == sequence[s]
+            && ap.av.alignment.findIndex(sequence[s])>-1)
         {
           for (int r = 0; r < sequence[s].getLength(); r++)
           {
@@ -540,7 +551,10 @@ public class AppletJmol extends Frame
       }
     }
 
-    viewer.evalStringQuiet(command.toString());
+    if (lastCommand == null || !lastCommand.equals(command.toString()))
+      viewer.evalStringQuiet(command.toString());
+
+    lastCommand = command.toString();
   }
 
   StringBuffer condenseCommand(String command, int pos)
@@ -608,14 +622,14 @@ public class AppletJmol extends Frame
       MCview.PDBfile pdb;
       if (loadedInline)
       {
-        pdb = ssm.setMapping(sequence,
+        pdb = ssm.setMapping(sequence,chains,
                                 pdbentry.getFile(),
                                 AppletFormatAdapter.PASTE);
         pdbentry.setFile("INLINE"+pdb.id);
       }
       else
       {
-         pdb = ssm.setMapping(sequence,
+         pdb = ssm.setMapping(sequence,chains,
                               pdbentry.getFile(),
                               AppletFormatAdapter.URL);
       }