Merge branch 'develop' into Release_2_9_Branch
[jalview.git] / src / ext / edu / ucsf / rbvi / strucviz2 / ChimeraChain.java
index 92193f2..9a29a99 100644 (file)
@@ -44,287 +44,329 @@ import java.util.TreeMap;
  * 
  */
 // TODO: [Optional] Implement toAttr() method
-public class ChimeraChain implements ChimeraStructuralObject {
+public class ChimeraChain implements ChimeraStructuralObject
+{
 
-       /**
-        * The model/subModel number this chain is a part of
-        */
-       private int modelNumber;
-       private int subModelNumber;
+  /**
+   * The model/subModel number this chain is a part of
+   */
+  private int modelNumber;
 
-       /**
-        * A pointer to the model this chain is a part of
-        */
-       private ChimeraModel chimeraModel;
+  private int subModelNumber;
 
-       /**
-        * The chainID (from the PDB record)
-        */
-       private String chainId;
+  /**
+   * A pointer to the model this chain is a part of
+   */
+  private ChimeraModel chimeraModel;
 
-       /**
-        * The residues that are part of this chain
-        */
-       private TreeMap<String, ChimeraResidue> residueMap;
+  /**
+   * The chainID (from the PDB record)
+   */
+  private String chainId;
 
-       /**
-        * userData to associate with this chain
-        */
-       private Object userData;
+  /**
+   * The residues that are part of this chain
+   */
+  private TreeMap<String, ChimeraResidue> residueMap;
 
-       /**
-        * Flag to indicate the selection state
-        */
-       private boolean selected = false;
+  /**
+   * userData to associate with this chain
+   */
+  private Object userData;
 
-       /**
-        * Constructor to create a new ChimeraChain
-        * 
-        * @param model
-        *          the model number this chain is part of
-        * @param subModel
-        *          the subModel number this chain is part of
-        * @param chainId
-        *          the chain ID for this chain
-        */
-       public ChimeraChain(int model, int subModel, String chainId) {
-               this.modelNumber = model;
-               this.subModelNumber = subModel;
-               this.chainId = chainId;
-               residueMap = new TreeMap<String, ChimeraResidue>();
-       }
+  /**
+   * Flag to indicate the selection state
+   */
+  private boolean selected = false;
 
-       /**
-        * set the selected state of this chain
-        * 
-        * @param selected
-        *          a boolean to set the selected state to
-        */
-       public void setSelected(boolean selected) {
-               this.selected = selected;
-       }
+  /**
+   * Constructor to create a new ChimeraChain
+   * 
+   * @param model
+   *          the model number this chain is part of
+   * @param subModel
+   *          the subModel number this chain is part of
+   * @param chainId
+   *          the chain ID for this chain
+   */
+  public ChimeraChain(int model, int subModel, String chainId)
+  {
+    this.modelNumber = model;
+    this.subModelNumber = subModel;
+    this.chainId = chainId;
+    residueMap = new TreeMap<String, ChimeraResidue>();
+  }
 
-       /**
-        * return the selected state of this chain
-        * 
-        * @return the selected state
-        */
-       public boolean isSelected() {
-               return selected;
-       }
+  /**
+   * set the selected state of this chain
+   * 
+   * @param selected
+   *          a boolean to set the selected state to
+   */
+  public void setSelected(boolean selected)
+  {
+    this.selected = selected;
+  }
 
-       public boolean hasSelectedChildren() {
-               if (selected) {
-                       return true;
-               } else {
-                       for (ChimeraResidue residue : getResidues()) {
-                               if (residue.isSelected())
-                                       return true;
-                       }
-               }
-               return false;
-       }
+  /**
+   * return the selected state of this chain
+   * 
+   * @return the selected state
+   */
+  public boolean isSelected()
+  {
+    return selected;
+  }
 
-       /**
-        * Return the list of selected residues
-        * 
-        * @return all selected residues
-        */
-       public List<ChimeraResidue> getSelectedResidues() {
-               List<ChimeraResidue> residueList = new ArrayList<ChimeraResidue>();
-               if (selected) {
-                       residueList.addAll(getResidues());
-               } else {
-                       for (ChimeraResidue residue : getResidues()) {
-                               if (residue.isSelected())
-                                       residueList.add(residue);
-                       }
-               }
-               return residueList;
-       }
+  public boolean hasSelectedChildren()
+  {
+    if (selected)
+    {
+      return true;
+    }
+    else
+    {
+      for (ChimeraResidue residue : getResidues())
+      {
+        if (residue.isSelected())
+          return true;
+      }
+    }
+    return false;
+  }
 
-       /**
-        * Add a residue to the chain.
-        * 
-        * @param residue
-        *          the ChimeraResidue to add to the chain.
-        */
-       public void addResidue(ChimeraResidue residue) {
-               String index = residue.getIndex();
-               // Put it in our map so that we can return it in order
-               residueMap.put(index, residue);
-       }
+  /**
+   * Return the list of selected residues
+   * 
+   * @return all selected residues
+   */
+  public List<ChimeraResidue> getSelectedResidues()
+  {
+    List<ChimeraResidue> residueList = new ArrayList<ChimeraResidue>();
+    if (selected)
+    {
+      residueList.addAll(getResidues());
+    }
+    else
+    {
+      for (ChimeraResidue residue : getResidues())
+      {
+        if (residue.isSelected())
+          residueList.add(residue);
+      }
+    }
+    return residueList;
+  }
 
-       /**
-        * Return the list of residues in this chain in pdb residue order
-        * 
-        * @return a Collection of residues in residue order
-        */
-       public Collection<ChimeraResidue> getResidues() {
-               return residueMap.values();
-       }
+  /**
+   * Add a residue to the chain.
+   * 
+   * @param residue
+   *          the ChimeraResidue to add to the chain.
+   */
+  public void addResidue(ChimeraResidue residue)
+  {
+    String index = residue.getIndex();
+    // Put it in our map so that we can return it in order
+    residueMap.put(index, residue);
+  }
 
-       /**
-        * Return the list of residues in this chain as a list
-        * 
-        * @return List of residues
-        */
-       public List<ChimeraStructuralObject> getChildren() {
-               return new ArrayList<ChimeraStructuralObject>(residueMap.values());
-       }
+  /**
+   * Return the list of residues in this chain in pdb residue order
+   * 
+   * @return a Collection of residues in residue order
+   */
+  public Collection<ChimeraResidue> getResidues()
+  {
+    return residueMap.values();
+  }
 
-       /**
-        * Get a specific residue
-        * 
-        * @param residueIndex
-        *          String representation of the residue index
-        * @return the ChimeraResidue represented by the residueIndex
-        */
-       public ChimeraResidue getResidue(String index) {
-               // Integer index = new Integer(residueIndex);
-               if (residueMap.containsKey(index))
-                       return residueMap.get(index);
-               return null;
-       }
+  /**
+   * Return the list of residues in this chain as a list
+   * 
+   * @return List of residues
+   */
+  public List<ChimeraStructuralObject> getChildren()
+  {
+    return new ArrayList<ChimeraStructuralObject>(residueMap.values());
+  }
 
-       /**
-        * Get a list of residues as a residue range
-        * 
-        * @param residueRange
-        *          String representation of the residue range
-        * @return the List of ChimeraResidues represented by the range
-        */
-       public List<ChimeraResidue> getResidueRange(String residueRange) {
-               String[] range = residueRange.split("-", 2);
-               if (range[1] == null || range[1].length() == 0) {
-                       range[1] = range[0];
-               }
-               List<ChimeraResidue> resultRange = new ArrayList<ChimeraResidue>();
-               int start = Integer.parseInt(range[0]);
-               int end = Integer.parseInt(range[1]);
-               for (int i = start; i <= end; i++) {
-                       String index = String.valueOf(i);
-                       if (residueMap.containsKey(index))
-                               resultRange.add(residueMap.get(index));
-               }
-               return resultRange;
-       }
+  /**
+   * Get a specific residue
+   * 
+   * @param residueIndex
+   *          String representation of the residue index
+   * @return the ChimeraResidue represented by the residueIndex
+   */
+  public ChimeraResidue getResidue(String index)
+  {
+    // Integer index = new Integer(residueIndex);
+    if (residueMap.containsKey(index))
+      return residueMap.get(index);
+    return null;
+  }
 
-       /**
-        * Get the ID for this chain
-        * 
-        * @return String value of the chainId
-        */
-       public String getChainId() {
-               return chainId;
-       }
+  /**
+   * Get a list of residues as a residue range
+   * 
+   * @param residueRange
+   *          String representation of the residue range
+   * @return the List of ChimeraResidues represented by the range
+   */
+  public List<ChimeraResidue> getResidueRange(String residueRange)
+  {
+    String[] range = residueRange.split("-", 2);
+    if (range[1] == null || range[1].length() == 0)
+    {
+      range[1] = range[0];
+    }
+    List<ChimeraResidue> resultRange = new ArrayList<ChimeraResidue>();
+    int start = Integer.parseInt(range[0]);
+    int end = Integer.parseInt(range[1]);
+    for (int i = start; i <= end; i++)
+    {
+      String index = String.valueOf(i);
+      if (residueMap.containsKey(index))
+        resultRange.add(residueMap.get(index));
+    }
+    return resultRange;
+  }
 
-       /**
-        * Get the model number for this chain
-        * 
-        * @return the model number
-        */
-       public int getModelNumber() {
-               return modelNumber;
-       }
+  /**
+   * Get the ID for this chain
+   * 
+   * @return String value of the chainId
+   */
+  public String getChainId()
+  {
+    return chainId;
+  }
 
-       /**
-        * Get the sub-model number for this chain
-        * 
-        * @return the sub-model number
-        */
-       public int getSubModelNumber() {
-               return subModelNumber;
-       }
+  /**
+   * Get the model number for this chain
+   * 
+   * @return the model number
+   */
+  public int getModelNumber()
+  {
+    return modelNumber;
+  }
 
-       /**
-        * Return a string representation of this chain as follows: Chain <i>chainId</i>
-        * (<i>residue_count</i> residues)
-        * 
-        * @return String representation of chain
-        */
-       public String displayName() {
-               if (chainId.equals("_")) {
-                       return ("Chain (no ID) (" + getResidueCount() + " residues)");
-               } else {
-                       return ("Chain " + chainId + " (" + getResidueCount() + " residues)");
-               }
-       }
+  /**
+   * Get the sub-model number for this chain
+   * 
+   * @return the sub-model number
+   */
+  public int getSubModelNumber()
+  {
+    return subModelNumber;
+  }
 
-       /**
-        * Return a string representation of this chain as follows: Node xxx [Model yyyy Chain
-        * <i>chainId</i>]
-        * 
-        * @return String representation of chain
-        */
-       public String toString() {
-               String displayName = chimeraModel.getModelName();
-               if (displayName.length() > 14)
-                       displayName = displayName.substring(0, 13) + "...";
-               if (chainId.equals("_")) {
-                       return (displayName + " Chain (no ID) (" + getResidueCount() + " residues)");
-               } else {
-                       return (displayName + " Chain " + chainId + " (" + getResidueCount() + " residues)");
-               }
-       }
+  /**
+   * Return a string representation of this chain as follows: Chain
+   * <i>chainId</i> (<i>residue_count</i> residues)
+   * 
+   * @return String representation of chain
+   */
+  public String displayName()
+  {
+    if (chainId.equals("_"))
+    {
+      return ("Chain (no ID) (" + getResidueCount() + " residues)");
+    }
+    else
+    {
+      return ("Chain " + chainId + " (" + getResidueCount() + " residues)");
+    }
+  }
 
-       /**
-        * Return the Chimera specification for this chain
-        * 
-        * @return Chimera specification
-        */
-       public String toSpec() {
-               if (chainId.equals("_")) {
-                       return ("#" + modelNumber + "." + subModelNumber + ":.");
-               } else {
-                       return ("#" + modelNumber + "." + subModelNumber + ":." + chainId);
-               }
-       }
+  /**
+   * Return a string representation of this chain as follows: Node xxx [Model
+   * yyyy Chain <i>chainId</i>]
+   * 
+   * @return String representation of chain
+   */
+  public String toString()
+  {
+    String displayName = chimeraModel.getModelName();
+    if (displayName.length() > 14)
+      displayName = displayName.substring(0, 13) + "...";
+    if (chainId.equals("_"))
+    {
+      return (displayName + " Chain (no ID) (" + getResidueCount() + " residues)");
+    }
+    else
+    {
+      return (displayName + " Chain " + chainId + " (" + getResidueCount() + " residues)");
+    }
+  }
 
-       /**
-        * Return the number of residues in this chain
-        * 
-        * @return integer number of residues
-        */
-       public int getResidueCount() {
-               return residueMap.size();
-       }
+  /**
+   * Return the Chimera specification for this chain
+   * 
+   * @return Chimera specification
+   */
+  public String toSpec()
+  {
+    if (chainId.equals("_"))
+    {
+      return ("#" + modelNumber + "." + subModelNumber + ":.");
+    }
+    else
+    {
+      return ("#" + modelNumber + "." + subModelNumber + ":." + chainId);
+    }
+  }
 
-       /**
-        * Set the ChimeraModel for this chain
-        * 
-        * @param model
-        *          ChimeraModel to associate with this chain
-        */
-       public void setChimeraModel(ChimeraModel model) {
-               this.chimeraModel = model;
-       }
+  /**
+   * Return the number of residues in this chain
+   * 
+   * @return integer number of residues
+   */
+  public int getResidueCount()
+  {
+    return residueMap.size();
+  }
 
-       /**
-        * Get the ChimeraModel for this chain
-        * 
-        * @return ChimeraModel associated with this chain
-        */
-       public ChimeraModel getChimeraModel() {
-               return chimeraModel;
-       }
+  /**
+   * Set the ChimeraModel for this chain
+   * 
+   * @param model
+   *          ChimeraModel to associate with this chain
+   */
+  public void setChimeraModel(ChimeraModel model)
+  {
+    this.chimeraModel = model;
+  }
 
-       /**
-        * Get the user data for this Chain
-        * 
-        * @return user data
-        */
-       public Object getUserData() {
-               return userData;
-       }
+  /**
+   * Get the ChimeraModel for this chain
+   * 
+   * @return ChimeraModel associated with this chain
+   */
+  public ChimeraModel getChimeraModel()
+  {
+    return chimeraModel;
+  }
 
-       /**
-        * Set the user data for this Chain
-        * 
-        * @param data
-        *          the user data to associate with this chain
-        */
-       public void setUserData(Object data) {
-               this.userData = data;
-       }
+  /**
+   * Get the user data for this Chain
+   * 
+   * @return user data
+   */
+  public Object getUserData()
+  {
+    return userData;
+  }
+
+  /**
+   * Set the user data for this Chain
+   * 
+   * @param data
+   *          the user data to associate with this chain
+   */
+  public void setUserData(Object data)
+  {
+    this.userData = data;
+  }
 }