001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.structure.symmetry.gui;
022
023import java.awt.event.ActionEvent;
024import java.awt.event.ActionListener;
025
026import org.biojava.nbio.structure.Atom;
027import org.biojava.nbio.structure.StructureTools;
028import org.biojava.nbio.structure.align.gui.StructureAlignmentDisplay;
029import org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol;
030import org.biojava.nbio.structure.align.gui.jmol.MultipleAlignmentJmol;
031import org.biojava.nbio.structure.align.util.RotationAxis;
032import org.biojava.nbio.structure.symmetry.internal.CeSymmResult;
033import org.slf4j.Logger;
034import org.slf4j.LoggerFactory;
035
036/**
037 * Action Listener for the symmetry menu. Trigger various internal symmetry
038 * specific analysis.
039 *
040 * @author Aleix Lafita
041 * @since 4.2.0
042 *
043 */
044public class SymmetryListener implements ActionListener {
045
046        private MultipleAlignmentJmol jmol;
047        private CeSymmResult symm;
048
049        private static final Logger logger = LoggerFactory
050                        .getLogger(SymmetryListener.class);
051
052        public SymmetryListener(MultipleAlignmentJmol jmol, CeSymmResult symm) {
053                this.jmol = jmol;
054                this.symm = symm;
055        }
056
057        @Override
058        public void actionPerformed(ActionEvent ae) {
059                String cmd = ae.getActionCommand();
060                if (cmd.equals("New Symmetry Analysis"))
061                        SymmetryGui.getInstance();
062
063                if (symm == null)
064                        logger.error("Currently not displaying a symmetry!");
065
066                try {
067                        if (cmd.equals("Repeats Superposition")) {
068                                MultipleAlignmentJmol j = SymmetryDisplay.displayRepeats(symm);
069                                String s = SymmetryDisplay.printSymmetryAxes(symm, false);
070                                j.evalString(s);
071
072                        } else if (cmd.equals("Multiple Structure Alignment")) {
073                                MultipleAlignmentJmol j = SymmetryDisplay.displayFull(symm);
074                                String s = SymmetryDisplay.printSymmetryAxes(symm);
075                                j.evalString(s);
076
077                        } else if (cmd.equals("Optimal Self Alignment")) {
078                                Atom[] cloned = StructureTools.cloneAtomArray(symm.getAtoms());
079                                AbstractAlignmentJmol jmol = StructureAlignmentDisplay.display(
080                                                symm.getSelfAlignment(), symm.getAtoms(), cloned);
081                                RotationAxis axis = new RotationAxis(symm.getSelfAlignment());
082                                jmol.evalString(axis.getJmolScript(symm.getAtoms()));
083                                jmol.setTitle(SymmetryDisplay.getSymmTitle(symm));
084
085                        } else if (cmd.equals("Show Symmetry Group")) {
086                                String script = SymmetryDisplay.printSymmetryGroup(symm);
087                                jmol.evalString(script);
088
089                        } else if (cmd.equals("Show Symmetry Axes")) {
090                                String s = SymmetryDisplay.printSymmetryAxes(symm);
091                                jmol.evalString(s);
092                        }
093
094                } catch (Exception e) {
095                        logger.error("Could not complete display option", e);
096                }
097        }
098}