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 org.biojava.nbio.structure.Atom;
024import org.biojava.nbio.structure.StructureException;
025import org.biojava.nbio.structure.align.gui.DisplayAFP;
026import org.biojava.nbio.structure.align.gui.jmol.JmolTools;
027import org.biojava.nbio.structure.align.model.AFPChain;
028import org.biojava.nbio.structure.gui.events.AlignmentPositionListener;
029import org.biojava.nbio.structure.gui.util.AlignedPosition;
030
031import javax.swing.*;
032import java.awt.*;
033import java.awt.event.WindowEvent;
034import java.awt.event.WindowListener;
035
036public class StatusDisplay extends JTextField implements AlignmentPositionListener, WindowListener  {
037
038        /**
039         *
040         */
041        private static final long serialVersionUID = 6939947266417830429L;
042
043        AFPChain afpChain;
044        Atom[] ca1;
045        Atom[] ca2;
046
047
048
049        public StatusDisplay(){
050                super();
051
052                this.setBackground(Color.white);
053                this.setEditable(false);
054                this.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
055
056        }
057        public void destroy(){
058                afpChain = null;
059                ca1= null;
060                ca2 = null;
061
062        }
063
064        @Override
065        public void mouseOverPosition(AlignedPosition p) {
066
067                if ( afpChain == null)
068                        return;
069
070                char[] aligs1  = afpChain.getAlnseq1();
071                char[] aligs2  = afpChain.getAlnseq2();
072
073                char c1 = aligs1[p.getPos1()];
074                char c2 = aligs2[p.getPos2()];
075
076                try {
077                        Atom a1 = DisplayAFP.getAtomForAligPos(afpChain, 0, p.getPos1(), ca1,false);
078                        Atom a2 = DisplayAFP.getAtomForAligPos(afpChain, 1, p.getPos2(), ca2,true);
079
080                        String pdbInfo1 = JmolTools.getPdbInfo(a1);
081                        String pdbInfo2 = JmolTools.getPdbInfo(a2);
082
083                        String msg = "alig pos:" + p.getPos1()+ " " +  pdbInfo1 + " ("+c1+") : " + pdbInfo2 + " ("+c2+")";
084
085                        this.setText(msg);
086
087
088
089                } catch (StructureException e){
090                        e.printStackTrace();
091                }
092
093                this.repaint();
094
095        }
096
097
098
099        @Override
100        public void positionSelected(AlignedPosition p) {
101                mouseOverPosition(p);
102
103        }
104        @Override
105        public void toggleSelection(AlignedPosition p) {
106                if ( afpChain == null)
107                        return;
108
109                char[] aligs1  = afpChain.getAlnseq1();
110                char[] aligs2  = afpChain.getAlnseq2();
111
112                char c1 = aligs1[p.getPos1()];
113                char c2 = aligs2[p.getPos2()];
114
115                try {
116                        Atom a1 = DisplayAFP.getAtomForAligPos(afpChain, 0, p.getPos1(), ca1,false);
117                        Atom a2 = DisplayAFP.getAtomForAligPos(afpChain, 1, p.getPos2(), ca2,true);
118
119                        String pdbInfo1 = JmolTools.getPdbInfo(a1);
120                        String pdbInfo2 = JmolTools.getPdbInfo(a2);
121
122                        String msg = "Clicked pos:" + p.getPos1()+ " " + pdbInfo1 + " ("+c1+") : " + pdbInfo2 + " ("+c2+")";
123
124                        this.setText(msg);
125                } catch (StructureException e){
126                        e.printStackTrace();
127                }
128
129        }
130
131
132        @Override
133        public void rangeSelected(AlignedPosition start, AlignedPosition end) {
134                char[] aligs1  = afpChain.getAlnseq1();
135                char[] aligs2  = afpChain.getAlnseq2();
136
137                char c1 = aligs1[start.getPos1()];
138                char c3 = aligs1[end.getPos1()];
139
140                char c2 = aligs2[start.getPos2()];
141                char c4 = aligs2[end.getPos2()];
142
143                try {
144                        Atom a1 = DisplayAFP.getAtomForAligPos(afpChain, 0, start.getPos1(), ca1,false);
145                        Atom a2 = DisplayAFP.getAtomForAligPos(afpChain, 1, start.getPos2(), ca2,true);
146
147                        Atom a3 = DisplayAFP.getAtomForAligPos(afpChain, 0, end.getPos1(), ca1,false);
148                        Atom a4 = DisplayAFP.getAtomForAligPos(afpChain, 1, end.getPos2(), ca2,true);
149
150                        String pdbInfo1 = JmolTools.getPdbInfo(a1);
151                        String pdbInfo2 = JmolTools.getPdbInfo(a2);
152
153                        String pdbInfo3 = JmolTools.getPdbInfo(a3);
154                        String pdbInfo4 = JmolTools.getPdbInfo(a4);
155
156                        String msg =  "Selected range1: " + pdbInfo1 + " ("+c1+") - " + pdbInfo3 + " ("+c3+")";
157                        msg       +=  " range2: "         + pdbInfo2 + " ("+c2+") - " + pdbInfo4 + " ("+c4+")";
158
159
160                        this.setText(msg);
161                } catch (StructureException e){
162                        e.printStackTrace();
163                }
164
165
166        }
167
168        @Override
169        public void selectionLocked() {
170                // TODO Auto-generated method stub
171
172        }
173
174        @Override
175        public void selectionUnlocked() {
176                // TODO Auto-generated method stub
177
178        }
179
180        public AFPChain getAfpChain() {
181                return afpChain;
182        }
183
184        public void setAfpChain(AFPChain afpChain) {
185                this.afpChain = afpChain;
186        }
187
188        public Atom[] getCa1() {
189                return ca1;
190        }
191
192        public void setCa1(Atom[] ca1) {
193                this.ca1 = ca1;
194        }
195
196        public Atom[] getCa2() {
197                return ca2;
198        }
199
200        public void setCa2(Atom[] ca2) {
201                this.ca2 = ca2;
202        }
203        @Override
204        public void windowActivated(WindowEvent e) {
205                // TODO Auto-generated method stub
206
207        }
208        @Override
209        public void windowClosed(WindowEvent e) {
210                // TODO Auto-generated method stub
211
212        }
213        @Override
214        public void windowClosing(WindowEvent e) {
215                destroy();
216
217        }
218        @Override
219        public void windowDeactivated(WindowEvent e) {
220                // TODO Auto-generated method stub
221
222        }
223        @Override
224        public void windowDeiconified(WindowEvent e) {
225                // TODO Auto-generated method stub
226
227        }
228        @Override
229        public void windowIconified(WindowEvent e) {
230                // TODO Auto-generated method stub
231
232        }
233        @Override
234        public void windowOpened(WindowEvent e) {
235                // TODO Auto-generated method stub
236
237        }
238
239
240
241
242
243
244
245
246
247}