// StructureViz imports
/**
- * The ChimeraTreeModel class provides the underlying model
- * for the navigation tree in the ModelNavigatorDialog.
+ * The ChimeraTreeModel class provides the underlying model for the navigation
+ * tree in the ModelNavigatorDialog.
*
* @author scooter
* @see ModelNavigatorDialog
- */
-public class ChimeraTreeModel extends DefaultTreeModel {
- private ChimeraManager chimeraManager;
- private JTree navigationTree;
- private int residueDisplay = ChimeraResidue.THREE_LETTER;
-
- /**
- * Constructor for the ChimeraTreeModel.
- *
- * @param chimeraObject the Chimera object that this tree represents
- * @param tree the JTree used to display the object
- * @see Chimera
- */
- public ChimeraTreeModel (ChimeraManager chimeraManager, JTree tree) {
- super(new DefaultMutableTreeNode());
- this.chimeraManager = chimeraManager;
- this.navigationTree = tree;
- DefaultMutableTreeNode rootNode = buildTree();
- this.setRoot(rootNode);
- }
-
- /**
- * Set the display type for the residues. The display type
- * must be one of:
- *
- * ChimeraResidue.THREE_LETTER
- * ChimeraResidue.SINGLE_LETTER
- * ChimeraResidue.FULL_NAME
- *
- * @param newDisplay the display type
- * @see ChimeraResidue
- */
- public void setResidueDisplay(int newDisplay) {
- this.residueDisplay = newDisplay;
- }
-
- /**
- * This method is called to rebuild the tree model "from scratch"
- */
- public void reload() {
- // First, rebuild the tree with the new data
- DefaultMutableTreeNode rootNode = buildTree();
- this.setRoot(rootNode);
-
- // Now let the superclass do all of the work
- super.reload();
- }
-
- /**
- * Rebuild an existing tree
- */
- public void rebuildTree() {
- DefaultMutableTreeNode rootNode = buildTree();
- DefaultTreeModel model = (DefaultTreeModel)navigationTree.getModel();
- model.setRoot(rootNode);
- model.reload();
- }
-
- /**
- * Build the tree from the current Chimera data
- *
- * @return DefaultMutableTreeNode that represents the currently loaded Chimera models
- */
- private DefaultMutableTreeNode buildTree() {
- int modelCount = chimeraManager.getChimeraModelsCount(true);
- DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(modelCount+" Open Chimera Models");
- TreePath rootPath = new TreePath(rootNode);
-
- TreePath path = null;
- DefaultMutableTreeNode model = null;
-
- // Add all of the Chimera models
- for (ChimeraModel chimeraModel: chimeraManager.getChimeraModels()) {
- model = new DefaultMutableTreeNode(chimeraModel);
- path = rootPath.pathByAddingChild(model);
- chimeraModel.setUserData(path);
- addChainNodes(chimeraModel, model, path);
- rootNode.add(model);
- }
- return rootNode;
- }
-
- /**
- * add chains to a tree model
- *
- * @param chimeraModel the ChimeraModel to get the chains from
- * @param treeModel the tree model to add the chains to
- * @param treePath the tree path where the chains should be added
- */
- private void addChainNodes(ChimeraModel chimeraModel,
- DefaultMutableTreeNode treeModel,
- TreePath treePath) {
- DefaultMutableTreeNode chain = null;
- TreePath chainPath = null;
-
- // Get the list of chains
- Collection<ChimeraChain> chainList = chimeraModel.getChains();
-
- if (chainList.size() == 0) {
- // No chains! Just add the residues
- addResidues(chimeraModel.getResidues(), treeModel, treePath);
- return;
- }
-
- // Iterate over the chains and add the chain and all of
- // the chain's residues
- for (ChimeraChain chimeraChain: chainList) {
- chain = new DefaultMutableTreeNode(chimeraChain);
- chainPath = treePath.pathByAddingChild(chain);
- chimeraChain.setUserData(chainPath);
- addResidues(chimeraChain.getResidues(), chain, chainPath);
- treeModel.add(chain);
- }
- }
-
- /**
- * add residues to a tree model
- *
- * @param residues the residues to add
- * @param treeModel the tree model to add the residues to
- * @param treePath the tree path where the residues should be added
- */
- private void addResidues(Collection<ChimeraResidue> residues,
- DefaultMutableTreeNode treeModel,
- TreePath treePath) {
- DefaultMutableTreeNode residue = null;
- TreePath residuePath = null;
-
- List<ChimeraResidue> sortedResidues = new ArrayList<ChimeraResidue>(residues);
- Collections.sort(sortedResidues);
-
- // Iterate over all residues & add them to the tree
- for (ChimeraResidue res: sortedResidues) {
- res.setDisplayType(this.residueDisplay);
- residue = new DefaultMutableTreeNode(res);
- residuePath = treePath.pathByAddingChild(residue);
- res.setUserData(residuePath);
- treeModel.add(residue);
- }
- }
+ */
+public class ChimeraTreeModel extends DefaultTreeModel
+{
+ private ChimeraManager chimeraManager;
+
+ private JTree navigationTree;
+
+ private int residueDisplay = ChimeraResidue.THREE_LETTER;
+
+ /**
+ * Constructor for the ChimeraTreeModel.
+ *
+ * @param chimeraObject
+ * the Chimera object that this tree represents
+ * @param tree
+ * the JTree used to display the object
+ * @see Chimera
+ */
+ public ChimeraTreeModel(ChimeraManager chimeraManager, JTree tree)
+ {
+ super(new DefaultMutableTreeNode());
+ this.chimeraManager = chimeraManager;
+ this.navigationTree = tree;
+ DefaultMutableTreeNode rootNode = buildTree();
+ this.setRoot(rootNode);
+ }
+
+ /**
+ * Set the display type for the residues. The display type must be one of:
+ *
+ * ChimeraResidue.THREE_LETTER ChimeraResidue.SINGLE_LETTER
+ * ChimeraResidue.FULL_NAME
+ *
+ * @param newDisplay
+ * the display type
+ * @see ChimeraResidue
+ */
+ public void setResidueDisplay(int newDisplay)
+ {
+ this.residueDisplay = newDisplay;
+ }
+
+ /**
+ * This method is called to rebuild the tree model "from scratch"
+ */
+ public void reload()
+ {
+ // First, rebuild the tree with the new data
+ DefaultMutableTreeNode rootNode = buildTree();
+ this.setRoot(rootNode);
+
+ // Now let the superclass do all of the work
+ super.reload();
+ }
+
+ /**
+ * Rebuild an existing tree
+ */
+ public void rebuildTree()
+ {
+ DefaultMutableTreeNode rootNode = buildTree();
+ DefaultTreeModel model = (DefaultTreeModel) navigationTree.getModel();
+ model.setRoot(rootNode);
+ model.reload();
+ }
+
+ /**
+ * Build the tree from the current Chimera data
+ *
+ * @return DefaultMutableTreeNode that represents the currently loaded Chimera
+ * models
+ */
+ private DefaultMutableTreeNode buildTree()
+ {
+ int modelCount = chimeraManager.getChimeraModelsCount(true);
+ DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(modelCount
+ + " Open Chimera Models");
+ TreePath rootPath = new TreePath(rootNode);
+
+ TreePath path = null;
+ DefaultMutableTreeNode model = null;
+
+ // Add all of the Chimera models
+ for (ChimeraModel chimeraModel : chimeraManager.getChimeraModels())
+ {
+ model = new DefaultMutableTreeNode(chimeraModel);
+ path = rootPath.pathByAddingChild(model);
+ chimeraModel.setUserData(path);
+ addChainNodes(chimeraModel, model, path);
+ rootNode.add(model);
+ }
+ return rootNode;
+ }
+
+ /**
+ * add chains to a tree model
+ *
+ * @param chimeraModel
+ * the ChimeraModel to get the chains from
+ * @param treeModel
+ * the tree model to add the chains to
+ * @param treePath
+ * the tree path where the chains should be added
+ */
+ private void addChainNodes(ChimeraModel chimeraModel,
+ DefaultMutableTreeNode treeModel, TreePath treePath)
+ {
+ DefaultMutableTreeNode chain = null;
+ TreePath chainPath = null;
+
+ // Get the list of chains
+ Collection<ChimeraChain> chainList = chimeraModel.getChains();
+
+ if (chainList.size() == 0)
+ {
+ // No chains! Just add the residues
+ addResidues(chimeraModel.getResidues(), treeModel, treePath);
+ return;
+ }
+
+ // Iterate over the chains and add the chain and all of
+ // the chain's residues
+ for (ChimeraChain chimeraChain : chainList)
+ {
+ chain = new DefaultMutableTreeNode(chimeraChain);
+ chainPath = treePath.pathByAddingChild(chain);
+ chimeraChain.setUserData(chainPath);
+ addResidues(chimeraChain.getResidues(), chain, chainPath);
+ treeModel.add(chain);
+ }
+ }
+
+ /**
+ * add residues to a tree model
+ *
+ * @param residues
+ * the residues to add
+ * @param treeModel
+ * the tree model to add the residues to
+ * @param treePath
+ * the tree path where the residues should be added
+ */
+ private void addResidues(Collection<ChimeraResidue> residues,
+ DefaultMutableTreeNode treeModel, TreePath treePath)
+ {
+ DefaultMutableTreeNode residue = null;
+ TreePath residuePath = null;
+
+ List<ChimeraResidue> sortedResidues = new ArrayList<ChimeraResidue>(
+ residues);
+ Collections.sort(sortedResidues);
+
+ // Iterate over all residues & add them to the tree
+ for (ChimeraResidue res : sortedResidues)
+ {
+ res.setDisplayType(this.residueDisplay);
+ residue = new DefaultMutableTreeNode(res);
+ residuePath = treePath.pathByAddingChild(residue);
+ res.setUserData(residuePath);
+ treeModel.add(residue);
+ }
+ }
}