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                                j.evalString("save STATE state_1");
072
073
074                        } else if (cmd.equals("Multiple Structure Alignment")) {
075                                MultipleAlignmentJmol j = SymmetryDisplay.displayFull(symm);
076                                String s = SymmetryDisplay.printSymmetryAxes(symm);
077                                j.evalString(s);
078                                j.evalString("save STATE state_1");
079
080                        } else if (cmd.equals("Optimal Self Alignment")) {
081                                Atom[] cloned = StructureTools.cloneAtomArray(symm.getAtoms());
082                                AbstractAlignmentJmol jmol = StructureAlignmentDisplay.display(
083                                                symm.getSelfAlignment(), symm.getAtoms(), cloned);
084                                RotationAxis axis = new RotationAxis(symm.getSelfAlignment());
085                                jmol.evalString(axis.getJmolScript(symm.getAtoms()));
086                                jmol.setTitle(SymmetryDisplay.getSymmTitle(symm));
087
088                        } else if (cmd.equals("Show Symmetry Group")) {
089                                String script = SymmetryDisplay.printSymmetryGroup(symm);
090                                jmol.evalString(script);
091
092                        } else if (cmd.equals("Show Symmetry Axes")) {
093                                String s = SymmetryDisplay.printSymmetryAxes(symm);
094                                jmol.evalString(s);
095                        }
096
097                } catch (Exception e) {
098                        logger.error("Could not complete display option", e);
099                }
100        }
101}