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.gui.aligpanel; 022 023import java.awt.Color; 024import java.awt.Dimension; 025import java.awt.event.WindowEvent; 026import java.awt.event.WindowListener; 027 028import javax.swing.JTextField; 029 030import org.biojava.nbio.structure.Atom; 031import org.biojava.nbio.structure.align.gui.jmol.JmolTools; 032import org.biojava.nbio.structure.align.multiple.util.MultipleAlignmentTools; 033import org.biojava.nbio.structure.gui.events.AlignmentPositionListener; 034import org.biojava.nbio.structure.gui.util.AlignedPosition; 035 036/** 037 * This class provides information of the selected positions in the 038 * {@link MultipleAligPanel}. 039 * <p> 040 * It has to be linked to a {@link MultipleAligPanel} in order to obtain 041 * the raw information and convert the mouse position to a String. 042 * 043 * @author Aleix Lafita 044 * 045 */ 046public class MultipleStatusDisplay extends JTextField 047implements AlignmentPositionListener, WindowListener { 048 049 private static final long serialVersionUID = 6939947266417830429L; 050 private MultipleAligPanel panel; 051 052 private MultipleStatusDisplay(){ 053 super(); 054 this.setBackground(Color.white); 055 this.setEditable(false); 056 this.setMaximumSize(new Dimension(Short.MAX_VALUE,30)); 057 } 058 059 /** 060 * Constructor using an alignment panel as a parent, where the 061 * information will be displayed. 062 * 063 * @param panel 064 */ 065 public MultipleStatusDisplay(MultipleAligPanel panel) { 066 this(); 067 this.panel = panel; 068 } 069 070 public void destroy(){ 071 panel = null; 072 } 073 074 @Override 075 public void mouseOverPosition(AlignedPosition p) { 076 077 if (panel == null) return; 078 079 try { 080 String msg = "alig pos"; 081 for (int str=0; str<panel.size; str++) { 082 083 String alnseq = panel.getAlnSequences().get(str); 084 char c = alnseq.charAt(p.getPos1()); 085 086 Atom a = MultipleAlignmentTools.getAtomForSequencePosition( 087 panel.getMultipleAlignment(), 088 panel.getMapSeqToStruct(), 089 str, p.getPos1()); 090 091 String pdbInfo = JmolTools.getPdbInfo(a); 092 msg += ": "+pdbInfo + " ("+c+") "; 093 } 094 this.setText(msg); 095 this.repaint(); 096 097 } catch (Exception e){ 098 e.printStackTrace(); 099 } 100 } 101 102 @Override 103 public void positionSelected(AlignedPosition p) { 104 mouseOverPosition(p); 105 } 106 107 @Override 108 public void toggleSelection(AlignedPosition p) { 109 110 if (panel == null) return; 111 112 try { 113 String msg = "Clicked pos"; 114 for (int str=0; str<panel.size; str++) { 115 116 String alnseq = panel.getAlnSequences().get(str); 117 char c = alnseq.charAt(p.getPos1()); 118 119 Atom a = MultipleAlignmentTools.getAtomForSequencePosition( 120 panel.getMultipleAlignment(), 121 panel.getMapSeqToStruct(), 122 str, p.getPos1()); 123 124 String pdbInfo = JmolTools.getPdbInfo(a); 125 126 msg += ": "+pdbInfo + " ("+c+") "; 127 } 128 this.setText(msg); 129 130 } catch (Exception e){ 131 e.printStackTrace(); 132 } 133 } 134 135 @Override 136 public void rangeSelected(AlignedPosition start, AlignedPosition end) { 137 138 try { 139 String msg = "Selected:"; 140 for (int str=0; str<panel.size; str++) { 141 142 String alnseq = panel.getAlnSequences().get(str); 143 char c1 = alnseq.charAt(start.getPos1()); 144 char c2 = alnseq.charAt(end.getPos1()); 145 146 Atom a1 = MultipleAlignmentTools.getAtomForSequencePosition( 147 panel.getMultipleAlignment(), 148 panel.getMapSeqToStruct(), 149 str, start.getPos1()); 150 151 Atom a2 = MultipleAlignmentTools.getAtomForSequencePosition( 152 panel.getMultipleAlignment(), 153 panel.getMapSeqToStruct(), 154 str, end.getPos1()); 155 156 String pdbInfo1 = JmolTools.getPdbInfo(a1); 157 String pdbInfo2 = JmolTools.getPdbInfo(a2); 158 159 msg += " range"+str+": " + pdbInfo1 + 160 " ("+c1+") - " + pdbInfo2 + " ("+c2+")"; 161 } 162 this.setText(msg); 163 164 } catch (Exception e){ 165 e.printStackTrace(); 166 } 167 } 168 169 @Override 170 public void windowClosing(WindowEvent e) { 171 destroy(); 172 } 173 @Override 174 public void selectionLocked() {} 175 @Override 176 public void selectionUnlocked() {} 177 @Override 178 public void windowActivated(WindowEvent e) {} 179 @Override 180 public void windowClosed(WindowEvent e) {} 181 @Override 182 public void windowDeactivated(WindowEvent e) {} 183 @Override 184 public void windowDeiconified(WindowEvent e) {} 185 @Override 186 public void windowIconified(WindowEvent e) {} 187 @Override 188 public void windowOpened(WindowEvent e) {} 189}