JAL-2360 structure viewers now using ColourMenuHelper, obsolete methods
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Dec 2016 13:12:33 +0000 (13:12 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Dec 2016 13:12:33 +0000 (13:12 +0000)
and fields removed, more methods pulled up

22 files changed:
src/jalview/appletgui/AppletJmol.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AppJmol.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/gui/ColourMenuHelper.java
src/jalview/gui/JalviewChimeraBindingModel.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/StructureViewerBase.java
src/jalview/jbgui/GStructureViewer.java
src/jalview/schemes/AnnotationColourGradient.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/schemes/ClustalxColourScheme.java
src/jalview/schemes/ColourSchemeI.java
src/jalview/schemes/CovariationColourScheme.java
src/jalview/schemes/PIDColourScheme.java
src/jalview/schemes/RNAHelicesColour.java
src/jalview/schemes/ResidueColourScheme.java
src/jalview/schemes/TCoffeeColourScheme.java
src/jalview/structures/models/AAStructureBindingModel.java
test/jalview/structures/models/AAStructureBindingModelTest.java

index 8196c2b..c0b4ff0 100644 (file)
@@ -586,7 +586,7 @@ public class AppletJmol extends EmbmenuFrame implements
 
   public void updateTitleAndMenus()
   {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
+    if (jmb.hasFileLoadingError())
     {
       repaint();
       return;
index 38ce476..b4586ca 100644 (file)
@@ -20,7 +20,6 @@
  */
 package jalview.ext.jmol;
 
-import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;
@@ -76,8 +75,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   Hashtable<String, String> chainFile;
 
-  public String fileLoadingError;
-
   /*
    * the default or current model displayed if the model cannot be identified
    * from the selection message
@@ -241,6 +238,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @param _hiddenCols
    *          an array of corresponding hidden columns for each alignment
    */
+  @Override
   public void superposeStructures(AlignmentI[] _alignment,
           int[] _refStructure, ColumnSelection[] _hiddenCols)
   {
@@ -487,35 +485,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   /**
-   * colour any structures associated with sequences in the given alignment
-   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
-   * if colourBySequence is enabled.
+   * Sends a set of colour commands to the structure viewer
+   * 
+   * @param colourBySequenceCommands
    */
-  public void colourBySequence(AlignmentViewPanel alignmentv)
+  @Override
+  protected void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands)
   {
-    boolean showFeatures = alignmentv.getAlignViewport()
-            .isShowSequenceFeatures();
-    if (!colourBySequence || !isLoadingFinished())
-    {
-      return;
-    }
-    if (getSsm() == null)
-    {
-      return;
-    }
-    String[] files = getPdbFile();
-
-    SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
-    FeatureRenderer fr = null;
-    if (showFeatures)
-    {
-      fr = getFeatureRenderer(alignmentv);
-    }
-    AlignmentI alignment = alignmentv.getAlignment();
-
-    for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
-            files, sr, fr, alignment))
+    for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
     {
       for (String cbyseq : cpdbbyseq.commands)
       {
@@ -531,6 +509,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @param alignment
    * @return
    */
+  @Override
   protected StructureMappingcommandSet[] getColourBySequenceCommands(
           String[] files, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
@@ -598,17 +577,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   /**
-   * returns the current featureRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract FeatureRenderer getFeatureRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * instruct the Jalview binding to update the pdbentries vector if necessary
    * prior to matching the jmol view's contents to the list of structure files
    * Jalview knows about.
@@ -717,16 +685,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     return null;
   }
 
-  /**
-   * returns the current sequenceRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract SequenceRenderer getSequenceRenderer(
-          AlignmentViewPanel alignment);
+  
 
   // ///////////////////////////////
   // JmolStatusListener
@@ -1286,6 +1245,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   }
 
+  @Override
   public void setJalviewColourScheme(ColourSchemeI cs)
   {
     colourBySequence = false;
@@ -1402,6 +1362,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   protected org.jmol.api.JmolAppConsoleInterface console = null;
 
+  @Override
   public void setBackgroundColour(java.awt.Color col)
   {
     jmolHistory(false);
index 8354410..2171815 100644 (file)
@@ -93,8 +93,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   private boolean loadingFinished = true;
 
-  public String fileLoadingError;
-
   /*
    * Map of ChimeraModel objects keyed by PDB full local file name
    */
@@ -254,18 +252,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Construct a title string for the viewer window based on the data Jalview
-   * knows about
-   * 
-   * @param verbose
-   * @return
-   */
-  public String getViewerTitle(boolean verbose)
-  {
-    return getViewerTitle("Chimera", verbose);
-  }
-
-  /**
    * Tells Chimera to display only the specified chains
    * 
    * @param toshow
@@ -328,6 +314,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     releaseUIResources();
   }
 
+  @Override
   public void colourByChain()
   {
     colourBySequence = false;
@@ -343,6 +330,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * <li>all others - white</li>
    * </ul>
    */
+  @Override
   public void colourByCharge()
   {
     colourBySequence = false;
@@ -364,6 +352,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * @param _hiddenCols
    *          an array of corresponding hidden columns for each alignment
    */
+  @Override
   public void superposeStructures(AlignmentI[] _alignment,
           int[] _refStructure, ColumnSelection[] _hiddenCols)
   {
@@ -680,34 +669,15 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
           String progressMsg);
 
   /**
-   * colour any structures associated with sequences in the given alignment
-   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
-   * if colourBySequence is enabled.
+   * Sends a set of colour commands to the structure viewer
+   * 
+   * @param colourBySequenceCommands
    */
-  public void colourBySequence(boolean showFeatures,
-          jalview.api.AlignmentViewPanel alignmentv)
+  @Override
+  protected void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands)
   {
-    if (!colourBySequence || !loadingFinished)
-    {
-      return;
-    }
-    if (getSsm() == null)
-    {
-      return;
-    }
-    String[] files = getPdbFile();
-
-    SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
-    FeatureRenderer fr = null;
-    if (showFeatures)
-    {
-      fr = getFeatureRenderer(alignmentv);
-    }
-    AlignmentI alignment = alignmentv.getAlignment();
-
-    for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
-            files, sr, fr, alignment))
+    for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
     {
       for (String command : cpdbbyseq.commands)
       {
@@ -723,6 +693,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * @param alignment
    * @return
    */
+  @Override
   protected StructureMappingcommandSet[] getColourBySequenceCommands(
           String[] files, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
@@ -758,40 +729,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   // //////////////////////////
 
   /**
-   * returns the current featureRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract FeatureRenderer getFeatureRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * instruct the Jalview binding to update the pdbentries vector if necessary
    * prior to matching the viewer's contents to the list of structure files
    * Jalview knows about.
    */
   public abstract void refreshPdbEntries();
 
-  private int getModelNum(String modelFileName)
-  {
-    String[] mfn = getPdbFile();
-    if (mfn == null)
-    {
-      return -1;
-    }
-    for (int i = 0; i < mfn.length; i++)
-    {
-      if (mfn[i].equalsIgnoreCase(modelFileName))
-      {
-        return i;
-      }
-    }
-    return -1;
-  }
-
   /**
    * map between index of model filename returned from getPdbFile and the first
    * index of models from this file in the viewer. Note - this is not trimmed -
@@ -814,17 +757,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * returns the current sequenceRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract SequenceRenderer getSequenceRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * Construct and send a command to highlight zero, one or more atoms. We do
    * this by sending an "rlabel" command to show the residue label at that
    * position.
@@ -976,6 +908,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     return loadNotifiesHandled;
   }
 
+  @Override
   public void setJalviewColourScheme(ColourSchemeI cs)
   {
     colourBySequence = false;
@@ -1050,6 +983,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    *      .html
    * @param col
    */
+  @Override
   public void setBackgroundColour(Color col)
   {
     viewerCommandHistory(false);
index 29a160c..3c0569e 100644 (file)
@@ -5689,8 +5689,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     colourMenu.add(textColour);
     colourMenu.addSeparator();
 
-    ColourMenuHelper
-            .addMenuItems(colourMenu, this, viewport.getAlignment());
+    ColourMenuHelper.addMenuItems(colourMenu, this,
+            viewport.getAlignment(), false);
 
     colourMenu.addSeparator();
     colourMenu.add(conservationMenuItem);
index aaa2397..ffb9639 100644 (file)
 package jalview.gui;
 
 import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
@@ -51,20 +38,12 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JMenu;
 import javax.swing.JPanel;
@@ -72,8 +51,6 @@ import javax.swing.JSplitPane;
 import javax.swing.SwingUtilities;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
 
 public class AppJmol extends StructureViewerBase
 {
@@ -92,8 +69,6 @@ public class AppJmol extends StructureViewerBase
 
   RenderPanel renderPanel;
 
-  ViewSelectionMenu seqColourBy;
-
   /**
    * 
    * @param files
@@ -137,6 +112,7 @@ public class AppJmol extends StructureViewerBase
     {
       useAlignmentPanelForSuperposition(ap);
     }
+    initMenus();
     if (leaveColouringToJmol || !usetoColour)
     {
       jmb.setColourBySequence(false);
@@ -151,7 +127,6 @@ public class AppJmol extends StructureViewerBase
       viewerColour.setSelected(false);
     }
     this.setBounds(bounds);
-    initMenus();
     setViewId(viewid);
     // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
     // bounds.width,bounds.height);
@@ -165,84 +140,19 @@ public class AppJmol extends StructureViewerBase
       }
     });
     initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
-
   }
 
-  private void initMenus()
+  @Override
+  protected void initMenus()
   {
-    seqColour.setSelected(jmb.isColourBySequence());
-    viewerColour.setSelected(!jmb.isColourBySequence());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-
-    seqColourBy = new ViewSelectionMenu(
-            MessageManager.getString("label.colour_by"), this, _colourwith,
-            new ItemListener()
-            {
-
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                if (!seqColour.isSelected())
-                {
-                  seqColour.doClick();
-                }
-                else
-                {
-                  // update the jmol display now.
-                  seqColour_actionPerformed(null);
-                }
-              }
-            });
-    viewMenu.add(seqColourBy);
-    final ItemListener handler;
-    JMenu alpanels = new ViewSelectionMenu(
-            MessageManager.getString("label.superpose_with"), this,
-            _alignwith, handler = new ItemListener()
-            {
+    super.initMenus();
 
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                alignStructs.setEnabled(_alignwith.size() > 0);
-                alignStructs.setToolTipText(MessageManager
-                        .formatMessage(
-                                "label.align_structures_using_linked_alignment_views",
-                                new String[] { new Integer(_alignwith
-                                        .size()).toString() }));
-              }
-            });
-    handler.itemStateChanged(null);
-    viewerActionMenu.add(alpanels);
-    viewerActionMenu.addMenuListener(new MenuListener()
-    {
+    viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
 
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        handler.itemStateChanged(null);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-    });
+    viewerColour
+            .setText(MessageManager.getString("label.colour_with_jmol"));
+    viewerColour.setToolTipText(MessageManager
+            .getString("label.let_jmol_manage_structure_colours"));
   }
 
   IProgressIndicator progressBar = null;
@@ -285,15 +195,6 @@ public class AppJmol extends StructureViewerBase
     openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
   }
 
-  /**
-   * Answers true if this viewer already involves the given PDB ID
-   */
-  @Override
-  protected boolean hasPdbId(String pdbId)
-  {
-    return jmb.hasPdbId(pdbId);
-  }
-
   private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
           SequenceI[][] seqs)
   {
@@ -302,6 +203,7 @@ public class AppJmol extends StructureViewerBase
             pdbentrys, seqs, null);
     addAlignmentPanel(ap);
     useAlignmentPanelForColourbyseq(ap);
+
     if (pdbentrys.length > 1)
     {
       alignAddedStructures = true;
@@ -685,76 +587,6 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  public void pdbFile_actionPerformed(ActionEvent actionEvent)
-  {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
-    chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      BufferedReader in = null;
-      try
-      {
-        // TODO: cope with multiple PDB files in view
-        in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
-        File outFile = chooser.getSelectedFile();
-
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
-        String data;
-        while ((data = in.readLine()) != null)
-        {
-          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
-          {
-            out.println(data);
-          }
-        }
-        out.close();
-      } catch (Exception ex)
-      {
-        ex.printStackTrace();
-      } finally
-      {
-        if (in != null)
-        {
-          try
-          {
-            in.close();
-          } catch (IOException e)
-          {
-            // ignore
-          }
-        }
-      }
-    }
-  }
-
-  @Override
-  public void viewMapping_actionPerformed(ActionEvent actionEvent)
-  {
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
-    try
-    {
-      cap.appendText(jmb.printMappings());
-    } catch (OutOfMemoryError e)
-    {
-      new OOMWarning(
-              "composing sequence-structure alignments for display in text box.",
-              e);
-      cap.dispose();
-      return;
-    }
-    jalview.gui.Desktop.addInternalFrame(cap,
-            MessageManager.getString("label.pdb_sequence_mapping"), 550,
-            600);
-  }
-
-  @Override
   public void eps_actionPerformed(ActionEvent e)
   {
     makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
@@ -801,148 +633,11 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  public void viewerColour_actionPerformed(ActionEvent actionEvent)
-  {
-    if (viewerColour.isSelected())
-    {
-      // disable automatic sequence colouring.
-      jmb.setColourBySequence(false);
-    }
-  }
-
-  @Override
-  public void seqColour_actionPerformed(ActionEvent actionEvent)
-  {
-    jmb.setColourBySequence(seqColour.isSelected());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (jmb.isColourBySequence())
-    {
-      if (!jmb.isLoadingFromArchive())
-      {
-        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
-        {
-          // Make the currently displayed alignment panel the associated view
-          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
-        }
-      }
-      // Set the colour using the current view for the associated alignframe
-      for (AlignmentPanel ap : _colourwith)
-      {
-        jmb.colourBySequence(ap);
-      }
-    }
-  }
-
-  @Override
-  public void chainColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chainColour.setSelected(true);
-    jmb.colourByChain();
-  }
-
-  @Override
-  public void chargeColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chargeColour.setSelected(true);
-    jmb.colourByCharge();
-  }
-
-  @Override
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-    zappoColour.setSelected(true);
-    jmb.setJalviewColourScheme(new ZappoColourScheme());
-  }
-
-  @Override
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-    taylorColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TaylorColourScheme());
-  }
-
-  @Override
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-    hydroColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HydrophobicColourScheme());
-  }
-
-  @Override
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-    helixColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HelixColourScheme());
-  }
-
-  @Override
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-    strandColour.setSelected(true);
-    jmb.setJalviewColourScheme(new StrandColourScheme());
-  }
-
-  @Override
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-    turnColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TurnColourScheme());
-  }
-
-  @Override
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-    buriedColour.setSelected(true);
-    jmb.setJalviewColourScheme(new BuriedColourScheme());
-  }
-
-  @Override
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-    setJalviewColourScheme(new PurinePyrimidineColourScheme());
-  }
-
-  /**
-   * Action on either selecting a user-defined colour, or 'User Defined...'
-   */
-  @Override
-  public void userColour_actionPerformed(ActionEvent e)
-  {
-    if (e.getActionCommand().equals(
-            MessageManager.getString("action.user_defined")))
-    {
-      userColour.setSelected(true);
-      new UserDefinedColours(this, null);
-    }
-    else
-    {
-      UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get(
-              e.getActionCommand());
-      jmb.setJalviewColourScheme(udc);
-    }
-  }
-
-  @Override
-  public void backGround_actionPerformed(ActionEvent actionEvent)
-  {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_background_colour"),
-            null);
-    if (col != null)
-    {
-      jmb.setBackgroundColour(col);
-    }
-  }
-
-  @Override
   public void showHelp_actionPerformed(ActionEvent actionEvent)
   {
     try
     {
-      jalview.util.BrowserLauncher
+      BrowserLauncher
               .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
     } catch (Exception ex)
     {
@@ -991,7 +686,7 @@ public class AppJmol extends StructureViewerBase
     {
       getSize(currentSize);
 
-      if (jmb != null && jmb.fileLoadingError != null)
+      if (jmb != null && jmb.hasFileLoadingError())
       {
         g.setColor(Color.black);
         g.fillRect(0, 0, currentSize.width, currentSize.height);
@@ -1034,104 +729,6 @@ public class AppJmol extends StructureViewerBase
     }
   }
 
-  public void updateTitleAndMenus()
-  {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
-    {
-      repaint();
-      return;
-    }
-    setChainMenuItems(jmb.getChainNames());
-
-    this.setTitle(jmb.getViewerTitle());
-    if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
-    {
-      viewerActionMenu.setVisible(true);
-    }
-    if (!jmb.isLoadingFromArchive())
-    {
-      seqColour_actionPerformed(null);
-    }
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see
-   * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
-   * .ActionEvent)
-   */
-  @Override
-  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
-  {
-    alignStructs_withAllAlignPanels();
-  }
-
-  private void alignStructs_withAllAlignPanels()
-  {
-    if (getAlignmentPanel() == null)
-    {
-      return;
-    }
-    ;
-    if (_alignwith.size() == 0)
-    {
-      _alignwith.add(getAlignmentPanel());
-    }
-    ;
-    try
-    {
-      AlignmentI[] als = new Alignment[_alignwith.size()];
-      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
-      int[] alm = new int[_alignwith.size()];
-      int a = 0;
-
-      for (AlignmentPanel ap : _alignwith)
-      {
-        als[a] = ap.av.getAlignment();
-        alm[a] = -1;
-        alc[a++] = ap.av.getColumnSelection();
-      }
-      jmb.superposeStructures(als, alm, alc);
-    } catch (Exception e)
-    {
-      StringBuffer sp = new StringBuffer();
-      for (AlignmentPanel ap : _alignwith)
-      {
-        sp.append("'" + ap.alignFrame.getTitle() + "' ");
-      }
-      Cache.log.info("Couldn't align structures with the " + sp.toString()
-              + "associated alignment panels.", e);
-
-    }
-
-  }
-
-  @Override
-  public void setJalviewColourScheme(ColourSchemeI ucs)
-  {
-    jmb.setJalviewColourScheme(ucs);
-
-  }
-
-  /**
-   * 
-   * @param alignment
-   * @return first alignment panel displaying given alignment, or the default
-   *         alignment panel
-   */
-  public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
-  {
-    for (AlignmentPanel ap : getAllAlignmentPanels())
-    {
-      if (ap.av.getAlignment() == alignment)
-      {
-        return ap;
-      }
-    }
-    return getAlignmentPanel();
-  }
-
   @Override
   public AAStructureBindingModel getBinding()
   {
@@ -1151,9 +748,8 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  protected AAStructureBindingModel getBindingModel()
+  protected String getViewerName()
   {
-    return jmb;
+    return "Jmol";
   }
-
 }
index 048f441..530f4fe 100644 (file)
 package jalview.gui;
 
 import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
 import jalview.io.StructureFile;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
 
-import java.awt.Color;
 import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
-import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
-import javax.swing.JMenu;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
 
 /**
  * GUI elements for handling an external chimera display
@@ -99,88 +74,21 @@ public class ChimeraViewFrame extends StructureViewerBase
   /**
    * Initialise menu options.
    */
-  private void initMenus()
+  @Override
+  protected void initMenus()
   {
+    super.initMenus();
+
     viewerActionMenu.setText(MessageManager.getString("label.chimera"));
+
     viewerColour.setText(MessageManager
             .getString("label.colour_with_chimera"));
     viewerColour.setToolTipText(MessageManager
             .getString("label.let_chimera_manage_structure_colours"));
-    helpItem.setText(MessageManager.getString("label.chimera_help"));
-    seqColour.setSelected(jmb.isColourBySequence());
-    viewerColour.setSelected(!jmb.isColourBySequence());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-
-    // save As not yet implemented
-    savemenu.setVisible(false);
 
-    ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
-            MessageManager.getString("label.colour_by"), this, _colourwith,
-            new ItemListener()
-            {
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                if (!seqColour.isSelected())
-                {
-                  seqColour.doClick();
-                }
-                else
-                {
-                  // update the Chimera display now.
-                  seqColour_actionPerformed(null);
-                }
-              }
-            });
-    viewMenu.add(seqColourBy);
+    helpItem.setText(MessageManager.getString("label.chimera_help"));
+    savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
-
-    final ItemListener handler;
-    JMenu alpanels = new ViewSelectionMenu(
-            MessageManager.getString("label.superpose_with"), this,
-            _alignwith, handler = new ItemListener()
-            {
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                alignStructs.setEnabled(_alignwith.size() > 0);
-                alignStructs.setToolTipText(MessageManager
-                        .formatMessage(
-                                "label.align_structures_using_linked_alignment_views",
-                                new Object[] { new Integer(_alignwith
-                                        .size()).toString() }));
-              }
-            });
-    handler.itemStateChanged(null);
-    viewerActionMenu.add(alpanels);
-    viewerActionMenu.addMenuListener(new MenuListener()
-    {
-
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        handler.itemStateChanged(null);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-      }
-    });
   }
 
   /**
@@ -234,15 +142,6 @@ public class ChimeraViewFrame extends StructureViewerBase
     }
   }
 
-  /**
-   * Answers true if this viewer already involves the given PDB ID
-   */
-  @Override
-  protected boolean hasPdbId(String pdbId)
-  {
-    return jmb.hasPdbId(pdbId);
-  }
-
   private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
           SequenceI[][] seqs)
   {
@@ -252,6 +151,7 @@ public class ChimeraViewFrame extends StructureViewerBase
             ap.getStructureSelectionManager(), pdbentrys, seqs, null);
     addAlignmentPanel(ap);
     useAlignmentPanelForColourbyseq(ap);
+
     if (pdbentrys.length > 1)
     {
       alignAddedStructures = true;
@@ -276,8 +176,6 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   }
 
-
-
   /**
    * Create a new viewer from saved session state data including Chimera session
    * file
@@ -373,7 +271,7 @@ public class ChimeraViewFrame extends StructureViewerBase
   {
     jmb.setFinishedInit(false);
     jalview.gui.Desktop.addInternalFrame(this,
-            jmb.getViewerTitle("Chimera", true), getBounds().width,
+            jmb.getViewerTitle(getViewerName(), true), getBounds().width,
             getBounds().height);
 
     if (!jmb.launchChimera())
@@ -440,7 +338,8 @@ public class ChimeraViewFrame extends StructureViewerBase
       {
         String prompt = MessageManager.formatMessage(
                 "label.confirm_close_chimera",
-                new Object[] { jmb.getViewerTitle("Chimera", false) });
+                        new Object[] { jmb.getViewerTitle(getViewerName(),
+                                false) });
         prompt = JvSwingUtils.wrapTooltip(true, prompt);
         int confirm = JvOptionPane.showConfirmDialog(this, prompt,
                 MessageManager.getString("label.close_viewer"),
@@ -570,7 +469,7 @@ public class ChimeraViewFrame extends StructureViewerBase
           try
           {
             int pos = filePDBpos.get(num).intValue();
-            long startTime = startProgressBar("Chimera "
+            long startTime = startProgressBar(getViewerName() + " "
                     + MessageManager.getString("status.opening_file_for")
                     + " " + pe.getId());
             jmb.openFile(pe);
@@ -735,76 +634,6 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  public void pdbFile_actionPerformed(ActionEvent actionEvent)
-  {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
-    chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      BufferedReader in = null;
-      try
-      {
-        // TODO: cope with multiple PDB files in view
-        in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
-        File outFile = chooser.getSelectedFile();
-
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
-        String data;
-        while ((data = in.readLine()) != null)
-        {
-          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
-          {
-            out.println(data);
-          }
-        }
-        out.close();
-      } catch (Exception ex)
-      {
-        ex.printStackTrace();
-      } finally
-      {
-        if (in != null)
-        {
-          try
-          {
-            in.close();
-          } catch (IOException e)
-          {
-            e.printStackTrace();
-          }
-        }
-      }
-    }
-  }
-
-  @Override
-  public void viewMapping_actionPerformed(ActionEvent actionEvent)
-  {
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
-    try
-    {
-      cap.appendText(jmb.printMappings());
-    } catch (OutOfMemoryError e)
-    {
-      new OOMWarning(
-              "composing sequence-structure alignments for display in text box.",
-              e);
-      cap.dispose();
-      return;
-    }
-    jalview.gui.Desktop.addInternalFrame(cap,
-            MessageManager.getString("label.pdb_sequence_mapping"), 550,
-            600);
-  }
-
-  @Override
   public void eps_actionPerformed(ActionEvent e)
   {
     throw new Error(
@@ -821,246 +650,17 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  public void viewerColour_actionPerformed(ActionEvent actionEvent)
-  {
-    if (viewerColour.isSelected())
-    {
-      // disable automatic sequence colouring.
-      jmb.setColourBySequence(false);
-    }
-  }
-
-  @Override
-  public void seqColour_actionPerformed(ActionEvent actionEvent)
-  {
-    jmb.setColourBySequence(seqColour.isSelected());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (jmb.isColourBySequence())
-    {
-      if (!jmb.isLoadingFromArchive())
-      {
-        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
-        {
-          // Make the currently displayed alignment panel the associated view
-          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
-        }
-      }
-      // Set the colour using the current view for the associated alignframe
-      for (AlignmentPanel ap : _colourwith)
-      {
-        jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
-      }
-    }
-  }
-
-  @Override
-  public void chainColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chainColour.setSelected(true);
-    jmb.colourByChain();
-  }
-
-  @Override
-  public void chargeColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chargeColour.setSelected(true);
-    jmb.colourByCharge();
-  }
-
-  @Override
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-    zappoColour.setSelected(true);
-    jmb.setJalviewColourScheme(new ZappoColourScheme());
-  }
-
-  @Override
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-    taylorColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TaylorColourScheme());
-  }
-
-  @Override
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-    hydroColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HydrophobicColourScheme());
-  }
-
-  @Override
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-    helixColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HelixColourScheme());
-  }
-
-  @Override
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-    strandColour.setSelected(true);
-    jmb.setJalviewColourScheme(new StrandColourScheme());
-  }
-
-  @Override
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-    turnColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TurnColourScheme());
-  }
-
-  @Override
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-    buriedColour.setSelected(true);
-    jmb.setJalviewColourScheme(new BuriedColourScheme());
-  }
-
-  @Override
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-    setJalviewColourScheme(new PurinePyrimidineColourScheme());
-  }
-
-  @Override
-  public void userColour_actionPerformed(ActionEvent e)
-  {
-    if (e.getActionCommand().equals(
-            MessageManager.getString("action.user_defined")))
-    {
-      new UserDefinedColours(this, null);
-    }
-    else
-    {
-      UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get(
-              e.getActionCommand());
-      jmb.setJalviewColourScheme(udc);
-    }
-  }
-
-  @Override
-  public void backGround_actionPerformed(ActionEvent actionEvent)
-  {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_background_colour"),
-            null);
-    if (col != null)
-    {
-      jmb.setBackgroundColour(col);
-    }
-  }
-
-  @Override
   public void showHelp_actionPerformed(ActionEvent actionEvent)
   {
     try
     {
-      jalview.util.BrowserLauncher
+      BrowserLauncher
               .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
     } catch (Exception ex)
     {
     }
   }
 
-  public void updateTitleAndMenus()
-  {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
-    {
-      repaint();
-      return;
-    }
-    setChainMenuItems(jmb.getChainNames());
-
-    this.setTitle(jmb.getViewerTitle("Chimera", true));
-    if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
-    {
-      viewerActionMenu.setVisible(true);
-    }
-    if (!jmb.isLoadingFromArchive())
-    {
-      seqColour_actionPerformed(null);
-    }
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see
-   * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
-   * .ActionEvent)
-   */
-  @Override
-  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
-  {
-    alignStructs_withAllAlignPanels();
-  }
-
-  private void alignStructs_withAllAlignPanels()
-  {
-    if (getAlignmentPanel() == null)
-    {
-      return;
-    }
-
-    if (_alignwith.size() == 0)
-    {
-      _alignwith.add(getAlignmentPanel());
-    }
-
-    try
-    {
-      AlignmentI[] als = new Alignment[_alignwith.size()];
-      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
-      int[] alm = new int[_alignwith.size()];
-      int a = 0;
-
-      for (AlignmentPanel ap : _alignwith)
-      {
-        als[a] = ap.av.getAlignment();
-        alm[a] = -1;
-        alc[a++] = ap.av.getColumnSelection();
-      }
-      jmb.superposeStructures(als, alm, alc);
-    } catch (Exception e)
-    {
-      StringBuffer sp = new StringBuffer();
-      for (AlignmentPanel ap : _alignwith)
-      {
-        sp.append("'" + ap.alignFrame.getTitle() + "' ");
-      }
-      Cache.log.info("Couldn't align structures with the " + sp.toString()
-              + "associated alignment panels.", e);
-    }
-  }
-
-  @Override
-  public void setJalviewColourScheme(ColourSchemeI ucs)
-  {
-    jmb.setJalviewColourScheme(ucs);
-
-  }
-
-  /**
-   * 
-   * @param alignment
-   * @return first alignment panel displaying given alignment, or the default
-   *         alignment panel
-   */
-  public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
-  {
-    for (AlignmentPanel ap : getAllAlignmentPanels())
-    {
-      if (ap.av.getAlignment() == alignment)
-      {
-        return ap;
-      }
-    }
-    return getAlignmentPanel();
-  }
-
   @Override
   public AAStructureBindingModel getBinding()
   {
@@ -1150,8 +750,8 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  protected AAStructureBindingModel getBindingModel()
+  protected String getViewerName()
   {
-    return jmb;
+    return "Chimera";
   }
 }
index a5f4355..8e0765b 100644 (file)
@@ -27,8 +27,9 @@ public class ColourMenuHelper
   /**
    * Adds items to the colour menu, as mutually exclusive members of a button
    * group. The callback handler is responsible for the action on selecting any
-   * of these options. It is returned the name of the selected colour, or "None"
-   * or "User Defined".
+   * of these options. The callback method receives the name of the selected
+   * colour, or "None" or "User Defined". This method returns the ButtonGroup to
+   * which items were added.
    * <ul>
    * <li>None</li>
    * <li>Clustal</li>
@@ -43,28 +44,35 @@ public class ColourMenuHelper
    *          a callback to handle menu selection
    * @param coll
    *          the data the menu is being built for
+   * @param simpleOnly
+   *          if true, only simple per-residue colour schemes are included
    */
-  public static void addMenuItems(final JMenu colourMenu,
-          final ColourChangeListener client, AnnotatedCollectionI coll)
+  public static ButtonGroup addMenuItems(final JMenu colourMenu,
+          final ColourChangeListener client, AnnotatedCollectionI coll,
+          boolean simpleOnly)
   {
     /*
      * ButtonGroup groups those items whose 
      * selection is mutually exclusive
      */
     ButtonGroup colours = new ButtonGroup();
-    JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
-            MessageManager.getString("label.none"));
-    noColourmenuItem.setName(ResidueColourScheme.NONE);
-    noColourmenuItem.addActionListener(new ActionListener()
+
+    if (!simpleOnly)
     {
-      @Override
-      public void actionPerformed(ActionEvent e)
+      JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
+              MessageManager.getString("label.none"));
+      noColourmenuItem.setName(ResidueColourScheme.NONE);
+      noColourmenuItem.addActionListener(new ActionListener()
       {
-        client.changeColour_actionPerformed(ResidueColourScheme.NONE);
-      }
-    });
-    colourMenu.add(noColourmenuItem);
-    colours.add(noColourmenuItem);
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          client.changeColour_actionPerformed(ResidueColourScheme.NONE);
+        }
+      });
+      colourMenu.add(noColourmenuItem);
+      colours.add(noColourmenuItem);
+    }
 
     /*
      * scan registered colour schemes (built-in or user-defined
@@ -74,9 +82,14 @@ public class ColourMenuHelper
             .getColourSchemes();
     for (ColourSchemeI scheme : colourSchemes)
     {
+      if (simpleOnly && !scheme.isSimple())
+      {
+        continue;
+      }
+
       /*
        * button text is i18n'd but the name is the canonical name of
-       * the colour scheme (inspected in changeColour_actionPerformed)
+       * the colour scheme (inspected in setColourSelected())
        */
       final String name = scheme.getSchemeName();
       String label = MessageManager.getStringOrReturn("label.colourScheme_"
@@ -148,18 +161,28 @@ public class ColourMenuHelper
       colours.add(radioItem);
     }
 
-    final String label = MessageManager.getString("action.user_defined");
-    JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(label);
-    userDefinedColour.addActionListener(new ActionListener()
+    /*
+     * only add the option to load/configure a user-defined colour
+     * to the AlignFrame colour menu
+     */
+    if (client instanceof AlignFrame)
     {
-      @Override
-      public void actionPerformed(ActionEvent e)
+      final String label = MessageManager.getString("action.user_defined");
+      JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(
+              label);
+      userDefinedColour.addActionListener(new ActionListener()
       {
-        client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
-      }
-    });
-    colourMenu.add(userDefinedColour);
-    colours.add(userDefinedColour);
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
+        }
+      });
+      colourMenu.add(userDefinedColour);
+      colours.add(userDefinedColour);
+    }
+
+    return colours;
   }
 
   /**
index 801b285..a797872 100644 (file)
@@ -95,7 +95,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
     }
     if (!isLoadingFromArchive())
     {
-      colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+      colourBySequence(ap);
     }
   }
 
index b6fd5fc..c660ab5 100644 (file)
@@ -1271,11 +1271,18 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
   protected void buildColourMenu()
   {
     SequenceGroup sg = getGroup();
+    if (sg == null)
+    {
+      /*
+       * popup menu with no sequence group scope
+       */
+      return;
+    }
     colourMenu.removeAll();
     colourMenu.add(textColour);
     colourMenu.addSeparator();
 
-    ColourMenuHelper.addMenuItems(colourMenu, this, sg);
+    ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
 
     colourMenu.addSeparator();
     colourMenu.add(conservationMenuItem);
index 91d7130..34ad659 100644 (file)
  */
 package jalview.gui;
 
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.DataSourceType;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
 import jalview.jbgui.GStructureViewer;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
+import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
 
 /**
  * Base class with common functionality for JMol, Chimera or other structure
@@ -52,6 +72,13 @@ import javax.swing.JOptionPane;
 public abstract class StructureViewerBase extends GStructureViewer
         implements Runnable, ViewSetProvider
 {
+  /*
+   * names for colour options (additional to Jalview colour schemes)
+   */
+  enum ViewerColour
+  {
+    BySequence, ByChain, ChargeCysteine, ByViewer
+  }
 
   /**
    * list of sequenceSet ids associated with the view
@@ -84,6 +111,13 @@ public abstract class StructureViewerBase extends GStructureViewer
   protected boolean allChainsSelected = false;
 
   /**
+   * Default constructor
+   */
+  public StructureViewerBase()
+  {
+    super();
+  }
+  /**
    * 
    * @param ap2
    * @return true if this Jmol instance is linked with the given alignPanel
@@ -273,8 +307,6 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   public abstract ViewerType getViewerType();
 
-  protected abstract AAStructureBindingModel getBindingModel();
-
   /**
    * add a new structure (with associated sequences and chains) to this viewer,
    * retrieving it if necessary first.
@@ -320,7 +352,7 @@ public abstract class StructureViewerBase extends GStructureViewer
       }
     }
     // otherwise, start adding the structure.
-    getBindingModel().addSequenceAndChain(new PDBEntry[] { pdbentry },
+    getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
             new SequenceI[][] { seqs }, new String[][] { chains });
     addingStructures = true;
     _started = false;
@@ -350,7 +382,10 @@ public abstract class StructureViewerBase extends GStructureViewer
     return option;
   }
 
-  protected abstract boolean hasPdbId(String pdbId);
+  protected boolean hasPdbId(String pdbId)
+  {
+    return getBinding().hasPdbId(pdbId);
+  }
 
   protected abstract List<StructureViewerBase> getViewersFor(
           AlignmentPanel alp);
@@ -438,7 +473,7 @@ public abstract class StructureViewerBase extends GStructureViewer
     // JBPNOTE: this looks like a binding routine, rather than a gui routine
     for (StructureViewerBase viewer : getViewersFor(null))
     {
-      AAStructureBindingModel bindingModel = viewer.getBindingModel();
+      AAStructureBindingModel bindingModel = viewer.getBinding();
       for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
       {
         if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
@@ -552,4 +587,389 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   abstract void showSelectedChains();
 
+  /**
+   * Action on selecting one of Jalview's registered colour schemes
+   */
+  @Override
+  public void changeColour_actionPerformed(String colourSchemeName)
+  {
+    AlignmentI al = getAlignmentPanel().av.getAlignment();
+    ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(
+            colourSchemeName, al, null);
+    getBinding().setJalviewColourScheme(cs);
+  }
+
+  /**
+   * Builds the colour menu
+   */
+  protected void buildColourMenu()
+  {
+    colourMenu.removeAll();
+    AlignmentI al = getAlignmentPanel().av.getAlignment();
+
+    /*
+     * add colour by sequence, by chain, by charge and cysteine
+     */
+    colourMenu.add(seqColour);
+    colourMenu.add(chainColour);
+    colourMenu.add(chargeColour);
+    chargeColour.setEnabled(!al.isNucleotide());
+
+    /*
+     * add all 'simple' (per-residue) colour schemes registered to Jalview
+     */
+    ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
+            al, true);
+
+    /*
+     * add 'colour by viewer' (menu item text is set in subclasses)
+     */
+    viewerColour.setSelected(false);
+    viewerColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        viewerColour_actionPerformed(actionEvent);
+      }
+    });
+    colourMenu.add(viewerColour);
+
+    /*
+     * add 'set background colour'
+     */
+    JMenuItem backGround = new JMenuItem();
+    backGround
+            .setText(MessageManager.getString("action.background_colour"));
+    backGround.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        background_actionPerformed(actionEvent);
+      }
+    });
+    colourMenu.add(backGround);
+
+    /*
+     * add colour buttons to a group so their selection is
+     * mutually exclusive (background colour is a separate option)
+     */
+    itemGroup.add(seqColour);
+    itemGroup.add(chainColour);
+    itemGroup.add(chargeColour);
+    itemGroup.add(viewerColour);
+  }
+
+  /**
+   * Construct menu items
+   */
+  protected void initMenus()
+  {
+    AAStructureBindingModel binding = getBinding();
+
+    seqColour = new JRadioButtonMenuItem();
+    seqColour.setText(MessageManager.getString("action.by_sequence"));
+    seqColour.setName(ViewerColour.BySequence.name());
+    seqColour.setSelected(binding.isColourBySequence());
+    seqColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        seqColour_actionPerformed(actionEvent);
+      }
+    });
+
+    chainColour = new JRadioButtonMenuItem();
+    chainColour.setText(MessageManager.getString("action.by_chain"));
+    chainColour.setName(ViewerColour.ByChain.name());
+    chainColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        chainColour_actionPerformed(actionEvent);
+      }
+    });
+
+    chargeColour = new JRadioButtonMenuItem();
+    chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
+    chargeColour.setName(ViewerColour.ChargeCysteine.name());
+    chargeColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        chargeColour_actionPerformed(actionEvent);
+      }
+    });
+
+    viewerColour = new JRadioButtonMenuItem();
+    // text is set in overrides of this method
+    viewerColour.setName(ViewerColour.ByViewer.name());
+    viewerColour.setSelected(!binding.isColourBySequence());
+
+    if (_colourwith == null)
+    {
+      _colourwith = new Vector<AlignmentPanel>();
+    }
+    if (_alignwith == null)
+    {
+      _alignwith = new Vector<AlignmentPanel>();
+    }
+
+    ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
+            MessageManager.getString("label.colour_by"), this, _colourwith,
+            new ItemListener()
+            {
+              @Override
+              public void itemStateChanged(ItemEvent e)
+              {
+                if (!seqColour.isSelected())
+                {
+                  seqColour.doClick();
+                }
+                else
+                {
+                  // update the Chimera display now.
+                  seqColour_actionPerformed(null);
+                }
+              }
+            });
+    viewMenu.add(seqColourBy);
+
+    final ItemListener handler = new ItemListener()
+    {
+      @Override
+      public void itemStateChanged(ItemEvent e)
+      {
+        alignStructs.setEnabled(_alignwith.size() > 0);
+        alignStructs.setToolTipText(MessageManager.formatMessage(
+                "label.align_structures_using_linked_alignment_views",
+                new String[] { String.valueOf(_alignwith.size()) }));
+      }
+    };
+    JMenu alpanels = new ViewSelectionMenu(
+            MessageManager.getString("label.superpose_with"), this,
+            _alignwith, handler);
+    handler.itemStateChanged(null);
+    viewerActionMenu.add(alpanels);
+    viewerActionMenu.addMenuListener(new MenuListener()
+    {
+      @Override
+      public void menuSelected(MenuEvent e)
+      {
+        handler.itemStateChanged(null);
+      }
+
+      @Override
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      @Override
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
+
+    buildColourMenu();
+  }
+
+  @Override
+  public void setJalviewColourScheme(ColourSchemeI cs) {
+    getBinding().setJalviewColourScheme(cs);
+  }
+  @Override
+  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+  {
+    alignStructs_withAllAlignPanels();
+  }
+  protected void alignStructs_withAllAlignPanels()
+  {
+    if (getAlignmentPanel() == null)
+    {
+      return;
+    }
+  
+    if (_alignwith.size() == 0)
+    {
+      _alignwith.add(getAlignmentPanel());
+    }
+  
+    try
+    {
+      AlignmentI[] als = new Alignment[_alignwith.size()];
+      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
+      int[] alm = new int[_alignwith.size()];
+      int a = 0;
+  
+      for (AlignmentPanel ap : _alignwith)
+      {
+        als[a] = ap.av.getAlignment();
+        alm[a] = -1;
+        alc[a++] = ap.av.getColumnSelection();
+      }
+      getBinding().superposeStructures(als, alm, alc);
+    } catch (Exception e)
+    {
+      StringBuffer sp = new StringBuffer();
+      for (AlignmentPanel ap : _alignwith)
+      {
+        sp.append("'" + ap.alignFrame.getTitle() + "' ");
+      }
+      Cache.log.info("Couldn't align structures with the " + sp.toString()
+              + "associated alignment panels.", e);
+    }
+  }
+  @Override
+  public void background_actionPerformed(ActionEvent actionEvent)
+  {
+    Color col = JColorChooser.showDialog(this,
+            MessageManager.getString("label.select_background_colour"),
+            null);
+    if (col != null)
+    {
+      getBinding().setBackgroundColour(col);
+    }
+  }
+  @Override
+  public void viewerColour_actionPerformed(ActionEvent actionEvent)
+  {
+    if (viewerColour.isSelected())
+    {
+      // disable automatic sequence colouring.
+      getBinding().setColourBySequence(false);
+    }
+  }
+  @Override
+  public void chainColour_actionPerformed(ActionEvent actionEvent)
+  {
+    chainColour.setSelected(true);
+    getBinding().colourByChain();
+  }
+  @Override
+  public void chargeColour_actionPerformed(ActionEvent actionEvent)
+  {
+    chargeColour.setSelected(true);
+    getBinding().colourByCharge();
+  }
+  @Override
+  public void seqColour_actionPerformed(ActionEvent actionEvent)
+  {
+    AAStructureBindingModel binding = getBinding();
+    binding.setColourBySequence(seqColour.isSelected());
+    if (_colourwith == null)
+    {
+      _colourwith = new Vector<AlignmentPanel>();
+    }
+    if (binding.isColourBySequence())
+    {
+      if (!binding.isLoadingFromArchive())
+      {
+        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
+        {
+          // Make the currently displayed alignment panel the associated view
+          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
+        }
+      }
+      // Set the colour using the current view for the associated alignframe
+      for (AlignmentPanel ap : _colourwith)
+      {
+        binding.colourBySequence(ap);
+      }
+    }
+  }
+  @Override
+  public void pdbFile_actionPerformed(ActionEvent actionEvent)
+  {
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            Cache.getProperty("LAST_DIRECTORY"));
+  
+    chooser.setFileView(new JalviewFileView());
+    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
+    chooser.setToolTipText(MessageManager.getString("action.save"));
+  
+    int value = chooser.showSaveDialog(this);
+  
+    if (value == JalviewFileChooser.APPROVE_OPTION)
+    {
+      BufferedReader in = null;
+      try
+      {
+        // TODO: cope with multiple PDB files in view
+        in = new BufferedReader(
+                new FileReader(getBinding().getPdbFile()[0]));
+        File outFile = chooser.getSelectedFile();
+  
+        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+        String data;
+        while ((data = in.readLine()) != null)
+        {
+          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
+          {
+            out.println(data);
+          }
+        }
+        out.close();
+      } catch (Exception ex)
+      {
+        ex.printStackTrace();
+      } finally
+      {
+        if (in != null)
+        {
+          try
+          {
+            in.close();
+          } catch (IOException e)
+          {
+            // ignore
+          }
+        }
+      }
+    }
+  }
+  @Override
+  public void viewMapping_actionPerformed(ActionEvent actionEvent)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();
+    try
+    {
+      cap.appendText(getBinding().printMappings());
+    } catch (OutOfMemoryError e)
+    {
+      new OOMWarning(
+              "composing sequence-structure alignments for display in text box.",
+              e);
+      cap.dispose();
+      return;
+    }
+    Desktop.addInternalFrame(cap,
+            MessageManager.getString("label.pdb_sequence_mapping"), 550,
+            600);
+  }
+
+  protected abstract String getViewerName();
+  public void updateTitleAndMenus()
+  {
+    AAStructureBindingModel binding = getBinding();
+    if (binding.hasFileLoadingError())
+    {
+      repaint();
+      return;
+    }
+    setChainMenuItems(binding.getChainNames());
+  
+    this.setTitle(binding.getViewerTitle(getViewerName(), true));
+    if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1)
+    {
+      viewerActionMenu.setVisible(true);
+    }
+    if (!binding.isLoadingFromArchive())
+    {
+      seqColour_actionPerformed(null);
+    }
+  }
 }
index 52f745d..6b89ab4 100644 (file)
 package jalview.jbgui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.gui.UserDefinedColours;
-import jalview.schemes.UserColourScheme;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.Map;
 
-import javax.swing.ButtonGroup;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -41,7 +38,7 @@ import javax.swing.JPanel;
 import javax.swing.JRadioButtonMenuItem;
 
 public abstract class GStructureViewer extends JInternalFrame implements
-        JalviewStructureDisplayI
+        JalviewStructureDisplayI, ColourChangeListener
 {
   // private AAStructureBindingModel bindingModel;
 
@@ -65,26 +62,6 @@ public abstract class GStructureViewer extends JInternalFrame implements
 
   protected JRadioButtonMenuItem chargeColour;
 
-  protected JRadioButtonMenuItem zappoColour;
-
-  protected JRadioButtonMenuItem taylorColour;
-
-  protected JRadioButtonMenuItem hydroColour;
-
-  protected JRadioButtonMenuItem strandColour;
-
-  protected JRadioButtonMenuItem helixColour;
-
-  protected JRadioButtonMenuItem turnColour;
-
-  protected JRadioButtonMenuItem buriedColour;
-
-  protected JRadioButtonMenuItem nucleotideColour;
-
-  protected JRadioButtonMenuItem purinePyrimidineColour;
-
-  protected JRadioButtonMenuItem userColour;
-
   protected JRadioButtonMenuItem viewerColour;
 
   protected JMenuItem helpItem;
@@ -204,11 +181,11 @@ public abstract class GStructureViewer extends JInternalFrame implements
       }
     });
 
-    viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
+    viewerActionMenu = new JMenu();
     viewerActionMenu.setVisible(false);
     viewerActionMenu.add(alignStructs);
     colourMenu = new JMenu();
-    buildColourMenu();
+    colourMenu.setText(MessageManager.getString("label.colours"));
     fileMenu.add(savemenu);
     fileMenu.add(viewMapping);
     savemenu.add(pdbFile);
@@ -230,240 +207,6 @@ public abstract class GStructureViewer extends JInternalFrame implements
     statusPanel.add(statusBar, null);
   }
 
-  /**
-   * Builds the colour menu
-   */
-  protected void buildColourMenu()
-  {
-    colourMenu.removeAll();
-    colourMenu.setText(MessageManager.getString("label.colours"));
-
-    JMenuItem backGround = new JMenuItem();
-    backGround
-            .setText(MessageManager.getString("action.background_colour"));
-    backGround.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        backGround_actionPerformed(actionEvent);
-      }
-    });
-    seqColour = new JRadioButtonMenuItem();
-    seqColour.setSelected(false);
-    seqColour.setText(MessageManager.getString("action.by_sequence"));
-    seqColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        seqColour_actionPerformed(actionEvent);
-      }
-    });
-    chainColour = new JRadioButtonMenuItem();
-    chainColour.setText(MessageManager.getString("action.by_chain"));
-    chainColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        chainColour_actionPerformed(actionEvent);
-      }
-    });
-    chargeColour = new JRadioButtonMenuItem();
-    chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
-    chargeColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        chargeColour_actionPerformed(actionEvent);
-      }
-    });
-    zappoColour = new JRadioButtonMenuItem();
-    zappoColour.setText(MessageManager
-            .getString("label.colourScheme_zappo"));
-    zappoColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        zappoColour_actionPerformed(actionEvent);
-      }
-    });
-    taylorColour = new JRadioButtonMenuItem();
-    taylorColour.setText(MessageManager
-            .getString("label.colourScheme_taylor"));
-    taylorColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        taylorColour_actionPerformed(actionEvent);
-      }
-    });
-    hydroColour = new JRadioButtonMenuItem();
-    hydroColour.setText(MessageManager
-            .getString("label.colourScheme_hydrophobic"));
-    hydroColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        hydroColour_actionPerformed(actionEvent);
-      }
-    });
-    strandColour = new JRadioButtonMenuItem();
-    strandColour.setText(MessageManager
-            .getString("label.colourScheme_strand_propensity"));
-    strandColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        strandColour_actionPerformed(actionEvent);
-      }
-    });
-    helixColour = new JRadioButtonMenuItem();
-    helixColour.setText(MessageManager
-            .getString("label.colourScheme_helix_propensity"));
-    helixColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        helixColour_actionPerformed(actionEvent);
-      }
-    });
-    turnColour = new JRadioButtonMenuItem();
-    turnColour.setText(MessageManager
-            .getString("label.colourScheme_turn_propensity"));
-    turnColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        turnColour_actionPerformed(actionEvent);
-      }
-    });
-    buriedColour = new JRadioButtonMenuItem();
-    buriedColour.setText(MessageManager
-            .getString("label.colourScheme_buried_index"));
-    buriedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        buriedColour_actionPerformed(actionEvent);
-      }
-    });
-    nucleotideColour = new JRadioButtonMenuItem();
-    nucleotideColour.setText(MessageManager
-            .getString("label.colourScheme_nucleotide"));
-    nucleotideColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        nucleotideColour_actionPerformed(actionEvent);
-      }
-    });
-    purinePyrimidineColour = new JRadioButtonMenuItem();
-    purinePyrimidineColour.setText(MessageManager
-            .getString("label.colourScheme_purine/pyrimidine"));
-    purinePyrimidineColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        purinePyrimidineColour_actionPerformed(actionEvent);
-      }
-    });
-    userColour = new JRadioButtonMenuItem();
-    userColour.setText(MessageManager.getString("action.user_defined"));
-    userColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        userColour_actionPerformed(actionEvent);
-      }
-    });
-    viewerColour = new JRadioButtonMenuItem();
-    viewerColour.setSelected(false);
-    viewerColour
-            .setText(MessageManager.getString("label.colour_with_jmol"));
-    viewerColour.setToolTipText(MessageManager
-            .getString("label.let_jmol_manage_structure_colours"));
-    viewerColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        viewerColour_actionPerformed(actionEvent);
-      }
-    });
-
-    /*
-     * add colour buttons to a group so their selection
-     * is mutually exclusive
-     */
-    ButtonGroup colourButtons = new ButtonGroup();
-
-    colourMenu.add(seqColour);
-    colourMenu.add(chainColour);
-    colourMenu.add(chargeColour);
-    colourMenu.add(zappoColour);
-    colourMenu.add(taylorColour);
-    colourMenu.add(hydroColour);
-    colourMenu.add(helixColour);
-    colourMenu.add(strandColour);
-    colourMenu.add(turnColour);
-    colourMenu.add(buriedColour);
-    colourMenu.add(purinePyrimidineColour);
-
-    /*
-     * add any user-defined colours that are loaded
-     */
-    Map<String, UserColourScheme> userColourSchemes = UserDefinedColours
-            .getUserColourSchemes();
-    if (userColourSchemes != null)
-    {
-      for (String schemeName : userColourSchemes.keySet())
-      {
-        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
-                schemeName);
-        radioItem.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent evt)
-          {
-            userColour_actionPerformed(evt);
-          }
-        });
-        colourMenu.add(radioItem);
-        colourButtons.add(radioItem);
-      }
-    }
-    colourMenu.add(userColour);
-    colourMenu.add(viewerColour);
-    colourMenu.add(backGround);
-
-    colourButtons.add(seqColour);
-    colourButtons.add(chainColour);
-    colourButtons.add(chargeColour);
-    colourButtons.add(zappoColour);
-    colourButtons.add(taylorColour);
-    colourButtons.add(hydroColour);
-    colourButtons.add(helixColour);
-    colourButtons.add(strandColour);
-    colourButtons.add(turnColour);
-    colourButtons.add(buriedColour);
-    colourButtons.add(purinePyrimidineColour);
-    colourButtons.add(userColour);
-    colourButtons.add(viewerColour);
-  }
-
   protected void fitToWindow_actionPerformed()
   {
   }
@@ -515,57 +258,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
 
   }
 
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void nucleotideColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void userColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void backGround_actionPerformed(ActionEvent actionEvent)
+  public void background_actionPerformed(ActionEvent actionEvent)
   {
 
   }
@@ -574,14 +267,4 @@ public abstract class GStructureViewer extends JInternalFrame implements
   {
 
   }
-
-  // {
-  // return bindingModel;
-  // }
-
-  // public void setBindingModel(AAStructureBindingModel bindingModel)
-  // {
-  // this.bindingModel = bindingModel;
-  // }
-
 }
index e3ef391..fb1443d 100755 (executable)
@@ -426,4 +426,10 @@ public class AnnotationColourGradient extends FollowerColourScheme
   {
     return "Annotation";
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index d68791c..be77e00 100755 (executable)
@@ -122,4 +122,10 @@ public class Blosum62ColourScheme extends ResidueColourScheme
   {
     return JalviewColourScheme.Blosum62.toString();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 2bb64fc..9c0b953 100755 (executable)
@@ -361,4 +361,10 @@ public class ClustalxColourScheme extends ResidueColourScheme
   {
     return JalviewColourScheme.Clustal.toString();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index be8793b..372b569 100755 (executable)
@@ -159,4 +159,15 @@ public interface ColourSchemeI
    * @return
    */
   String getSchemeName();
+
+  /**
+   * Answers true if the colour scheme depends only on the sequence symbol, and
+   * not on other information such as alignment consensus or annotation. (Note
+   * that simple colour schemes may have a fading by percentage identity or
+   * conservation overlaid.) Simple colour schemes can be propagated to
+   * structure viewers.
+   * 
+   * @return
+   */
+  boolean isSimple();
 }
index 3637ce3..6cb095b 100644 (file)
@@ -149,4 +149,10 @@ public class CovariationColourScheme extends ResidueColourScheme
   {
     return "Covariation";
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 5628fcd..389655c 100755 (executable)
@@ -114,4 +114,10 @@ public class PIDColourScheme extends ResidueColourScheme
   {
     return new PIDColourScheme();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 7a1d8d3..056a167 100644 (file)
@@ -240,4 +240,10 @@ public class RNAHelicesColour extends ResidueColourScheme
   {
     return JalviewColourScheme.RNAHelices.toString();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 92de7ac..57f7d57 100755 (executable)
@@ -409,4 +409,14 @@ public abstract class ResidueColourScheme implements ColourSchemeI
   {
     return false;
   }
+
+  /**
+   * Default method returns true. Override this to return false in colour
+   * schemes that are not determined solely by the sequence symbol.
+   */
+  @Override
+  public boolean isSimple()
+  {
+    return true;
+  }
 }
index 6f55204..13d1d55 100644 (file)
@@ -170,4 +170,10 @@ public class TCoffeeColourScheme extends ResidueColourScheme
   {
     return JalviewColourScheme.TCoffee.toString();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 063eacf..fda08fd 100644 (file)
  */
 package jalview.structures.models;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
 import jalview.api.StructureSelectionManagerProvider;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 
+import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -85,6 +92,8 @@ public abstract class AAStructureBindingModel extends
    */
   protected String[] modelFileNames = null;
 
+  public String fileLoadingError;
+
   /**
    * Data bean class to simplify parameterisation in superposeStructures
    */
@@ -688,4 +697,80 @@ public abstract class AAStructureBindingModel extends
   {
     return null;
   }
+
+  public abstract void setJalviewColourScheme(ColourSchemeI cs);
+
+  public abstract void superposeStructures(AlignmentI[] als, int[] alm,
+          ColumnSelection[] alc);
+
+  public abstract void setBackgroundColour(Color col);
+
+  protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
+          String[] files, SequenceRenderer sr, FeatureRenderer fr,
+          AlignmentI alignment);
+
+  /**
+   * returns the current featureRenderer that should be used to colour the
+   * structures
+   * 
+   * @param alignment
+   * 
+   * @return
+   */
+  public abstract FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment);
+
+  /**
+   * returns the current sequenceRenderer that should be used to colour the
+   * structures
+   * 
+   * @param alignment
+   * 
+   * @return
+   */
+  public abstract SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment);
+
+  protected abstract void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands);
+
+  public abstract void colourByChain();
+
+  public abstract void colourByCharge();
+
+  /**
+   * colour any structures associated with sequences in the given alignment
+   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
+   * if colourBySequence is enabled.
+   */
+  public void colourBySequence(AlignmentViewPanel alignmentv)
+  {
+    boolean showFeatures = alignmentv.getAlignViewport()
+            .isShowSequenceFeatures();
+    if (!colourBySequence || !isLoadingFinished())
+    {
+      return;
+    }
+    if (getSsm() == null)
+    {
+      return;
+    }
+    String[] files = getPdbFile();
+  
+    SequenceRenderer sr = getSequenceRenderer(alignmentv);
+  
+    FeatureRenderer fr = null;
+    if (showFeatures)
+    {
+      fr = getFeatureRenderer(alignmentv);
+    }
+    AlignmentI alignment = alignmentv.getAlignment();
+  
+    StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
+            files, sr, fr, alignment);
+    colourBySequence(colourBySequenceCommands);
+  }
+
+  public boolean hasFileLoadingError()
+  {
+    return fileLoadingError != null && fileLoadingError.length() > 0;
+  }
 }
index b74a089..0422537 100644 (file)
@@ -24,18 +24,25 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
 import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
 import jalview.structure.AtomSpec;
+import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
 
+import java.awt.Color;
 import java.util.Arrays;
 import java.util.List;
 
@@ -155,6 +162,59 @@ public class AAStructureBindingModelTest
       {
         return null;
       }
+
+      @Override
+      public void setJalviewColourScheme(ColourSchemeI cs)
+      {
+      }
+
+      @Override
+      public void superposeStructures(AlignmentI[] als, int[] alm,
+              ColumnSelection[] alc)
+      {
+      }
+
+      @Override
+      public void setBackgroundColour(Color col)
+      {
+      }
+
+      @Override
+      protected StructureMappingcommandSet[] getColourBySequenceCommands(
+              String[] files, SequenceRenderer sr, FeatureRenderer fr,
+              AlignmentI alignment)
+      {
+        return null;
+      }
+
+      @Override
+      public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+      {
+        return null;
+      }
+
+      @Override
+      public SequenceRenderer getSequenceRenderer(
+              AlignmentViewPanel alignment)
+      {
+        return null;
+      }
+
+      @Override
+      protected void colourBySequence(
+              StructureMappingcommandSet[] colourBySequenceCommands)
+      {
+      }
+
+      @Override
+      public void colourByChain()
+      {
+      }
+
+      @Override
+      public void colourByCharge()
+      {
+      }
     };
   }
 
@@ -239,4 +299,14 @@ public class AAStructureBindingModelTest
     assertFalse(matched[4]); // superposable, but hidden, column
     assertTrue(matched[5]);
   }
+
+  public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+  {
+    return null;
+  }
+
+  public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
+  {
+    return null;
+  }
 }