X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fext%2Fedu%2Fucsf%2Frbvi%2Fstrucviz2%2FChimeraTreeModel.java;fp=src%2Fext%2Fedu%2Fucsf%2Frbvi%2Fstrucviz2%2FChimeraTreeModel.java;h=9ecc6a77845f492fb38f6dc46b3e6ba9b1586e14;hb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;hp=f3447ce66b171ab740941b0e5e9b0de464c9e824;hpb=619cc880371f3228e6a1fb33c6bfb6e7a7e2622c;p=jalview.git diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraTreeModel.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraTreeModel.java index f3447ce..9ecc6a7 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraTreeModel.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraTreeModel.java @@ -46,149 +46,171 @@ import javax.swing.tree.TreePath; // 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 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 residues, - DefaultMutableTreeNode treeModel, - TreePath treePath) { - DefaultMutableTreeNode residue = null; - TreePath residuePath = null; - - List sortedResidues = new ArrayList(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 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 residues, + DefaultMutableTreeNode treeModel, TreePath treePath) + { + DefaultMutableTreeNode residue = null; + TreePath residuePath = null; + + List sortedResidues = new ArrayList( + 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); + } + } }