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.align.ce; 022 023import org.biojava.nbio.structure.Atom; 024import org.biojava.nbio.structure.Group; 025import org.biojava.nbio.structure.Structure; 026import org.biojava.nbio.structure.align.model.AFPChain; 027import org.biojava.nbio.structure.jama.Matrix; 028 029import javax.swing.*; 030import java.lang.reflect.InvocationTargetException; 031import java.lang.reflect.Method; 032import java.util.List; 033 034/** 035 * A class to wrap some of the strucutre.gui classes using Reflection 036 * 037 * @author Andreas Prlic 038 * 039 */ 040 041public class GuiWrapper { 042 043 static final String guiPackage = "org.biojava.nbio.structure.gui"; 044 045 static final String strucAlignmentDisplay = "org.biojava.nbio.structure.align.gui.StructureAlignmentDisplay"; 046 static final String displayAFP = "org.biojava.nbio.structure.align.gui.DisplayAFP" ; 047 static final String alignmentGUI = "org.biojava.nbio.structure.align.gui.AlignmentGui"; 048 static final String strucAligJmol = "org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol"; 049 static final String abstractAligJmol = "org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol"; 050 051 static final String scaleMatrixPanel = "org.biojava.nbio.structure.gui.ScaleableMatrixPanel"; 052 053 @SuppressWarnings("rawtypes") 054 public static boolean isGuiModuleInstalled(){ 055 String className = displayAFP; 056 try { 057 @SuppressWarnings("unused") 058 Class c = Class.forName(className); 059 } catch (ClassNotFoundException ex){ 060 return false; 061 } 062 return true; 063 } 064 065 @SuppressWarnings({ "rawtypes", "unchecked" }) 066 public static Object display(AFPChain afpChain, Atom[] ca1, Atom[] ca2) 067 throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException{ 068 069 Class c = Class.forName(strucAlignmentDisplay); 070 071 Method display = c.getMethod("display", new Class[]{AFPChain.class, Atom[].class, 072 Atom[].class}); 073 074 Object structureAlignmentJmol = display.invoke(null, afpChain,ca1,ca2); 075 076 return structureAlignmentJmol; 077 } 078 079 080 081 @SuppressWarnings({ "rawtypes", "unchecked" }) 082 public static void showAlignmentImage(AFPChain afpChain, Atom[] ca1, 083 Atom[] ca2, Object jmol) 084 throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException{ 085 086 Class abstractAligJmolC = Class.forName(abstractAligJmol); 087 088 Class c = Class.forName(displayAFP); 089 Method show = c.getMethod("showAlignmentPanel", new Class[] {AFPChain.class, Atom[].class, Atom[].class, abstractAligJmolC}); 090 091 show.invoke(null,afpChain, ca1, ca2, jmol); 092 } 093 094 095 /** Shows a structure in Jmol 096 * @since 3.0.5 097 */ 098 public static void showStructure(Structure structure) 099 throws ClassNotFoundException, NoSuchMethodException, 100 InvocationTargetException, IllegalAccessException, InstantiationException{ 101 102 Class<?> structureAlignmentJmol = Class.forName(strucAligJmol); 103 104 Object strucAligJ = structureAlignmentJmol.newInstance(); 105 106 Method setS = structureAlignmentJmol.getMethod("setStructure", new Class[] {Structure.class}); 107 108 setS.invoke(strucAligJ,structure); 109 } 110 111 112 @SuppressWarnings({ "rawtypes", "unchecked" }) 113 public static void showAlignmentGUI() 114 throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { 115 // proxy for AlignmentGui.getInstance(); 116 117 118 Class c = Class.forName(alignmentGUI); 119 Method m = c.getMethod("getInstance", (Class[])null); 120 m.invoke(c,(Object[])null); 121 } 122 123 @SuppressWarnings({"unused" }) 124 public static Structure getAlignedStructure(Atom[] ca1, Atom[] ca2) 125 throws ClassNotFoundException, NoSuchMethodException, 126 InvocationTargetException, IllegalAccessException{ 127 128 Class<?> structureAlignmentJmol = Class.forName(strucAligJmol); 129 130 Class<?> c = Class.forName(displayAFP); 131 Method show = c.getMethod("getAlignedStructure", new Class[] { Atom[].class, Atom[].class}); 132 133 Structure s = (Structure) show.invoke(null, ca1, ca2); 134 135 return s; 136 137 } 138 139 public static JPanel getScaleableMatrixPanel(Matrix m) 140 throws ClassNotFoundException, NoSuchMethodException, 141 InvocationTargetException, IllegalAccessException, InstantiationException{ 142 143 Class<?> scaleMatrixPanelC = Class.forName(scaleMatrixPanel); 144 145 Method setMatrix = scaleMatrixPanelC.getMethod("setMatrix", new Class[] { Matrix.class}); 146 147 JPanel panel = (JPanel) scaleMatrixPanelC.newInstance(); 148 149 setMatrix.invoke(panel, m); 150 151 return panel; 152 153 } 154 155 @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) 156 public static Atom[] getAtomArray(Atom[] ca, List<Group> hetatoms, List<Group> nucs) 157 throws ClassNotFoundException, NoSuchMethodException, 158 InvocationTargetException, IllegalAccessException{ 159 160 Class structureAlignmentJmol = Class.forName(strucAligJmol); 161 162 Class c = Class.forName(displayAFP); 163 Method show = c.getMethod("getAtomArray", new Class[] { Atom[].class, List.class, List.class}); 164 165 Atom[] atoms = (Atom[]) show.invoke(null, ca, hetatoms, nucs); 166 167 return atoms; 168 169 } 170 171 172}